Here the scenario is I want to pass a variable which will be send from one page to another and in next page it's gonna store through a form. So I have passed the variable from first page to second page through the URL. But I want to hide the parameter in the URL. How do I do it?
Here is my route :
Route::get('/registration/{course_id}',[
'uses'=>'AppController@getregistration',
'as'=>'registration'
]);
And Controller :
public function getregistration($course_id)
{
return view('index')->with('course_id',$course_id);
}
And first page this is how I send the value to first page:
<li> <a href="{{route('registration',['course_id' => '1'])}}">A</a> </li>
You cannot hide parameters. Even if you use the post method instead of the get method to remove parameters from the url. You can still see the passed parameters in the request message. The way to safely hide parameters is to encrypt them.
It's possible to hide the URL parameters from users by creating a PHP session. You must then store the parameters in session variables, use a PHP redirect to call the second PHP script and retrieve the session variable values in the second PHP script.
you can use session (if user is logged in) pass user id (not that good idea thou, users can guess that easily) make a POST request with params (not link, form is used for that)
The required parameters are the parameters that we pass in the URL. Sometimes you want to capture some segments of the URI then this can be done by passing the parameters to the URL. For example, you want to capture the user id from the URL.
Route
Route::post('/registration',['uses'=>'AppController@getregistration','as'=>'registration']);
View
{!!Form::open(array('url' => '/registration')) !!}
{!! Form::hidden('course_id', '1') !!}
{!! Form::submit('registration') !!}
{!! Form::close() !!}
Controller
public function getregistration(Request $request)
{
$course_id = $request->input('course_id');
return view('index')->with('course_id',$course_id);
}
use encryption method, it will show encrypted id in url
View
<li> <a href="{{route('registration',['course_id' => Crypt::encrypt('1') ])}}">A</a> </li>
Controller
public function getregistration($course_id)
{
$course_id = Crypt::decrypt($course_id);
return view('index')->with('course_id',$course_id);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With