Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

etelford's avatar

4.3 Models and Repositories

Is it still recommended in 4.3 to use Repositories? If so, would we store them in app/Repositories and then have a folder in Repositories for each one of our Models, for example:

app/Respositories/DbRespository // abstract class
app/Respositories/User/UserRespository // interface
app/Respositories/User/DbUserRespository // extends DbRespository implements UserRespository
app/Respositories/Task/TaskRespository // interface
app/Respositories/Task/TaskUserRespository // extends DbRespository implements TaskRespository

Furthermore, if we were also leveraging Commands, those now go in app/Console, right? Should these be separated out by model as well, like:

app/Console/User/RegisterUserCommand
app/Console/User/ConvertUserCommand
app/Console/Task/UpdateTaskCommand
etc.
0 likes
1 reply
JoshWilley's avatar

The repository pattern is not specific to Laravel, so the version of Laravel you're using should not have an impact on what design patterns you choose to use.

This is an architecture question and it's purely up to you! In fact, I would say that the new folder structure in 4.3 gives you even more flexibility in the way that you organize your application.

For instance, you can now change the default namespace with a single Artisan command: php artisan app:name JoshWilley

// This would change the application's "default" namespace like so
App\Http\Controllers
App\Http\Filters
App\Http\Requests

JoshWilley\Http\Controllers
JoshWilley\Http\Filters
...etc

Regarding the command design pattern, you can organize it however you wish. However, I will note that the App/Console directory is intended to replace the old app/commands directory to be used for Artisan commands.

As @JeffreyWay points out countless times, a design pattern is just a tool for you to use to build your application. It's up to you to decide if it's the right tool for the job.

1 like

Please or to participate in this conversation.