Ejemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(CreateUserRequest $request)
 {
     $propertyKeys = array();
     $propertyKeys = ArrayCheckHelper::ignoreRepeated($request->all(), "property");
     /*foreach($request->all() as $key => $val){
      		if(preg_match("%^property[0-9]+$%", $key) && $val !== ""){
      			//check that a value doesn't repeat
      			$repeatedProperty= false;
      			foreach($propertyKeys as $propertyKey){
      				if($val == $propertyKey){
      					$repeatedProperty=true;
      					break;
      				}
      			}
      			if(!$repeatedProperty)
      				$propertyKeys[]= $val;
      		}
      	}   */
     if (count(Person::where('ci', $request->get('ci'))->get()) == 0) {
         Person::create(['ci' => $request->get('ci'), 'name' => $request->get('name'), 'last_name' => $request->get('last_name'), 'email' => $request->get('email'), 'telephone' => $request->get('telephone'), 'id_country' => $request->get('id_country')]);
     }
     $person = Person::where('ci', $request->get('ci'))->get()->first();
     $user = User::create(['id_person' => $person->id, 'id_role' => $request->get('id_role'), 'default_property' => $propertyKeys[0], 'auth_key' => 'some key', 'username' => $request->get('username'), 'password' => $request->get('password')]);
     $user->properties()->attach($propertyKeys);
     return \Redirect::route('admin.users.index');
 }
Ejemplo n.º 2
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }