I think just a little bit of flow logic needs to be put in to make this work.
The code below would give the user a form where they put in their reference number, we look up that number and get any additional info from the design and then redirect to the correct url.
// form
<form action="/findMyRef" method="post">
<input type="text" name="number">
</form>
// route
Route::post('/findMyRef', 'DesignController@route');
// DesignController
public function route(Request $request)
{
$design = Design::query()
->where('reference_number', $request->number)
->firstOrFail();
return redirect('/d/' . $design->slug );
}
Hi Ben, Thank you very much for providing that, totally makes sense and will give that a try. I did post the same question on Reddit and was advised to use Javascript to transfer the ref number directly in to the URL and query it BUT I am liking this idea a whole lot better, also helps as trying to avoid any unnecessary javascript on the project. Thanks again for the insight, hugely appreciated. Chris
nowendwell liked this reply
Works perfectly and will make sense to do it this way as I can validate the input too. Thanks @Ben
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community