How do I create sub directories to work in Laravel 5.1?

I am using Laravel 5.1. I usually do to create jobs php artisan make:job SomeJobName

. This would basically create a job SomeJobName

in the directory app/Jobs

. But what if my application is huge. I will end up with a lot of files in this folder. I want to organize it a bit. I want to make sub directories like:

app/Jobs/Users/
   Store.php
   Update.php
   Delete.php
app/Jobs/Posts
   Store.php
   Update.php
   Delete.php

      

What is the recommended approach for this?

+3


source to share


3 answers


artisan make:*

commands will accept a relative namespace so you can do something like this:

php artisan make:job Users/Store

      



You don't even need to create subdirectories as the artisan will create them if they don't exist.

+5


source


It's not a problem. Just create them manually and follow PSR naming conventions.

For example, the file app/Jobs/Posts/Store.php

will contain a class like:



namespace App\Jobs\Posts;

use App\Jobs\Job;

class Store extends Job {}

      

You can copy the rest of the class from the autogenerated version or follow the documentation .

+1


source


This should be possible if you change the namespaces later.

Create a subdirectory (like users), copy your work (like Store.php) and change the namespace to namespace App\Jobs\Users;

In the consuming script you need to import it with use App\Jobs\Users\Store;

or use a full qualifier\App\Jobs\Users\Store

+1


source







All Articles