I just tried one laravel course on udemy, but I write down what I felt compared to writing ruby on rails that I had studied so far.
With laravel, modifying the contents of the database is much easier than with rails. It's also quite helpful to have the up and down methods in the migration file by default.
What I found annoying when using rails was that every time I added or removed columns to a table or added options, I had to rollback or create a new migration file. It's a bad thing.
Furthermore, when adding options, if you don't write the up and down methods yourself, you'll want to delete the migration file later and you won't be able to go back using rollback (migrate: status to down). become unable). I remember doing it without knowing it at all and suffering a lot of pain.
In rails, validation is described in model, whereas it is described in model.
In laravel, write it in a file called controller or ** FormRequest ** that was not in rails.
In rails, validation was executed when executing Model create, save, update, but
laravel is in the method of controller. Also, if you write it in ** FormRequest **, you can make the validation finished when you enter the controller method.
This is the part I don't understand the most so far. It's a way of thinking that wasn't rails. (It seems that you can implement it yourself). For more information, read the Resources page at the end of this article. I can understand it somehow, but it is difficult to actually use it.
So I can't explain in detail here.
Simply put, ** don't instantiate in a class **.
Compared to rails, laravel is long and hard to write, whether command line or coding.
rails
items = Item.all
item = Item.find(1)
name = item.name
#Command line
rails s
rails db:migrate
laravel
$items = Item::all();
$item = Item::find(1);
$name = $item->name;
//Command line
php artisan serve
php artisan db:migrate
As you can see.
In order to add user authentication functions to rails, it was necessary to install a gem called devise, but in the case of laravel, it is provided by default. It's not that big of a difference, but for reference.
I'm still new to laravel, and there are some parts that I don't understand, but I've summarized them. I would appreciate it if you could point out any mistakes in the description.
Compare the features of Laravel and Rails! I tried to summarize routing, ORM, DI, etc. https://techblog.raccoon.ne.jp/archives/1550033605.html
How to specifically use Laravel Dependency Injection (DI) https://qiita.com/ishiitakeru/items/e47dbb3e5b07078cc9b5
Dependency injection https://laraweb.net/surrounding/2001/
Recommended Posts