app/Http/Controllers/UsersController.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)
    {
        $this->validate($request,
        [
            'name'=>'string|required|max:30',
            'email'=>'string|required|unique:users',
            'password'=>'string|required',
            'role'=>'required|in:admin,user',
            'status'=>'required|in:active,inactive',
            'photo'=>'nullable|string',
        ]);
        $data=$request->all();
        $data['password']=Hash::make($request->password);
        $status=User::create($data);
        if($status){
            request()->session()->flash('success','Successfully added user');
        }
        else{
            request()->session()->flash('error','Error occurred while adding user');
        }
        return redirect()->route('users.index');
    }
public function store ( Request $ request ) { $ this -> validate ( $ request , [ 'name' => 'string|required|max:30' , 'email' => 'string|required|unique:users' , 'password' => 'string|required' , 'role' => 'required|in:admin,user' , 'status' => 'required|in:active,inactive' , 'photo' => 'nullable|string' , ] ) ; $ data = $ request -> all ( ) ; $ data [ 'password' ] = Hash :: make ( $ request -> password ) ; $ status = User :: create ( $ data ) ; if ( $ status ) { request ( ) -> session ( ) -> flash ( 'success' , 'Successfully added user' ) ; } else { request ( ) -> session ( ) -> flash ( 'error' , 'Error occurred while adding user' ) ; } return redirect ( ) -> route ( 'users.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// dd($request->all()); // dd($data); // dd($status);