Working on issue #47, refactor place association code to make it simpler
This commit is contained in:
parent
cd3a71980d
commit
4254437d7c
1 changed files with 6 additions and 5 deletions
|
@ -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
|
||||||
//that’s the app’s 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:') {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue