app/Http/Controllers/Admin/PostController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Post $post)
    {
        $data = $request->all();
        if (Auth::user()->id != $post->user_id) {
            abort(403);
        }
        $validateData = $request->validate([
            'title' => 'required|max:240',
            'content' => 'required',
        ]);
        if ($data['title'] != $post->title) {
            $post->title = $data['title'];
            $post->slug = $post->createSlug($data['title']);
        }
        if ($data['content'] != $post->content) {
            $post->content = $data['content'];
        }
        $post->update();
        return redirect()->route('admin.posts.show', $post);
    }
public function update ( Request $ request , Post $ post ) { $ data = $ request -> all ( ) ; if ( Auth :: user ( ) -> id != $ post -> user_id ) { abort ( 403 ) ; } $ validateData = $ request -> validate ( [ 'title' => 'required|max:240' , 'content' => 'required' , ] ) ; if ( $ data [ 'title' ] != $ post -> title ) { $ post -> title = $ data [ 'title' ] ; $ post -> slug = $ post -> createSlug ( $ data [ 'title' ] ) ; } if ( $ data [ 'content' ] != $ post -> content ) { $ post -> content = $ data [ 'content' ] ; } $ post -> update ( ) ; return redirect ( ) -> route ( 'admin.posts.show' , $ post ) ; }
Update the specified resource in storage.
Update the specified resource in storage .