I've made a simple Laravel CRUD, and I'm stuck on a problem.
My posts have a slug column and a uuid column in the table in which they are stored. I've binded the routes to the PostController using
Route::resource("posts", "PostController");
I want to be able to call the show route by using the slug in the URL, (example.com/posts/all-about-my-new-banana-maker), but to be able to call the edit route by using the UUID (example.com/posts/ddd83f7b-9c73-11eb-93c2-e55e28ace783/edit)
I've tried editing my Post model and changing getRouteKeyName:
class Post extends Model
{
use HasFactory;
// Set mass-assignable fields
protected $fillable = ["title", "content", "category", "image", "slug", "uuid"];
/**
* Get the route keyfor the model
* @return string
*/
public function getRouteKeyName() {
return "slug";
}
}
I can only see to have UUID or slug, not both at the same time. How could I make it so that both UUID and slug retrieve my post?