From cf8ba61943457cdd8ce6002c0c39e726fff6ffee Mon Sep 17 00:00:00 2001 From: syarig Date: Sat, 12 Dec 2020 23:29:49 +0900 Subject: [PATCH] chore: remove example project code in src-php --- .../Http/Controllers/CommentController.php | 32 ++------- .../Http/Controllers/PostController.php | 68 +------------------ .../src-php/Http/Requests/PostRequest.php | 26 +------ example-project/src-php/Models/Category.php | 2 +- example-project/src-php/Models/Post.php | 26 +------ 5 files changed, 8 insertions(+), 146 deletions(-) diff --git a/example-project/src-php/Http/Controllers/CommentController.php b/example-project/src-php/Http/Controllers/CommentController.php index aef45f4..423c358 100644 --- a/example-project/src-php/Http/Controllers/CommentController.php +++ b/example-project/src-php/Http/Controllers/CommentController.php @@ -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 + } } diff --git a/example-project/src-php/Http/Controllers/PostController.php b/example-project/src-php/Http/Controllers/PostController.php index 44527b1..3316dd8 100644 --- a/example-project/src-php/Http/Controllers/PostController.php +++ b/example-project/src-php/Http/Controllers/PostController.php @@ -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 } } diff --git a/example-project/src-php/Http/Requests/PostRequest.php b/example-project/src-php/Http/Requests/PostRequest.php index fc41aeb..771d69c 100644 --- a/example-project/src-php/Http/Requests/PostRequest.php +++ b/example-project/src-php/Http/Requests/PostRequest.php @@ -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 } } diff --git a/example-project/src-php/Models/Category.php b/example-project/src-php/Models/Category.php index 1a68b97..f4f8885 100644 --- a/example-project/src-php/Models/Category.php +++ b/example-project/src-php/Models/Category.php @@ -8,6 +8,6 @@ class Category extends Model { public function posts() { - return $this->hasMany('App\Post'); + // posts } } diff --git a/example-project/src-php/Models/Post.php b/example-project/src-php/Models/Post.php index f38d8b7..de8c5c8 100644 --- a/example-project/src-php/Models/Post.php +++ b/example-project/src-php/Models/Post.php @@ -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 } }