Suppose I have the following query,
$results = Listing::select('listings.id', 'listings.slug', 'page_contents.html_title AS name')
->join('page_contents', function ($join) {
$join->on('page_contents.subject_id', '=', 'listings.id')
->where('page_contents.subject_type', '=', 'App\Listing');
});
$results
will include the specified select columns (which is all I need), but also, all data for page_contents
,
{
"id": 3,
"slug": "omnis-et-harum-atque",
"name": "Omnis et harum atque",
"page_content": {
"id": 3,
"subject_type": "App\\Listing",
"subject_id": 3,
"html_title": "Omnis et harum atque",
"meta_title": "Omnis et harum atque",
... and a load more stuff I don't want,
"created_at": "2019-05-23 09:16:37",
"updated_at": "2019-05-23 09:16:37"
}
How do I remove page_content
from the returned data. The data is being returned for an API and so the page_data
info is way over the top.
Laravel 5.8
Cheers
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire