app/Http/Controllers/CommentsController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
 $this->validate($request, [
 'message' => 'required|min:10|max:255',
 ]);
 if(\Auth::user() == null){
     return view('home');
 }
 $comment = new Comment();
 $comment->user_id=\Auth::user()->id;
 $comment->message=$request->message;
 if($comment->save()){
     return redirect('comments');
 }
 return view('comments');
    }
public function store ( Request $ request ) { $ this -> validate ( $ request , [ 'message' => 'required|min:10|max:255' , ] ) ; if ( \ Auth :: user ( ) == null ) { return view ( 'home' ) ; } $ comment = new Comment ( ) ; $ comment -> user_id = \ Auth :: user ( ) -> id ; $ comment -> message = $ request -> message ; if ( $ comment -> save ( ) ) { return redirect ( 'comments' ) ; } return view ( 'comments' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// Podstawowa walidacja formularza: