Is it good practice to create Models directory? [closed] - laravel

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
By default, Laravel's model classes are placed in the App/ directory and models files mess up the App/ directory.
So, I want to create an App/Models/ directory and move all model classes to App/Models/.
And there are many articles in the internet and stackoverflow answers about how to do that.
My question is whether it is a good practice or bad practice to move models to App/Models/ in Laravel?
Laravel doesn't do it by default, so I think it should be a very bad practice because it is said that Laravel gives developers the best practices, and I'm afraid that moving models to App/Models/ causes troubles in the future while developing.
If it is a good practice, why doesn't Laravel do it by default?

It is completely okay to do like that. Always I create separate folders for Frontend, backend controllers also. In Models also you can do as per you wish. Only thing is you have to define namespace depend on that.

That is not quite right. Since Laravel 8, the models can be found under App/Models. And I think it's better that way.

Related

Many laravel apps in one server. How to organize? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I'll be setting up a server that will host several laravel applications. There will be a few ones at the beginning, but with time we can end up having dozens of them. Most of which (if not all) will be laravel projects.
I'm not sure how to organize all this. I have several choices:
Use a different laravel project for each application. Every application would be placed in a different directory. That would mean lots of files and space taken up by apps.
Use a single laravel project, having a src folder inside the project where I would be placing each application in a separate subfolder. Each of these subfolders would contain only the service provider(s) of each app, as well as their own routes, controllers, rules, etc.
I've been told lately of an approach similar to the second one, but instead of placing the apps in src directory, each app would be developed as a library, and the main laravel project would require each one of them. That way, apps would be in vendor dir, and could easily be required or unrequired.
I can also group applications across a few laravel projects, using either approach 2 or 3.
What are the advantages and inconvenients of each one of these approaches? Is there an optimal approach to this problem?
Thanks!
If they are different and not connected in anyway, the best thing in my opinion is to have their own seperate projects because it would be easier to deal with the webserver (like nginx) and the other options would just make everything more complicated.

Where to put classes in a Laravel project [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I have a coded years ago a custom PHP class to create and manage HTML tables.
I'd like to add it in my new Laravel project.
Where do you think it would be the best to put those files ?
Best regards,
Nicolas
It's as you want. Laravel adopts the MVC architecture, if you see that your PHP class deals with databases put it Model folder (/App), if it's dealing with views, put it in views folder (/resources/views) and if it's a controller class you have to put it in controller (/App/Http/Controllers).
But the main thing you have to do is to read the Laravel documentation to understand really how it works. The link for the documentation is https://laravel.com/docs

Is it still relevant to use Repository Pattern in a laravel application?” [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I'm setting up a new laravel project, and want to reduce code in my controllers. Do I need to use repository pattern?”
Do I need to use repository pattern?
Trying to organise your code doesn't directly mean that you "have to" and "need to" use the repository pattern. You can safely use helper classes to extract some of the logic from the controllers. Moreover, Laravel structures its code quite well. You can help it by implementing gateways or using observers where possible. Using events is a possibility too. However, you should be aware of how these things work before implementing them since you might introduce errors with the testing later on.

Ruby script folder structure [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have several Ruby scripts that have been refactored to use common methods. What folder structure should I use for these files?
For example: I have reports "Grower", "Fecal", "30Day", "30DayFecal", etc. that all use methods in files "date_of", "get_fecal_data", "get_fy", "chart_fecal", etc. I'm thinking that I should set up folders like;
App
-Grower
-Fecal
-30Day
-30DayFecal
-lib
-date_of.rb
-get_fecal_data.rb
-get_fy.rb
-chart_fecal.rb
Please advise.
Seems you're being partially influenced by the Rails folder layout.
app
models
controllers
views
lib
...
You can use that, since it is a common way to think, and will aid you getting advice from others. Just be sure to make it clear that you're not developing a Rails app, so you don't create other confusions.
Views
These can be any output-formatters. Rails app commonly export data in .csv format, for instance.
Controllers
These, along with services and related concepts, are things that manipulate data after a Model has retrieved it from a 'store' (e.g. a file on disk, database, or anything).
A common convention is that Controllers depend upon Models, whereas Lib[raries] is self-sufficient. Some would say that Services depend upon external API data.

what is the best way to use same lib, helpers, etc in different CodeIgniter Projects? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I have a lot of codes in libraries, helpers, models of my old codeigniter projects.
I want to start a new project that I think I can use those codes without rewriting them. Also, when I want to update the codes in the libraries, helpers or models, I only have to update them once in one file. However if I copy and paste the file to the new project, I have to update each of them when I have an update in the code.
So how can I do this in best practice?
Thank You
Have a look at theis article by Phil Sturgeon - in it he details a way to create a 'shared' folder, so that you can run multiple codeigniter installations from the same shared folder.
http://codeigniter.com/forums/viewthread/136321/
Since Codeigniter 2.0 you can share same system folder among many projects. In previous versions you can do this with a little tweak. So once you have a common system folder you can keep all you libraries and helpers here which can be used by all the projects. There is no provision to have common models so either you can transform them to helper or library class, which actually makes sense.

Resources