app/Http/Controllers/PostController.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)
    {
        $request->validate([
            'title' => 'required',
            'subtitle' => 'required',
            'body' => 'required'
        ]);
        $data = $request->all();
        $data['user_id'] = 1;
        $data['slug'] = Str::slug($data['title'], '-');
        $newPost = New Post();
        $newPost->fill($data);
        $saved = $newPost->save();
        if ($saved) {
            return redirect()->route('post.show', $newPost->slug);
        }
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'title' => 'required' , 'subtitle' => 'required' , 'body' => 'required' ] ) ; $ data = $ request -> all ( ) ; $ data [ 'user_id' ] = 1 ; $ data [ 'slug' ] = Str :: slug ( $ data [ 'title' ] , '-' ) ; $ newPost = New Post ( ) ; $ newPost -> fill ( $ data ) ; $ saved = $ newPost -> save ( ) ; if ( $ saved ) { return redirect ( ) -> route ( 'post.show' , $ newPost -> slug ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
// User ID // generate post slug // da modificare gestendo lo slug anzichè l'id