/** * @test */ public function canEditAddress() { $address = $this->guardian()->addresses()->orderBy('created_at', 'DESC')->first(); $name = 'Test ' . rand(1, 400000); $this->visit('/account/address')->click('#edit-' . $address->id)->type($name, 'name')->press('Save')->see('Your changes were saved'); // can't figure out why the address is showing up cached // in the browser... so we'll check the DB directly $this->assertEquals($name, Address::findOrFail($address->id)->name); }
/** * Handle the event. * * @param Address $address * * @return void */ public function handle(Address $address) { if (app()->environment('testing')) { app('log')->info('Not fetching coordinates for address while testing'); return; } try { // object was serialized, so get a new one with DB connectivity $address = Address::findOrFail($address->id); $response = json_decode(Geocoder::geocode('json', ['address' => implode(' ', [$address->address_one, $address->address_two, $address->city, $address->state, $address->zip_code]), 'componets' => 'country:GB'])); if ($response->status == 'OK') { $address->latitude = $response->results[0]->geometry->location->lat; $address->longitude = $response->results[0]->geometry->location->lng; // Figure out the city/state foreach ($response->results[0]->address_components as $addressParts) { if (property_exists($addressParts, 'types') && is_array($addressParts->types)) { if (in_array('administrative_area_level_1', $addressParts->types)) { $address->state = $addressParts->short_name; } elseif (in_array('locality', $addressParts->types)) { $address->city = $addressParts->long_name; } } } // use township as the city if (strlen($address->city) == 0) { foreach ($response->results[0]->address_components as $addressParts) { if (property_exists($addressParts, 'types') && is_array($addressParts->types)) { if (in_array('administrative_area_level_3', $addressParts->types)) { $address->city = $addressParts->long_name; } } } } $address->save(); $this->delete(); } elseif (DatabaseSeeder::isSeeding() === false && app()->environment('testing') === false) { Log::error('Problematic response from GMaps', ['address' => $address, 'response' => (array) $response]); } } catch (\RuntimeException $e) { //ignore failures if we're local. //useful when seeding and not on the internet if (DatabaseSeeder::isSeeding() || App::environment('local', 'testing') && $e->getMessage() == 'cURL request retuened following error: Could not resolve host: maps.googleapis.com') { Log::debug('Suppressing error when fetching coordinates for address'); return; } throw $e; } }
@extends('emails.simple') @section('body') <?php // Serialized objects need to be re-instantiated in order // to have a successful database connection $primaryAddress = \BibleBowl\Address::findOrFail($guardian['primary_address_id']); $group = \BibleBowl\Group::findOrFail($groupId); $playerCount = count($players); ?> @if ($hasEmailBody) @include('emails.theme.text-block', [ 'body' => $emailBody ]) @include('emails.theme.empty-spacer') @endif @include('emails.theme.header', [ 'header' => 'Registration Confirmation' ]) <table cellpadding="0" cellspacing="0" bgcolor="#f4f4f4" border="0"> <tr> <!--=========== JUST ENTER YOUR INFO HERE =========--> <td valign="middle" bgcolor="#f4f4f4" height="10" class="sectionRegularInfoTextTD" style="border-collapse: collapse;color: #42484c;font-family: Arial, Tahoma, Verdana, sans-serif;font-size: 13px;font-weight: lighter;padding: 0;margin: 0;text-align: left;line-height: 165%;letter-spacing: 0;"> @include('emails.theme.text-block', [ 'body' => 'Please double check the below information to ensure everything is correct. If you find a mistake, you can '.EmailTemplate::link(url('login'), 'login to your Bible Bowl account').' and correct the mistake.' ])
public static function validationRules($groupAlreadyExists = false) { // Check to see if a group is a duplicate by looking at the location where they meet (zip code or city/state // and their program/name when the group is created Validator::extend('isnt_duplicate', function ($attribute, $value, $parameters, $validator) { $meetingAddress = Address::findOrFail($validator->getData()['meeting_address_id']); $group = Group::where('name', $value)->where('program_id', $validator->getData()['program_id'])->whereHas('meetingAddress', function ($query) use($meetingAddress) { $query->orWhere(function ($query) use($meetingAddress) { $query->where('city', '=', $meetingAddress->city); $query->where('state', '=', $meetingAddress->state); })->where('zip_code', '=', $meetingAddress->zip_code); })->first(); return is_null($group); }); return ['name' => 'required|max:128' . ($groupAlreadyExists ? '' : '|isnt_duplicate'), 'program_id' => 'required', 'owner_id' => 'required|exists:users,id', 'address_id' => 'required|exists:addresses,id']; }
/** * @param AddressOwnerOnlyRequest $request * @param $id * * @return mixed */ public function update(AddressOwnerOnlyRequest $request, $id) { $this->validate($request, Address::validationRules(), Address::validationMessages()); Address::findOrFail($id)->update($request->all()); return redirect('/account/address')->withFlashSuccess('Your changes were saved'); }