How to keep the fields of a form after being redirected by login or registration in Laravel?

Viewed 149

The business logic is as follows:

  1. Fill out the form to publish a card.
  2. Click on publish card button.
  3. Publish if only if the user is authenticated.
  4. If you are not authenticated, request to log in with the option to register.
  5. If the user is registered or logged in, redirect to the form keeping the fields filled.

This is the logic of what I want to do

Note:

  • I currently show the login view if it is not authenticated with the help of laravel's Authentication Middleware.
  • The login view has the option to register.
  • I do not have much experience in laravel, I would like you could be explicit in your answer.
1 Answers

Try this one

<input type="text" class="form-control" placeholder="Name" name="name" required value="{{ old('name') }}">

this keep old value when you return page.

if you want redirect page with data, use Compact. for example

$data["name"] = "name"
$data["gender"] = "something"
return view('your blade file path', compact('data'));

and on blade file

<input type="text" class="form-control" placeholder="Name" name="name" required value="{{ $data['name'] }}">
Related