Reputation: 7895
in some laravel based packages there is a reference to properties that are not declared but are the name of that model's table column .
tickets table:
id
name
content
and Ticket model:
class Ticket extends Model {
//there is no "protected $content;" defined inside model
$this->content = foo;
......
}
does model properties are created dynamically based on model table columns?
Upvotes: 1
Views: 357
Reputation: 59
Model attributes are implicitly declared depending on the mapped database table columns.
youcan explicitly declare the matching table
protected $table = 'tablename';
Upvotes: 0
Reputation: 164
You need to set $guarded or $fillable https://laravel.com/docs/5.1/eloquent#mass-assignment in your model. For example:
class Ticket extends model {
protected $guarded =[];
}
This let's you access all table columns and update them.
class Ticket extends model {
protected $fillable = ['name', 'content'];
}
This let's you access columns name
and content
and udpate only them.
Upvotes: 2