I needed to add public $incrementing = false
to the model class.
Why do my models return 0 when accessing a string-based primary key model property in Laravel 4?
-
19-10-2022 - |
Question
I have a table set up something like this:
Schema::create('capability', function($T) {
$T->string('code',32)->primary();
$T->string('name',64);
});
And a corresponding model like this:
class Capability extends BaseModel {
protected $table = 'capability';
protected $primaryKey = 'code';
public $timestamps = false;
}
When I seed some data like this...
$c1 = Capability::create(array(
'name' => 'Manage Clients',
'code' => 'manage_clients'
));
...and access the data members of $c1 like this...
echo $c1->name.", ".$c1->code;
...the result is Manage Clients, 0
.
Why is the result not Manage Clients, manage_clients
as I was expecting?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow