learner1982
7 months ago
39
10
Laravel

Controller <> Model Conflict?

Posted 7 months ago by learner1982

i'm considering to use the same import alias, for my models, in all my controllers. Example:

App\Http\Controllers\ProductController.php

use App\Product as Model;
use App\Customer;
use App\User;
...
$model= Model::latest()->paginate(20);
$customer = Customer::latest()->paginate(20);
$user = User::latest()->paginate(20);

App\Http\Controllers\CustomerController.php

use App\Product;
use App\Customer as Model;
use App\User;
...
$product = Product::latest()->paginate(20);
$model = Model::latest()->paginate(20);
$user = User::latest()->paginate(20);

I think this will be good for code-reuse in many of my controllers.

Next I'm thinking that Traits will come in really handy, using the same "self" > Model syntax in all controllers.

Is this a good or bad idea?

Is there any side-effects that I'm not thinking of?

Thanks? :-)

Please sign in or create an account to participate in this conversation.