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)
    {
        $request->validate([
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8'],
            'role' => ['required', 'not_in:0']
        ]);
        $user = new User();
        $user->name = $request->name;
        $user->email = $request->email;
        $user->password = Hash::make($request->password);
        $user->assignRole($request->role);
        if ($request->role == 'kasir') {
            $absen = new Absen();
            $absen->user_id = $user->id;
            $absen->absen = 0;
            $absen->kode_id = 1;
            $absen->created_at = Carbon::yesterday();
            $absen->save();
        }
        $user->save();
        return redirect()->route('users.index')->with('success', 'Data user berhasil ditambahkan');
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'name' => [ 'required' , 'string' , 'max:255' ] , 'email' => [ 'required' , 'string' , 'email' , 'max:255' , 'unique:users' ] , 'password' => [ 'required' , 'string' , 'min:8' ] , 'role' => [ 'required' , 'not_in:0' ] ] ) ; $ user = new User ( ) ; $ user -> name = $ request -> name ; $ user -> email = $ request -> email ; $ user -> password = Hash :: make ( $ request -> password ) ; $ user -> assignRole ( $ request -> role ) ; if ( $ request -> role == 'kasir' ) { $ absen = new Absen ( ) ; $ absen -> user_id = $ user -> id ; $ absen -> absen = 0 ; $ absen -> kode_id = 1 ; $ absen -> created_at = Carbon :: yesterday ( ) ; $ absen -> save ( ) ; } $ user -> save ( ) ; return redirect ( ) -> route ( 'users.index' ) -> with ( 'success' , 'Data user berhasil ditambahkan' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .