app/Http/Controllers/UserController.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([
            'name' => ['required','min:5','max:30'],
            'email'=> ['required','unique:users'],
            'password'=> ['required','min:6'],
            'phone'=> ['required','min:8','max:12']
        ]);
        $user = new user;
        if($request->hasFile('image')){
            if($user->image != "")
            {
                $file_path = public_path('images/user_images/').$user->image;
                unlink($file_path);
            }
             $fileName = time().'.'.request()->image->getClientOriginalExtension();
             request()->image->move(public_path('images/user_images'), $fileName);
             $user->image =  $fileName;
         }
        $user->name = $request->name;
        $user->email = $request->email;
        $user->password = Hash::make($request->password);
        $user->phone = $request->phone;
        $user->role = $request->role;
        $user->save();
        return redirect()->to("/usersListing")->with('success',"User Create Successfully");
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'name' => [ 'required' , 'min:5' , 'max:30' ] , 'email' => [ 'required' , 'unique:users' ] , 'password' => [ 'required' , 'min:6' ] , 'phone' => [ 'required' , 'min:8' , 'max:12' ] ] ) ; $ user = new user ; if ( $ request -> hasFile ( 'image' ) ) { if ( $ user -> image != " " ) { $ file_path = public_path ( 'images/user_images/' ) . $ user -> image ; unlink ( $ file_path ) ; } $ fileName = time ( ) . '.' . request ( ) -> image -> getClientOriginalExtension ( ) ; request ( ) -> image -> move ( public_path ( 'images/user_images' ) , $ fileName ) ; $ user -> image = $ fileName ; } $ user -> name = $ request -> name ; $ user -> email = $ request -> email ; $ user -> password = Hash :: make ( $ request -> password ) ; $ user -> phone = $ request -> phone ; $ user -> role = $ request -> role ; $ user -> save ( ) ; return redirect ( ) -> to ( " /usersListing " ) -> with ( 'success' , " User Create Successfully " ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .