app/Http/Controllers/Dashboard/UserController.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,User $user)
    {
        $request->validate([
            'first_name' => 'required',
            'last_name' => 'required',
            'email' => ['required', Rule::unique('users')->ignore($user->id),],
            'image' => 'image',
            'permissions' => 'required|min:1'
        ]);
        $request_data = $request->except(['permissions', 'image']);
        if ($request->image) {
            if ($user->image != 'default.png') {
                Storage::disk('public_uploads')->delete('/user_images/' . $user->image);
            }
            Image::make($request->image)
                ->resize(300, null, function ($constraint) {
                    $constraint->aspectRatio();
                })
                ->save(public_path('uploads/user_images/' . $request->image->hashName()));
            $request_data['image'] = $request->image->hashName();
        }
        $user->update($request_data);
        $user->syncPermissions($request->permissions);
        session()->flash('success', __('site.updated_successfully'));
        return redirect()->route('dashboard.users.index');
    }
public function update ( Request $ request , User $ user ) { $ request -> validate ( [ 'first_name' => 'required' , 'last_name' => 'required' , 'email' => [ 'required' , Rule :: unique ( 'users' ) -> ignore ( $ user -> id ) , ] , 'image' => 'image' , 'permissions' => 'required|min:1' ] ) ; $ request_data = $ request -> except ( [ 'permissions' , 'image' ] ) ; if ( $ request -> image ) { if ( $ user -> image != 'default.png' ) { Storage :: disk ( 'public_uploads' ) -> delete ( '/user_images/' . $ user -> image ) ; } Image :: make ( $ request -> image ) -> resize ( 300 , null , function ( $ constraint ) { $ constraint -> aspectRatio ( ) ; } ) -> save ( public_path ( 'uploads/user_images/' . $ request -> image -> hashName ( ) ) ) ; $ request_data [ 'image' ] = $ request -> image -> hashName ( ) ; } $ user -> update ( $ request_data ) ; $ user -> syncPermissions ( $ request -> permissions ) ; session ( ) -> flash ( 'success' , __ ( 'site.updated_successfully' ) ) ; return redirect ( ) -> route ( 'dashboard.users.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//end of inner if //end of external if