Here is link how to write code on this forum
https://help.github.com/articles/basic-writing-and-formatting-syntax/#quoting-code
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Sorry I'm a complete noob to the Eloquent stuff so I will try and explain as best possible what output I would like
I have 3 tables in a CMS system
pages page_id page_title page_description
meta_data meta_id meta_id_fk (page_id) object_id (either 1 or 2 pages are 1 and blogs are 2) meta_field_id (fk for meta_fields) raw_data (content) meta_fields field_id field_name
in my old site I would have a function which would be similar to this:
$page = select * from pages where page_slug = :page_slug ',
$pagedata = SELECT d.raw_data, f.field_name
FROM meta_data AS d
LEFT JOIN meta_fields AS f ON d.meta_field_id = f.meta_field_id
WHERE meta_id_fk = $page->page_id;
foreach ($pagedata as $values) {
$data[$values->field_name] = $values->raw_data;
}
return $data;
Now that I have discovered Laravel and models I started with
$page = Page::where('page_slug', '=', 'page_slug')->first();
$data = Page::where('page_slug', 'page_slug')->first()->MetaData;
in my Page Mode I have
public function MetaData()
{
return $this->hasMany('App\MetaData', 'meta_id_fk', 'page_id');
}
This works as I have the data but I want to join with meta_fields table In an ideal word I would like my array to be
$data = array(
['field_name1'] => 'raw_data',
['field_name12] => 'raw_data'
)
in my blade template I would like to do:
<p>This is the content {{ data.field_name; }}
The CMS is a bespoke one I inherited from the previous guy in my job and it seems to work ok. Any help or guidance would be most appreciated.
Thanks
Please or to participate in this conversation.