Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 Models Folder

I have a directory called models inside app/ where I place all my model classes. Now I want to change the directory where the following command outputs the generated classes

php artisan make:model SomeModel 
like image 747
Alan Avatar asked Apr 16 '15 23:04

Alan


People also ask

Where are models stored in Laravel?

Models in Laravel 5.5 are created inside the app folder. Models are mostly used to interact with the database using Eloquent ORM.

How do I know Laravel Model?

Laravel find() method Example find method returns the model that has a primary key matching the given key . it will return also all models which have a primary key in given array.

What is Laravel vendor folder?

Role of vendor folder in Laravel The vendor is a subfolder in the Laravel root directory. It includes the Composer dependencies in the file autoload. php. Composer is a PHP based tool for dependency management. As a Laravel project works with many libraries, it requires the Composer for dependency management.

What are models in Laravel?

Laravel is an MVC based PHP framework. In MVC architecture, 'M' stands for 'Model'. A Model is basically a way for querying data to and from the table in the database. Laravel provides a simple way to do that using Eloquent ORM (Object-Relational Mapping). Every table has a Model to interact with the table.


2 Answers

You can't and, if you're hewing to Laravel's version of the universe, you shouldn't. Laravel 5 provides, and assumes, a PSR-4 naming convention for all its class files. This means models (and all classes) should be placed based on their full class name.

When you say

php artisan make:model SomeModel 

You're actually creating a model with the full name of App\SomeModel, so artisan creates the following file.

app/SomeModel.php 

If you said

php artisan make:model 'Test\SomeModel' 

you'd be creating a model with the full name App\Test\SomeModel, and Laravel would create the following file

app/Test/SomeModel.php 

So, its your model's full class name (namespace included) that determines where the class definition file is.

like image 195
Alan Storm Avatar answered Oct 19 '22 17:10

Alan Storm


I found it should be:

php artisan make:model ModelFolder\\SomeModel 
like image 42
Travis Yang Avatar answered Oct 19 '22 19:10

Travis Yang