Descending the code in laravel 5.1

In this section you are going to read, I will go through the Model class and analyze it a little deeper than the usual. Nothing so advanced, so don’t worry: I will just use the class code to show you what you can do with your models.

Take it as a list of useful tips and tricks.

 

A big file

At the time of building hyguyz the Model class under IlluminateDatabaseEloquent counts 3361 lines of code, which is a big class with many methods and features. However, this length is acceptable considering that we can do the same thing in many different ways (just think about the save() method, the ::create() method, and the possibility to specify an associative array in the model constructor: three ways to insert a new record).

Recommended :  Easily monitor your Campaign in laravel

In the first part of the class you can see all the properties we saw before, set to their default values.

  ...

  protected $fillable = array();

  ...

  protected $guarded = array('*');

  ...

  protected $casts = array();

  ...

Yes, by default every attribute is guarded. A total blacklist for maximum security!

About the author

Deven Rathore

I'm Deven Rathore, a multidisciplinary & self-taught designer with 3 years of experience. I'm passionate about technology, music, coffee, traveling and everything visually stimulating. Constantly learning and experiencing new things.

Pin It on Pinterest

Shares