app/Http/Controllers/Admin/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)
    {
        $this->validate(request(), [
            'fname' => 'required',
            'lname' => 'required',
            'email' => 'required|email|unique:users',
            'password' => 'required|min:6',
            'phonenumber' => 'required',
            'avatar-1' => ['mimes:jpeg,png']
        ]);
        if($request->hasfile('avatar-1'))
         {
            $file = $request->file('avatar-1');
            $avatarname=time().$file->getClientOriginalName();
            $file->move(public_path().'/img/staff', $avatarname);
         }else{
            $avatarname="default_avatar_male.jpg";
         }
        $user= new User;
        $user->fname=$request->get('fname');
        $user->lname=$request->get('lname');
        $user->email=$request->get('email');
        $user->role_id=$request->get('role_id');
        $user->password=Hash::make($request->get('password'));
        $user->phonenumber=$request->get('phonenumber');
        $date=date_create($request->get('date'));
        $format = date_format($date,"Y-m-d");
        $user->created_at = strtotime($format);
        $user->updated_at = strtotime($format);
        $user->avatar = $avatarname;
        $user->save();
        return redirect('admins/create')->with('success', 'Staff has been created successfully.');
    }
public function store ( Request $ request ) { $ this -> validate ( request ( ) , [ 'fname' => 'required' , 'lname' => 'required' , 'email' => 'required|email|unique:users' , 'password' => 'required|min:6' , 'phonenumber' => 'required' , 'avatar-1' => [ 'mimes:jpeg,png' ] ] ) ; if ( $ request -> hasfile ( 'avatar-1' ) ) { $ file = $ request -> file ( 'avatar-1' ) ; $ avatarname = time ( ) . $ file -> getClientOriginalName ( ) ; $ file -> move ( public_path ( ) . '/img/staff' , $ avatarname ) ; } else { $ avatarname = " default_avatar_male.jpg " ; } $ user = new User ; $ user -> fname = $ request -> get ( 'fname' ) ; $ user -> lname = $ request -> get ( 'lname' ) ; $ user -> email = $ request -> get ( 'email' ) ; $ user -> role_id = $ request -> get ( 'role_id' ) ; $ user -> password = Hash :: make ( $ request -> get ( 'password' ) ) ; $ user -> phonenumber = $ request -> get ( 'phonenumber' ) ; $ date = date_create ( $ request -> get ( 'date' ) ) ; $ format = date_format ( $ date , " Y-m-d " ) ; $ user -> created_at = strtotime ( $ format ) ; $ user -> updated_at = strtotime ( $ format ) ; $ user -> avatar = $ avatarname ; $ user -> save ( ) ; return redirect ( 'admins/create' ) -> with ( 'success' , 'Staff has been created successfully.' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .