Following a tutorial I have seen that its creator used something he had not seen until now that he was directly accessing the content of the attributes of a class without going directly through the attribute. He told me that this is called massive allocation, I searched for information in laravel's documentation but it must be very basic because it does not specify it well.
An example
Users Model
protected $fillable = ['nombre','apellidos','direccion,'codigo postal','email','contraseña'];
public function emailUsuario()
{
return $this->email ;
}
There comes my doubt (I do not understand that function), probably the easiest thing in the world and when you make a query to the model from another model such that.
$usuario = New User();
$usuario->email = $request->email
$usuario->save
or
User::create([$request->email])
I understand it much better, however as I say, I understand it when it is from another model but if you try to access the content of an attribute from the same class it is harder to understand it
This is what I do not understand
"return $this->email"
Here we really access the email field as if it were a class attribute, that is, as if the email was like this
protected $email;
but should not it be?
"return $this->fillable["email"]"
Here if we go through the variable fillable
I hope you understand what I want to argue
Can somebody explain to me why we did not pass for fillable and even then it is completely correct?