hardsshah's avatar

Why there is no model directory in Laravel5

Hi All, I was wondering why Taylor has removed the model directory from Laravel 5 and moved the models directly to app directory? Also is there any way i can move the models to a directory for my app, as i just like to tidy it up a bit.

0 likes
8 replies
bestmomo's avatar

You can put your models where you want, for example create app\Models, or something more distributed, depending on your application organisation. You just need to correctly namespace them.

Just take care for User model that is used for authentication. If you change its namespace you need to inform config/auth.php.

3 likes
toniperic's avatar
Level 30

Of course, you can move it wherever you want, just make sure to properly namespace it.

You can manually create app/Models/User.php and just make sure to namespace it, like so

namespace App\Models;

class User {
    // your code
}
4 likes
pmall's avatar

Also you have to use fully qualified class names for relationships.

JeffreyWay's avatar

People are so concerned about this. Just add the models directory back in, if you miss it.

4 likes
hardsshah's avatar

Thanks for the answers! it was really helpful... is there any way i don't have to use full class names? eg, App/models/drivers:: ?

rikh's avatar

You mean like this...

use App/models/drivers;

drivers::blar()

hardsshah's avatar

@JeffreyWay one of the concern is, if Taylor has removed directory, there might be some reason, i just wanted to be pretty sure that if he has removed it for a reason then i wouldn't like to add it back :)

4 likes
davorminchorov's avatar

The Laravel 4 folder default structure supports small apps from the start and with a little bit of customization, it can support bigger apps. The new folder structure in Laravel 5 supports medium apps and with a little bit of customization, it can support either smaller or bigger apps. It's different for every project.

Check this out: http://mattstauffer.co/blog/how-to-organize-class-namespaces

Please or to participate in this conversation.