app/Http/Controllers/Dashboard/EmpolyeeController.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)
    {
       if($request->hasFile('post_image')){
        $filenameWithExtention=$request->file('post_image')
        ->getClientOriginalName();
        $fileName=pathinfo($filenameWithExtention,
        PATHINFO_FILENAME) ;
        $max_file_uploads=500;
        $extension=$request->file('post_image')->getClientOriginalExtension();
        $fileNameStore=$fileName .'_'.time().'.'.$extension;
        $request->file('post_image')->move(public_path('uploads/images/images'),$fileNameStore);
    }else{
        $fileNameStore="noImage.jpg";
    }
       $employee=Employee::where('emp_name',$request->emp_name)->exists();
       if ($employee == false) {
           $request_data['emp_name']=$request->emp_name;
           $request_data['national_num']=$request->national_num;
           $request_data['adress']=$request->adress;
           $request_data['phone']=$request->phone;
        $request_data['emp_img']=$fileNameStore;
           $Employee=Employee::create($request_data);
           $user=User::where('email', $request->email)->exists();
           if ($user == false) {
               if ($request->emp_type == 1) {
                   $request_data=$request->except(['password','permission']);
                   $request_data['password']=Hash::make($request->password);
                   $request_data['employee_id']=$Employee->id;
                   $request_data['email']=$request->email;
                   $request_data['name']=$request->emp_name;
                   $request_data['national_num']=$request->national_num;
                   $request_data['adress']=$request->adress;
                   $request_data['phone']=$request->phone;
                   $request_data['user_img']=$fileNameStore;
                   $request_data['role_id_fk']='3';
                   $user=User::create($request_data);
                   $user->attachRole('super_admin'); 
               } elseif ($request->emp_type == 2) {
                   $request_data=$request->except(['password','permission']);
                   $request_data['password']=Hash::make($request->password);
                   $request_data['employee_id']=$Employee->id;
                   $request_data['name']=$Employee->emp_name;
                   $request_data['email']=$request->email;
                   $request_data['national_num']=$request->national_num;
                   $request_data['adress']=$request->adress;
                   $request_data['phone']=$request->phone;
                $request_data['user_img']=$fileNameStore;
                   $request_data['role_id_fk']='3';
                   $user=User::create($request_data);
                   $user->attachRole('admin'); 
               }
           }
       }else{
            notify_msg('error','هذا المستخدم موجود  مسبقا');
            return redirect('admin/employees/create');
        }
        return back();
    }
public function store ( Request $ request ) { if ( $ request -> hasFile ( 'post_image' ) ) { $ filenameWithExtention = $ request -> file ( 'post_image' ) -> getClientOriginalName ( ) ; $ fileName = pathinfo ( $ filenameWithExtention , PATHINFO_FILENAME ) ; $ max_file_uploads = 500 ; $ extension = $ request -> file ( 'post_image' ) -> getClientOriginalExtension ( ) ; $ fileNameStore = $ fileName . '_' . time ( ) . '.' . $ extension ; $ request -> file ( 'post_image' ) -> move ( public_path ( 'uploads/images/images' ) , $ fileNameStore ) ; } else { $ fileNameStore = " noImage.jpg " ; } $ employee = Employee :: where ( 'emp_name' , $ request -> emp_name ) -> exists ( ) ; if ( $ employee == false ) { $ request_data [ 'emp_name' ] = $ request -> emp_name ; $ request_data [ 'national_num' ] = $ request -> national_num ; $ request_data [ 'adress' ] = $ request -> adress ; $ request_data [ 'phone' ] = $ request -> phone ; $ request_data [ 'emp_img' ] = $ fileNameStore ; $ Employee = Employee :: create ( $ request_data ) ; $ user = User :: where ( 'email' , $ request -> email ) -> exists ( ) ; if ( $ user == false ) { if ( $ request -> emp_type == 1 ) { $ request_data = $ request -> except ( [ 'password' , 'permission' ] ) ; $ request_data [ 'password' ] = Hash :: make ( $ request -> password ) ; $ request_data [ 'employee_id' ] = $ Employee -> id ; $ request_data [ 'email' ] = $ request -> email ; $ request_data [ 'name' ] = $ request -> emp_name ; $ request_data [ 'national_num' ] = $ request -> national_num ; $ request_data [ 'adress' ] = $ request -> adress ; $ request_data [ 'phone' ] = $ request -> phone ; $ request_data [ 'user_img' ] = $ fileNameStore ; $ request_data [ 'role_id_fk' ] = '3' ; $ user = User :: create ( $ request_data ) ; $ user -> attachRole ( 'super_admin' ) ; } elseif ( $ request -> emp_type == 2 ) { $ request_data = $ request -> except ( [ 'password' , 'permission' ] ) ; $ request_data [ 'password' ] = Hash :: make ( $ request -> password ) ; $ request_data [ 'employee_id' ] = $ Employee -> id ; $ request_data [ 'name' ] = $ Employee -> emp_name ; $ request_data [ 'email' ] = $ request -> email ; $ request_data [ 'national_num' ] = $ request -> national_num ; $ request_data [ 'adress' ] = $ request -> adress ; $ request_data [ 'phone' ] = $ request -> phone ; $ request_data [ 'user_img' ] = $ fileNameStore ; $ request_data [ 'role_id_fk' ] = '3' ; $ user = User :: create ( $ request_data ) ; $ user -> attachRole ( 'admin' ) ; } } } else { notify_msg ( 'error' , 'هذا المستخدم موجود  مسبقا'); return redirect ( 'admin/employees/create' ) ; } return back ( ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//  $path=$request->file('post_image')->storeAs('public/uploads/images',$fileNameStore); //dd($request_data); /// super_admin // $user->syncPermissions($request->permission); // dd($request_data); /// super_admin // $user->syncPermissions($request->permission); // Session::flash('message', 'هذا المستخدم موجود  مسبقا');