chore: remove example project code in src-php

This commit is contained in:
syarig 2020-12-12 23:29:49 +09:00
parent 26383aa79d
commit cf8ba61943
5 changed files with 8 additions and 146 deletions

View File

@ -12,32 +12,8 @@ use Validator;
class CommentController extends Controller
{
public function create(CommentRequest $request)
{
$input_comment = $request->input('comment');
$post = Post::where('hash', $input_comment['post_hash'])->first();
$input_comment['user_id'] = Auth::id();
$input_comment['post_id'] = $post->id;
if (\session('edit_post_id') === $post->id) {
Comment::create($input_comment);
}
return redirect()->back();
}
public function update(CommentRequest $request)
{
$input_comment = $request->input('comment');
$comment_id = (int)$request->comment_id;
$post = Post::where('hash', $input_comment['post_hash'])->first();
if (\session('edit_post_id') === $post->id) {
$comment = Auth::user()->comments()->find($comment_id);
$comment->fill($input_comment);
$comment->save();
}
return redirect()->back();
}
function index()
{
// index
}
}

View File

@ -11,74 +11,8 @@ use Illuminate\Support\Facades\Auth;
class PostController extends Controller
{
const CREATE_POST_FLAG = -1;
const PAGINATE_NUMBER = 12;
public function index()
{
$posts = Post::with('pictures')->orderBy('created_at', 'asc')->paginate(self::PAGINATE_NUMBER);
$categories = Category::orderBy('id')->get();
return view('home.index', compact('posts', 'categories'));
}
public function edit(Request $request, Post $post = null)
{
$edit_post_id = self::CREATE_POST_FLAG;
if ($post === null) {
$post = new Post;
} else {
$edit_post_id = $post->id;
}
$request->session()->flash('edit_post_id', $edit_post_id);
$categories = Category::orderBy('id')->get();
return view('admin.post.edit', compact('post', 'categories'));
}
public function create(PostRequest $request)
{
$input_post = $request->input('post');
$input_post['published_at'] = date_format(new \DateTime(), 'Y-m-d H:i:s');
$input_post['user_id'] = Auth::id();
if (\session('edit_post_id') === self::CREATE_POST_FLAG) {
$hashids = new Hashids(config('APP_KEY'), Post::HASH_LEN);
$post = Post::create($input_post);
$post->hash = $hashids->encode($post->id);
$post->save();
$request->session()->flash('edit_post_id', self::CREATE_POST_FLAG);
}
return redirect()->route('admin.index');
}
public function update(PostRequest $request, Post $post)
{
$input_post = $request->input('post');
$input_post['published_at'] = date_format(new \DateTime(), 'Y-m-d H:i:s');
$input_post['user_id'] = Auth::id();
if (\session('edit_post_id') === $post->id) {
$post->fill($input_post);
$post->save();
$request->session()->flash('edit_post_id', self::CREATE_POST_FLAG);
}
return redirect()->route('admin.index');
}
public function show(Request $request, Post $post)
{
$request->session()->flash('edit_post_id', $post->id);
return view('home.detail', compact('post'));
}
public function delete(Post $post)
{
$post and $post->delete();
return redirect()->route('admin.index');
// index
}
}

View File

@ -8,32 +8,8 @@ use App\Rules\Category;
class PostRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
if ($this->path !== 'post') {
return true;
}
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
// 'post.category_id' => new Category,
'post.thumb' => 'between:1,255',
'post.title' => 'between:0,255',
'post.content' => 'between:0,8191'
];
// authorize
}
}

View File

@ -8,6 +8,6 @@ class Category extends Model
{
public function posts()
{
return $this->hasMany('App\Post');
// posts
}
}

View File

@ -6,32 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id', 'title', 'thumb', 'content', 'published_at', 'category_id'
];
public function user()
{
return $this->belongsTo('App\User');
}
public function comments()
{
return $this->hasMany('App\Comment');
}
public function category()
{
return $this->belongsTo('App\Category');
}
public function pictures()
{
return $this->hasMany('App\Picture');
// user
}
}