app/Http/Controllers/Backend/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)
    {
        $validatedData = $request->validate([
            'role' => 'required',
            'name' => 'required',
            'phone' => 'required',
            'email' => 'required|unique:users|max:255',
            'password' => 'required',
            'image' => 'required',
        ]);
       $userData=new User();
       $userData->role=$request->role;
       $userData->name=$request->name;
       $userData->phone=$request->phone;
       $userData->email=$request->email;
       $userData->password=bcrypt($request->password);
        if($request->hasFile('image')){
            $file=$request->file('image');
            $extension=$file->getClientOriginalExtension();
            $newImage=time().'.'.$extension;
            $file->move('upload/user_images/',$newImage);
            $userData->image=$newImage;
        }else{
            return $request;
            $userData->image='';
        }
       $userData->save();
       Session::flash('success','User Created successfully');
       return redirect()->back();
    }
public function store ( Request $ request ) { $ validatedData = $ request -> validate ( [ 'role' => 'required' , 'name' => 'required' , 'phone' => 'required' , 'email' => 'required|unique:users|max:255' , 'password' => 'required' , 'image' => 'required' , ] ) ; $ userData = new User ( ) ; $ userData -> role = $ request -> role ; $ userData -> name = $ request -> name ; $ userData -> phone = $ request -> phone ; $ userData -> email = $ request -> email ; $ userData -> password = bcrypt ( $ request -> password ) ; if ( $ request -> hasFile ( 'image' ) ) { $ file = $ request -> file ( 'image' ) ; $ extension = $ file -> getClientOriginalExtension ( ) ; $ newImage = time ( ) . '.' . $ extension ; $ file -> move ( 'upload/user_images/' , $ newImage ) ; $ userData -> image = $ newImage ; } else { return $ request ; $ userData -> image = '' ; } $ userData -> save ( ) ; Session :: flash ( 'success' , 'User Created successfully' ) ; return redirect ( ) -> back ( ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .