Support the ongoing development of Laravel.io →
Configuration Eloquent

I got 30 odd classes and code written in L4.2. Using eloquent extensively i have always used XyzModel::where('xyz','=',2)->get() queries a lot.

So now i had to add use App\Http\Model\XyzModel on top of all 30 files.

Instead i added the alias to the App.php file

My question is

  1. Is there any performance impact by having 30 Extra aliases in the app.php file
  2. When i use XyzModel::where('xyz','=',2)->get() i still get error, and if i use \XyzModel::where('xyz','=',2)->get() the error goes away. (In XyzController, the above Eloquent works in views without the \ ) Is there any way i can change the alias in app.js so as to i dont have to add an extra \ in front of the class.

My current alias looks like this 'UserGroup' => App\Http\Models\UserGroup::class,

The alias sometimes works, sometimes doesnt (using \ in front it starts working). why is this happening?

Last updated 2 years ago.
0

I'm also upgrading to L5 from 4.2 and have 30+ classes. I'm creating a command that talks to all of them, so I'm forced to have 37 use \App\Models\[name].php statements at the top of my Command class. Gross!

Obviously I understand the value in proper Namespacing, but this is serious code bloat for me. In 4.2, I could access all my models with use App\Models;. Now, unless I'm mistaken, I can't do that?

Most of my use cases won't require that many, but even 10-15 isn't great. I assume the caveat of the old 4.2 method is that everything is imported into a single namespace, which is good for having less code, but bad for performance / considered quite dirty.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

joy014 joy014 Joined 12 Apr 2014

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.

© 2025 Laravel.io - All rights reserved.