Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here
Tutorial Free

Laravel Models folder: To Be or Not To Be

October 10, 2017
2 min read
This short post is inspired by some discussions that appear constantly in various forums or social media channels. Question of the day/month/year: why is there no app/Models folder? And do we need one?

Once upon a time there was a folder

Does anyone remember Laravel 4? There was a clear MVC folder structure there: app:
  • controllers
  • models
  • views
It was really easy to understand what to put where. At that time, to be honest, a lot of custom logic was put directly into models, therefore their importance was quite big.

Revolution in Laravel 5.0

People started panicking when default Laravel 5.0 installation didn't contain app/models folder anymore, along with other folder structure changes like app/Http or resources/views. From then default models were created directly in app/ folder, like app/User.php. At first there was a rant from the community - why the change? laravel y u no models The main reason is to support bigger application architecture with Laravel - separating the concerns and introducing layers like app/Http (everything related to routes) and resources (not only views but front-end stuff to compile). In this case models were kind of in the middle of everything. So they remained in just app/ folder. And it looks ok but not if project contains 20+ models, it becomes cluttered.

Guess what, you can have your folder

Of course, people started defending Taylor and offering a workaround - you can actually still have app/Models folder and put all the models there, as soon as you have a proper namespace inside:
namespace App\Models;
Also you can even generate models with artisan commands this way:
php artisan make:model Models/Book
The result is the file app/Models/Book.php:
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Book extends Model
{
    //
}

Or maybe use DDD?

There's another theory on how to structure your application folders - by domain, or "topic". So have subfolders for every topic and then inside of it have Models, Providers and whatever else you want. laravel ddd folders It won't be a default Laravel folder structure, but some developers are big fans of DDD (Domain-Driven Design). Read more here:

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.