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).
... protected $fillable = array(); ... protected $guarded = array('*'); ... protected $casts = array(); ...
Yes, by default every attribute is guarded. A total blacklist for maximum security!