app/Http/Controllers/WEB/RegisterController.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 register(Request $request)
    {  
        $this->validate($request,[
            'name'=>'required|max:30|min:4|regex:/(^([a-zA-Z]+)(\d+)?$)/u|unique:users',
            'email'=>'required|max:191|email|unique:users',
            'password'=>'required|max:191|min:6|confirmed',
            'password_confirmation'=>'required',
            'gender'=>'required',
            'phone'=>'required|max:15|min:11',
            'birthdate'=>'required|before:today',
            'user_image'=>'required',
            'role'=>'required',
            ]);
            if($request->file('user_image')  != null){
                $image = $request->file('user_image'); 
                $newimgname = uniqid().".".$image->getClientOriginalExtension();
                $image->move('imgs/uploaded/',$newimgname);
                $image_path= 'imgs/uploaded/'.$newimgname;
            }
          $registereduser = new User;
          $registereduser->name = request('name');
          $registereduser->email = request('email');
          $registereduser->password =bcrypt(request('password'));
          $registereduser->gender = request('gender');
          $registereduser->phone = request('phone');
          $registereduser->birthdate = request('birthdate');
          $registereduser->user_image = $image_path;
          $registereduser->role = request('role');
          $registereduser->visibility =1;
          $registereduser->save();  
           auth()->login($registereduser);
        return redirect('/login');
    }
public function register ( Request $ request ) { $ this -> validate ( $ request , [ 'name' => 'required|max:30|min:4|regex:/(^([a-zA-Z]+)(\d+)?$)/u|unique:users' , 'email' => 'required|max:191|email|unique:users' , 'password' => 'required|max:191|min:6|confirmed' , 'password_confirmation' => 'required' , 'gender' => 'required' , 'phone' => 'required|max:15|min:11' , 'birthdate' => 'required|before:today' , 'user_image' => 'required' , 'role' => 'required' , ] ) ; if ( $ request -> file ( 'user_image' ) != null ) { $ image = $ request -> file ( 'user_image' ) ; $ newimgname = uniqid ( ) . " . " . $ image -> getClientOriginalExtension ( ) ; $ image -> move ( 'imgs/uploaded/' , $ newimgname ) ; $ image_path = 'imgs/uploaded/' . $ newimgname ; } $ registereduser = new User ; $ registereduser -> name = request ( 'name' ) ; $ registereduser -> email = request ( 'email' ) ; $ registereduser -> password = bcrypt ( request ( 'password' ) ) ; $ registereduser -> gender = request ( 'gender' ) ; $ registereduser -> phone = request ( 'phone' ) ; $ registereduser -> birthdate = request ( 'birthdate' ) ; $ registereduser -> user_image = $ image_path ; $ registereduser -> role = request ( 'role' ) ; $ registereduser -> visibility = 1 ; $ registereduser -> save ( ) ; auth ( ) -> login ( $ registereduser ) ; return redirect ( '/login' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// validation // dd($request->file('user_image')); //rename the images files //holding the inserted image //moving the pic to images folder //image path // inserting data //login //   if( $registereduser->role == 'user') //   { //     return redirect('/home'); //   } //   else if( $registereduser->role == 'company') //   { //     return redirect('/homeofcompany'); //   } //   else //   { //     return redirect('/'); //   }  