Closed andrewminion-luminfire closed 4 years ago
I think it would probably be a better idea to just pass the actual id of the model. A hashid is more useful when is displayed to users.
My app has a JS frontend and the hashids are visible and used by users and in the API requests it makes.
I would use hasids in views and original ids in api calls.
@andrewminion-luminfire
you can try to
$item = Outlet::findByHashidOrFail($hashid);
$id = $item->hashidToId($hashid);
$request->validate([
'name' => 'required|unique:outlets,name,' . $id,
]);
I’m using eloquent hashids on a number of related objects, and often I am passing a
related_model_id
as part of my request.Currently I’m only validating it as
string|required
but it would be great to be able to validate that the model actually exists, like theexists:table,column
validation rule.Is that something you’d consider adding?