Some of Eloquents in Laravel you may not know

Tram Ho

Laravel is probably not new to PHP Developer anymore, it’s a framework that I think is probably the best of PHP with a lot of features. But not everything Laravel can do is included in its documentation. Here are some features you may not know about

1. getOriginal ()

After altering a variable from a Model by assigning a new value to its element, you can still get the original value of that element using getOriginal

2. isDirty ()

Check if the value of a variable taken from the Model has been changed (It sounds like watching if the soul has been corrupted) 😄 )

3. Change the column name ‘deleted_at’

If you use the solf delete in Laravel, the time your data is deleted will be saved in the deleted_at column. If you want to rename that column, do the following

4. push ()

You can save the price of a result from the model and its relationship. I will have the relationship between the article and the author is 1 lot: 1 article will have 1 author. In the Post model

The processing will be as follows

5. is ()

Help you check for 2 values ​​from the model

6. replicate ()

You can copy a value of a model and save it as a new record;

7. Select the values ​​to retrieve from find ()

You can just retrieve the values ​​you want, it will be the same as that instead of you select * from then you select column1, column2, ... from

Above are some things I think will help you, thank you for reading 😄


Share the news now

Source : Viblo