Level 88
Setting it to string should probably fix it! An integer is a string as well.
// app/User.php
class User extends Model
{
protected $keyType = 'string';
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hey!
In my app i use the standard primary key (id) for all models. For all my API Routes i want to use uuid's for model key binding - but only for the api routes.
In my RouteServiceProvider i use this to "rebind" the models but the problem ist my models are using keyType = int so the binding is not working correctly. Any ideas?
public function boot()
{
parent::boot();
if(request()->is('api*')) {
Route::model('users', function ($value) {
return \App\User::whereUuid($value)->firstOrFail();
});
}
}
Please or to participate in this conversation.