I have a table, from an old database, where the primary key is a string. When I print it on the screen, it is printed like an integer. Eg. if the key is 8-001abc, on the screen I have 8.
This is my code: model
protected $table = 'mytable';
public $primaryKey = 'mykey';
public $incrementing = false;
protected $casts = [
'mykey' => 'string'
];
controller
$item = MyModel::where('somefield', '=', 0)->get();
return view('mymodel.index', compact('item'));
view
@foreach($item as $rowitem)
<p>{{ $rowitem->mykey }}</p>
@endforeach
any idea? thank you!