123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace App\Http\Controllers;
- use App\Post;
- use App\Repositories\Posts;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- class PostsController extends Controller
- {
- /**
- * @var \App\Repositories\Posts
- */
- protected $posts;
- public function __construct(Posts $posts)
- {
- $this->middleware('auth')
- ->except(['index', 'show']);
- $this->posts = $posts;
- }
- /**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function create()
- {
- return view('posts.create');
- }
- /**
- * Remove the specified resource from storage.
- *
- * @param int $id
- *
- * @return \Illuminate\Http\Response
- */
- public function destroy($id)
- {
- //
- }
- /**
- * Show the form for editing the specified resource.
- *
- * @param int $id
- *
- * @return \Illuminate\Http\Response
- */
- public function edit($id)
- {
- //
- }
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index(Request $request)
- {
- $posts = $this->posts->all();
- // $posts = Post::latest()
- // ->filter($request->only(['month', 'year']))
- // ->get();
- return view('posts.index', compact('posts'));
- }
- public function show(Post $post)
- {
- return view('posts.show', compact('post'));
- }
- /**
- * Store a newly created resource in storage.
- *
- * - Create new post using the request data
- * - Save it to the database
- * - Redirect to the home page
- *
- * @param \Illuminate\Http\Request $request
- *
- * @return \Illuminate\Http\Response
- */
- public function store(Request $request)
- {
- // $post = new Post();
- // $post->title = $request->get('title');
- // $post->body = $request->get('body');
- // $post->save();
- $this->validate($request, [
- 'title' => 'required|min:10',
- 'body' => 'required',
- ]);
- auth()->user()->publish(new Post(request(['title', 'body'])));
- return redirect('/');
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param int $id
- *
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request, $id)
- {
- //
- }
- }
|