Working on issue #47, refactor place association code to make it simpler

This commit is contained in:
Jonny Barnes 2017-03-22 19:36:45 +00:00
parent cd3a71980d
commit 4254437d7c

View file

@ -26,11 +26,12 @@ class NoteService
); );
if (array_key_exists('location', $data) && $data['location'] !== null && $data['location'] !== 'no-location') { if (array_key_exists('location', $data) && $data['location'] !== null && $data['location'] !== 'no-location') {
if (substr($data['location'], 0, strlen(config('app.url'))) == config('app.url')) { if (starts_with($data['location'], config('app.url'))) {
//uri of form http://host/places/slug, we want slug so chop off start //uri of form http://host/places/slug, we want slug
//thats the apps url plus `/places/` //get the URL path, then take last part, we can hack with basename
$slug = mb_substr($location, mb_strlen(config('app.url')) + 8); //as path looks like file path.
$place = Place::where('slug', '=', $slug)->first(); $slug = basename(parse_Url($data['location'], PHP_URL_PATH));
$place = Place::where('slug', $slug)->first();
$note->place()->associate($place); $note->place()->associate($place);
} }
if (substr($data['location'], 0, 4) == 'geo:') { if (substr($data['location'], 0, 4) == 'geo:') {