app/Http/Controllers/Dashboard/UsersEmpController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\User  $user
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $data = $this->validate(
            request(),
            [
                'user_img' => 'image|mimes:jpg,jpeg,png,gif,bmp',
                'role_id' => 'required',
                'name' => 'required',
				'email'    => 'required|email|unique:users,email,'.$id,
                'password' => 'sometimes|nullable|min:6|confirmed',
                'password_confirmation' => 'sometimes|nullable',
            ]
        );
        $request_data['name'] = $request->name;
        $request_data['national_num'] = $request->national_num;
        $request_data['adress'] = $request->adress;
        $request_data['phone'] = $request->phone;
        if (request()->hasFile('user_img')) {
            $file = $request->file('user_img');
            $name = rand(11111, 99999) . '.' .$file->getClientOriginalName();
            $user = User::find($id);
            File::delete(('public/uploads/images/user_images/' . $user->user_img));
            $request->file('user_img')->move(public_path('uploads/images/user_images'),$name);
            $request_data['user_img'] = $name;
        }
        $request_data['email'] = $request->email;
        $request_data['password'] = Hash::make($request->password);
         User::where('id', $id)->update($request_data);
         $user = User::find($id);
        if ($request->role_id) {
            $user->syncRoles($request->role_id);
        }
        if ($request->permission && $request->role_id[0] != 1) {
            $user->syncPermissions($request->permission);
        }
		session()->flash('success', "تم التعديل بنجاح");
        return redirect('admin/usersemps');
    }
public function update ( Request $ request , $ id ) { $ data = $ this -> validate ( request ( ) , [ 'user_img' => 'image|mimes:jpg,jpeg,png,gif,bmp' , 'role_id' => 'required' , 'name' => 'required' , 'email' => 'required|email|unique:users,email,' . $ id , 'password' => 'sometimes|nullable|min:6|confirmed' , 'password_confirmation' => 'sometimes|nullable' , ] ) ; $ request_data [ 'name' ] = $ request -> name ; $ request_data [ 'national_num' ] = $ request -> national_num ; $ request_data [ 'adress' ] = $ request -> adress ; $ request_data [ 'phone' ] = $ request -> phone ; if ( request ( ) -> hasFile ( 'user_img' ) ) { $ file = $ request -> file ( 'user_img' ) ; $ name = rand ( 11111 , 99999 ) . '.' . $ file -> getClientOriginalName ( ) ; $ user = User :: find ( $ id ) ; File :: delete ( ( 'public/uploads/images/user_images/' . $ user -> user_img ) ) ; $ request -> file ( 'user_img' ) -> move ( public_path ( 'uploads/images/user_images' ) , $ name ) ; $ request_data [ 'user_img' ] = $ name ; } $ request_data [ 'email' ] = $ request -> email ; $ request_data [ 'password' ] = Hash :: make ( $ request -> password ) ; User :: where ( 'id' , $ id ) -> update ( $ request_data ) ; $ user = User :: find ( $ id ) ; if ( $ request -> role_id ) { $ user -> syncRoles ( $ request -> role_id ) ; } if ( $ request -> permission && $ request -> role_id [ 0 ] != 1 ) { $ user -> syncPermissions ( $ request -> permission ) ; } session ( ) -> flash ( 'success' , " تم التعديل بنجاح"); return redirect ( 'admin/usersemps' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//dd($request->all()); //dd($request_data); //dd($user);