I have a eloquent query like this:
$entity= Entity::find($entity_id)
->join('address', 'entities.id', '=', 'address.entity_id');
dd($entity);
Now when I go to url /entities/243
I get the results from ::find however I do not get results from my ->join, so there is no address.
When I do this query:
$entity= Entity::where('id', $entity_id)
->join('address', 'entities.id', '=', 'address.entity_id')
->first();
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous (SQL: select * from
entities
inner joinaddress
onentities
.id
=address
.entity_id
whereid
= 50 andentities
.deleted_at
is null limit 1)
This is what I get, how would I structure this query properly? So I want to return entity that matches i.e and it's address, all within original array, I don't want it separate i.e
I want dd($entity); to give me:
entities fields: value address fields: value
so I don't have to go $entity->address to get to address, hopefully that makes sense.
Edit::
//
+"id": 43
+"name": "Costa Coffee Town Hall"
+"type": "Food & Drink"
+"tags": "Coffee, Cake, Food"
+"email": "cos@liveandnow.com"
+"logo": "http://ift.tt/2gKBrK3"
+"cover": ""
+"bio": null
+"main": null
+"twitter_business": null
+"facebook_business": null
+"instagram_business": null
+"google_places": null
+"eventbrite": null
+"featured": 1
+"ical": null
+"slug": null
+"url": null
+"video": null
+"api_key": null
+"contact_number": null
+"contact_name": null
+"geoloc_id": 142
+"deleted_at": null
+"created_at": "2017-07-27 16:08:12"
+"updated_at": "2017-08-15 10:17:31"
+"wikipedia": null
+"building_name": "The Old Town Hall"
+"address": "Parliament Square Greaves Street"
+"town": "Oldham"
+"postcode": "OL1 1QN"
+"telephone": "0161 926 7706"
+"private": 0
+"entity_id": 142
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2yJuUpH
via IFTTT
Aucun commentaire:
Enregistrer un commentaire