public function store_familiar() { $colonia = Session::get("colonia"); $urbanism = Urbanism::where('colony_id', '=', $colonia)->first(); $post = Input::All(); $invited_id = md5(uniqid(mt_rand(), true)); $encrypted = Crypt::encrypt(md5(uniqid(mt_rand(), true))); $user_id = Auth::user()->id; $user_admin = Neighbors::where('user_id', '=', $user_id)->first(); $invited = new InvitedNeighbors(); $invited->neighbor_id = $user_admin->id; $invited->invited_id = $invited_id; $invited->urbanism_id = Input::get('urbanism'); $invited->email = Input::get('email'); $invited->confirmed = 0; $invited->confirmation_code = $encrypted; $invited->save(); $user = new UserNeighbors(); $user->email = Input::get('email'); $user->status_id = '1'; $user->confirmed = '1'; $user->confirmation_code = md5(uniqid(mt_rand(), true)); $user->save(); $last_user_add = $user->id; $role = Role::where('name', '=', 'vecino')->first(); $rol = new AssigmentRole(); $rol->user_id = $last_user_add; $rol->role_id = $role->id; $rol->colony_id = $colonia; $rol->save(); $neighbor = new Neighbors(); $neighbor->user_id = $last_user_add; $neighbor->name = Input::get('firstname'); $neighbor->last_name = Input::get('lastname'); $neighbor->phone = Input::get('phone'); $neighbor->save(); $last_neighbor_add = $neighbor->id; $urbanism_type = Input::get('urbanism_type'); $neighbor_properties = new NeighborProperty(); $neighbor_properties->neighbors_id = $last_neighbor_add; $neighbor_properties->urbanism_id = Input::get('urbanism'); $num_floor_id = null; $num_street_id = null; if ($urbanism_type == 3) { $num_floor_id = Input::get('piso'); $neighbor_properties->num_floor_id = $num_floor_id; } else { $num_street_id = Input::get('calle'); $neighbor_properties->num_street_id = $num_street_id; } $house = Input::get('casa'); $neighbor_properties->num_house_or_apartment = $house; $buscardomicilio = NeighborProperty::select('neighbors_properties.id')->where('neighbors_properties.urbanism_id', '=', $urbanism->id)->where('neighbors_properties.num_floor_id', '=', $num_floor_id)->where('neighbors_properties.num_street_id', '=', $num_street_id)->where('neighbors_properties.num_house_or_apartment', '=', $house)->first(); if ($buscardomicilio) { $status = 0; } else { $status = 1; } $neighbor_properties->status = $status; $neighbor_properties->save(); $neighbor_reg = InvitedNeighbors::where('invited_id', '=', $invited_id)->first(); $urbanism = Urbanism::where('id', '=', $neighbor_reg->urbanism_id)->first(); $email = $neighbor_reg->email; $data = array('email' => $email, 'link' => 'ConfirmationController@confirm_data_fam', 'code' => $neighbor_reg->confirmation_code, 'name_inv' => $user_admin->name, 'lname_inv' => $user_admin->last_name, 'urbanism' => $urbanism->name); Mail::send('emails.confirm_neighbors', $data, function ($message) use($email) { $message->subject('Invitación HABITARIA'); $message->to($email); }); $notice_msg = 'Datos guardados exitosamente'; return Redirect::action('ColonyController@reg_familiar')->with('error', false)->with('msg', $notice_msg)->with('class', 'info'); }
public function store() { $post = Input::All(); $urbanismNeigh = Input::get('urbanism'); $user = new UserNeighbors(); $user->email = Input::get('email'); $user->password = Hash::make(Input::get('password')); $user->status_id = '1'; $user->confirmed = '1'; $user->confirmation_code = md5(uniqid(mt_rand(), true)); $user->save(); $last_user_add = $user->id; $role = Role::where('name', '=', 'vecino')->first(); $urbanism = Urbanism::findOrFail(Input::get('urbanism')); $rol = new AssigmentRole(); $rol->user_id = $last_user_add; $rol->role_id = $role->id; $rol->colony_id = $urbanism->colony_id; $rol->save(); $neighbor = new Neighbors(); $neighbor->user_id = $last_user_add; //$neighbor->urbanism_id = Input::get('urbanism'); $neighbor->name = Input::get('firstname'); $neighbor->last_name = Input::get('lastname'); $neighbor->phone = Input::get('phone'); $neighbor->save(); $last_neighbor_add = $neighbor->id; $urbanism_type = Input::get('urbanism_type'); $neighbor_properties = new NeighborProperty(); $neighbor_properties->neighbors_id = $last_neighbor_add; $neighbor_properties->urbanism_id = Input::get('urbanism'); $num_floor_id = null; $num_street_id = null; if ($urbanism_type == 3) { $num_floor_id = Input::get('name_floor'); $neighbor_properties->num_floor_id = $num_floor_id; } else { $num_street_id = Input::get('name_street'); $neighbor_properties->num_street_id = $num_street_id; } $house = Input::get('num_house_or_apartment'); $neighbor_properties->num_house_or_apartment = $house; $buscardomicilio = NeighborProperty::select('neighbors_properties.id')->where('neighbors_properties.urbanism_id', '=', $urbanism->id)->where('neighbors_properties.num_floor_id', '=', $num_floor_id)->where('neighbors_properties.num_street_id', '=', $num_street_id)->where('neighbors_properties.num_house_or_apartment', '=', $house)->first(); if ($buscardomicilio) { $status = 0; } else { $status = 1; } $neighbor_properties->status = $status; $neighbor_properties->save(); $user_auth = User::where('id', '=', $last_user_add)->first(); $confirm = InvitedNeighbors::where('Confirmation_code', '=', Input::get('code'))->first(); $confirm->confirmed = true; $confirm->update(['id']); $colonies = Colony::select('colonies.id')->join('urbanisms', 'urbanisms.colony_id', '=', 'colonies.id')->join('neighbors_properties', 'urbanisms.id', '=', 'neighbors_properties.urbanism_id')->where('neighbors_properties.urbanism_id', '=', $urbanismNeigh)->first(); $user = Neighbors::where('id', '=', $last_neighbor_add)->pluck('user_id'); $user_auth = User::where('id', '=', $user)->first(); Auth::login($user_auth); if (Auth::check()) { Session::put('colonia', $colonies->id); return Redirect::action('HomeController@index'); } else { return Redirect::action('UsersController@login'); } }