I have my layout file defined as a component. I configured the component to receive a variable as an argument. I have my variable defined in my controller as the full DB CMS Model passed in a return view to the blade file. From there, I simply pass the variable when calling the component from within the blade file. Please note that doing it this way requires the long form using ":". I can't get it to recognize the variable inside the component call using the short form.
My controller:
public function show($id)
{
$document = Document::Post()->findOrFail($id);
return view('pages.blog.post.show-post')
->with("document", $document);
}
My component call within the view "show-post"
<x-layout.layout-master
:document=$document
>
Inside the master, the $document variable is now directly available and I can access anything from the Model.
The primary reason that I needed to do this is that I store default layout variables defined as attributes in the Model based on the document type, every html page starts from a document record. Sometimes I need to override those defaults.
I have override variables defined in my component, set with default = null. When needed, I add an explicit value to the override variable when calling layout-master. Inside layout-master, i use the override values if explicitly set to something other than null, otherwise I use the defaults from the document record to define the final layout of the html page.
I have just now worked this out for the first time and it seems to work so far.