Hi, I want to have two buttons in the home page (Writer & Reader) and these buttons will direct to the registration page by getting the value of the button (profession).
My routes:
Route::post('auth/register', [
'as' => 'writer_path',
'uses' => 'ProfessionController@displayForm'
]);
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');
When I type app.com/auth/register, it directs me to the page successfully.
I also created ProfessionController.php:
class ProfessionController extends Controller
{
//
public function displayForm()
{
$input = Input::get();
$profession = $input['profession'];
return view('auth/register', ['profession' => $profession]);
}
}
This is the home.blade.php:
{!! Form::open(['route' => ['writer_path']]) !!}
{!! Form::hidden('profession', 'writer') !!}
{!! Form::submit('Writer', array('class' => 'btn btn-warning')) !!}
{!! Form::close() !!}
When I click on the button to get navigated to the registration page, it doesn't direct me to anywhere.
This is the Network in Developer Tools:
This is what I get in the register>cookies:
Finally, I suspect this may be happen because of this bit in register.blade.php
<legend>Register</legend>
{!! Form::open(array('url' => '/auth/register')) !!}
{!! csrf_field() !!}
...
Source also seems fine:
<form method="POST" action="http://vocal.app/auth/register" accept-charset="UTF-8"><input name="_token" type="hidden" value="STbW72rcFbaa3M1nYPerO2fQHXGgr1gwvqeP1cHr">
<input name="profession" type="hidden" value="writer">
<input class="btn btn-warning" type="submit" value="Writer">
</form>
Edit #1
I tried this:
{!! Form::open(['route' => ['writer_path'], 'method' => 'POST']) !!}
and that:
$input = \Input::get();
but no luck.
Also, I tried: but still no output.
$input = Input::get();
$profession = $input['profession'];
dd($profession);
If I understand your code correctly you are trying to set up two routes with the same URL that point to different locations. That won't work since (for Laravel) it's the same thing, the end URL is always a POST request to /auth/register .
You'll have to use different URLs or check another way which controller to show.
ftiersch said:
If I understand your code correctly you are trying to set up two routes with the same URL that point to different locations. That won't work since (for Laravel) it's the same thing, the end URL is always a POST request to /auth/register .
You'll have to use different URLs or check another way which controller to show.
Solved!! Thanks
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community