|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Http\Controllers; |
| 4 | + |
| 5 | +use Illuminate\Http\Request; |
| 6 | + |
| 7 | +use App\Http\Requests; |
| 8 | +use App\Comment; |
| 9 | +use App\Post; |
| 10 | +use Session; |
| 11 | + |
| 12 | +class CommentsController extends Controller |
| 13 | +{ |
| 14 | + /** |
| 15 | + * Display a listing of the resource. |
| 16 | + * |
| 17 | + * @return \Illuminate\Http\Response |
| 18 | + */ |
| 19 | + public function index() |
| 20 | + { |
| 21 | + // |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * Show the form for creating a new resource. |
| 26 | + * |
| 27 | + * @return \Illuminate\Http\Response |
| 28 | + */ |
| 29 | + public function create() |
| 30 | + { |
| 31 | + // |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Store a newly created resource in storage. |
| 36 | + * |
| 37 | + * @param \Illuminate\Http\Request $request |
| 38 | + * @return \Illuminate\Http\Response |
| 39 | + */ |
| 40 | + public function store(Request $request, $post_id) |
| 41 | + { |
| 42 | + $this->validate($request, array( |
| 43 | + 'name' => 'required|max:255', |
| 44 | + 'email' => 'required|email|max:255', |
| 45 | + 'comment' => 'required|min:5|max:2000' |
| 46 | + )); |
| 47 | + |
| 48 | + $post = Post::find($post_id); |
| 49 | + |
| 50 | + $comment = new Comment(); |
| 51 | + $comment->name = $request->name; |
| 52 | + $comment->email = $request->email; |
| 53 | + $comment->comment = $request->comment; |
| 54 | + $comment->approved = true; |
| 55 | + $comment->post()->associate($post); |
| 56 | + |
| 57 | + $comment->save(); |
| 58 | + |
| 59 | + Session::flash('success', 'Comment was added'); |
| 60 | + |
| 61 | + return redirect()->route('blog.single', [$post->slug]); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Display the specified resource. |
| 66 | + * |
| 67 | + * @param int $id |
| 68 | + * @return \Illuminate\Http\Response |
| 69 | + */ |
| 70 | + public function show($id) |
| 71 | + { |
| 72 | + // |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Show the form for editing the specified resource. |
| 77 | + * |
| 78 | + * @param int $id |
| 79 | + * @return \Illuminate\Http\Response |
| 80 | + */ |
| 81 | + public function edit($id) |
| 82 | + { |
| 83 | + // |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Update the specified resource in storage. |
| 88 | + * |
| 89 | + * @param \Illuminate\Http\Request $request |
| 90 | + * @param int $id |
| 91 | + * @return \Illuminate\Http\Response |
| 92 | + */ |
| 93 | + public function update(Request $request, $id) |
| 94 | + { |
| 95 | + // |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Remove the specified resource from storage. |
| 100 | + * |
| 101 | + * @param int $id |
| 102 | + * @return \Illuminate\Http\Response |
| 103 | + */ |
| 104 | + public function destroy($id) |
| 105 | + { |
| 106 | + // |
| 107 | + } |
| 108 | +} |
0 commit comments