app/Http/Controllers/EmpresaController.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->is('api/*')) {
            $dataEmp                        = [];
            $dataEmp['nombre']              = $request->get('empresa');
            $dataEmp['costo']               = 0;
            $dataEmp['fecha_inicio']        = Carbon::now()->toDateString();
            $dataEmp['fecha_fin_pruebas']   = Carbon::now()->addDays(60)->toDateString();
            $dataEmp['ciudad_id']           = 1;
            $dataEmp['pruebas']             = 1;
            $dataEmp['usuarios_permitidos'] = 3;
            $empresa                        = Empresa::create($dataEmp);
            $empresa->configuracion()->create();
            $data             = $request->only(['email', 'nombre', 'apellido', 'telefono']);
            $data['password'] = bcrypt($request->get('password'));
            $usuario          = $empresa->usuarios()->create($data);
            $usuario->syncRoles('Administrador');
            if ($request->has('foto') && $request->get('foto') != null) {
                $usuario->foto = $request->file('foto')->store('public/usuarios');
                $usuario->save();
            }
            $usuario->notify(new EmpresaRegistradaNotification($usuario, $request->get('password')));
            return response()->json(['creado'=>true]);
        } else {
            $empresa = Empresa::create($request->all());
            $empresa->configuracion()->create();
        }
        return redirect('empresa');
    }
public function store ( Request $ request ) { if ( $ request -> is ( 'api/*' ) ) { $ dataEmp = [ ] ; $ dataEmp [ 'nombre' ] = $ request -> get ( 'empresa' ) ; $ dataEmp [ 'costo' ] = 0 ; $ dataEmp [ 'fecha_inicio' ] = Carbon :: now ( ) -> toDateString ( ) ; $ dataEmp [ 'fecha_fin_pruebas' ] = Carbon :: now ( ) -> addDays ( 60 ) -> toDateString ( ) ; $ dataEmp [ 'ciudad_id' ] = 1 ; $ dataEmp [ 'pruebas' ] = 1 ; $ dataEmp [ 'usuarios_permitidos' ] = 3 ; $ empresa = Empresa :: create ( $ dataEmp ) ; $ empresa -> configuracion ( ) -> create ( ) ; $ data = $ request -> only ( [ 'email' , 'nombre' , 'apellido' , 'telefono' ] ) ; $ data [ 'password' ] = bcrypt ( $ request -> get ( 'password' ) ) ; $ usuario = $ empresa -> usuarios ( ) -> create ( $ data ) ; $ usuario -> syncRoles ( 'Administrador' ) ; if ( $ request -> has ( 'foto' ) && $ request -> get ( 'foto' ) != null ) { $ usuario -> foto = $ request -> file ( 'foto' ) -> store ( 'public/usuarios' ) ; $ usuario -> save ( ) ; } $ usuario -> notify ( new EmpresaRegistradaNotification ( $ usuario , $ request -> get ( 'password' ) ) ) ; return response ( ) -> json ( [ 'creado' => true ] ) ; } else { $ empresa = Empresa :: create ( $ request -> all ( ) ) ; $ empresa -> configuracion ( ) -> create ( ) ; } return redirect ( 'empresa' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .