Answer the question
In order to leave comments, you need to log in
Is it right to create a page structure with a controller?
Hello. An idea came up recently. Let's say the site has a complex structure with several kinds of pages and many repetitive elements. Would it be correct to build pages on such a site using a controller, as if by assembling them with a constructor - create views for repeating elements and then call them?
I'll explain a little. Suppose there is an article page on the site with a block of comments, and there is another page with a list of articles and displaying the latest comments on each element of this list. It would be logical to put the comments block in a separate display and call it on each page where comments need to be displayed, passing an array of comments to it.
Then the controller structure for each page, in a simplified form, will look like this:
...
$html .= veiw('...', [...]);
$html .= veiw('...', [...]);
$html .= veiw('...', [...]);
...
Answer the question
In order to leave comments, you need to log in
That's right - read the documentation and use view composer 's (or view creators).
Laravel uses inheritance patterns. Read what it is and you won't have to build a bike. And yes. View Composers will help you too, as JhaoDa said
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question