Support the ongoing development of Laravel.io →
Forms Laravel
Last updated 2 years ago.
0

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 );
}
Last updated 4 years ago.
0

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

1

Works perfectly and will make sense to do it this way as I can validate the input too. Thanks @Ben

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Chris error500 Joined 16 Jan 2020

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.