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',
            'email' => 'required',
            'password' => 'required',
            'roles' => 'required|array'
        ]);
        $user = new User;
        $user->name = $request->name;
        $user->email = $request->email;
        $user->password = bcrypt($request->password);
        $user->save();
        $user->roles()->attach($request->roles);
        return redirect()->route('user.index')->with('success','oooooooh');
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'name' => 'required' , 'email' => 'required' , 'password' => 'required' , 'roles' => 'required|array' ] ) ; $ user = new User ; $ user -> name = $ request -> name ; $ user -> email = $ request -> email ; $ user -> password = bcrypt ( $ request -> password ) ; $ user -> save ( ) ; $ user -> roles ( ) -> attach ( $ request -> roles ) ; return redirect ( ) -> route ( 'user.index' ) -> with ( 'success' , 'oooooooh' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// $user->create($request->all());