Support the ongoing development of Laravel.io →
posted 9 years ago
Architecture
Last updated 2 years ago.
0

I think both ways will work, but I am thinking of controllers as classes that manage particular resource. Also laravel has some Route methods that make your life easier if you go this way.

E.g.

Route::resource('lead', 'LeadController');
Route::resource('inquiry', 'InquiryController');

In LeadController you can have a "index" method that will show all cars/leads available and a "show" method that will display a single car info page
In InquiryController you can have a "store" method that will store new inquiry for a car

Last updated 9 years ago.
0

Thanks TorchSK. I like the cleanness of this solution, but I wonder about the usage of LeadController for the car info page display. I think it works within this relatively straightforward scenario, but what if the page also contained info about an associated dealership. Which resource would be the 'primary' resource who's controller would get used? In that type of situation, would it be better to name the controller for the page name, and have it manage both resources ('leads' and 'dealers')?

0

Well it is a Lead information page. So the view should be called from Lead controller. This Lead controller can of course display another info than lead info (e.g. dealer info).

I would leave the name of this controller as LeadController, and in the show method just fetch all the data you need for thew view(page).

0

Sign in to participate in this thread!

Eventy

Your banner here too?

jegra jegra Joined 19 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.