Skip to content

Instantly share code, notes, and snippets.

@pmkay
Last active January 6, 2023 09:21
Show Gist options
  • Save pmkay/39dfb9855b3cff82fc12770f2aea4e73 to your computer and use it in GitHub Desktop.
Save pmkay/39dfb9855b3cff82fc12770f2aea4e73 to your computer and use it in GitHub Desktop.
Using multiple keys for route model binding in Laravel
<?php
public function boot()
{
Route::bind('course', function ($value) {
return Course::where('slug', $value)->orWhere(function ($query) use ($value) {
if (is_numeric($value)) {
$query->where('id', $value);
}
})->firstOrFail();
});
parent::boot();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment