app/Http/Controllers/DashboardPostController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Post  $post
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Post $post)
    {   
        $rules = [
            'title' => 'required|max:255',
            'category_id' => 'required',
            'status' => 'required',
            'image' => 'image|file|max:1024',
            'body' => 'required'
        ];
        if($request->slug != $post->slug){
            $rules['slug'] = 'required|unique:posts';
        }
        $validatedData = $request->validate($rules);
        if($request->file('image')){
            if($request->oldImage){
                Storage::delete($request->oldImage);
            }
            $validatedData['image'] = $request->file('image')->store('post-image');
        }
        $validatedData['user_id'] = auth()->user()->id;
        $validatedData['excerpt'] = Str::limit(strip_tags($request->body), 200);
        Post::where('id', $post->id)
            ->update($validatedData);
        return redirect('dashboard/posts')->with('success', 'Edit Success');
    }
public function update ( Request $ request , Post $ post ) { $ rules = [ 'title' => 'required|max:255' , 'category_id' => 'required' , 'status' => 'required' , 'image' => 'image|file|max:1024' , 'body' => 'required' ] ; if ( $ request -> slug != $ post -> slug ) { $ rules [ 'slug' ] = 'required|unique:posts' ; } $ validatedData = $ request -> validate ( $ rules ) ; if ( $ request -> file ( 'image' ) ) { if ( $ request -> oldImage ) { Storage :: delete ( $ request -> oldImage ) ; } $ validatedData [ 'image' ] = $ request -> file ( 'image' ) -> store ( 'post-image' ) ; } $ validatedData [ 'user_id' ] = auth ( ) -> user ( ) -> id ; $ validatedData [ 'excerpt' ] = Str :: limit ( strip_tags ( $ request -> body ) , 200 ) ; Post :: where ( 'id' , $ post -> id ) -> update ( $ validatedData ) ; return redirect ( 'dashboard/posts' ) -> with ( 'success' , 'Edit Success' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .