Laravel: How to hide url parameter?

In this scenario, I want to pass a variable that will be sent from one page to another, and on the next page it will be stored through a form. So I passed the variable from the first page to the second page by URL. But I want to hide the parameter in the URL. How to do it?

Here is my route:

Route::get('/registration/{course_id}',[ 'uses'=>' AppController@getregistration ', 'as'=>'registration' ]); 

And the controller:

 public function getregistration($course_id) { return view('index')->with('course_id',$course_id); } 

And the first page is how I post the value to the first page:

 <li> <a href="{{route('registration',['course_id' => '1'])}}">A</a> </li> 
+5
source share
3 answers

Shipping method

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); } 

Get method

use the encryption method, it will show the encrypted identifier in the 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); } 
+4
source

You cannot hide the parameter in the URL . If you do not want to show ID , try using SLUG . I hope you understand what SLUG . If you do not, then here. If the course title is My new course title , then its slug will be my-new-course-title . And make sure it is unique as the ID in the table. It is also good for SEO, readable and looks good.

+1
source

here you are not hiding the parameter in url, instead of converting the value of the encrypt or hash parameter is up to you,

another way is to first save the value in the session, and then call the value from the session without the definition parameter in the URL.

because the laravel route only works with the url / string / id template, post get. The dynamic value that you must write / receive using the template method.

Thanks.

0
source

Source: https://habr.com/ru/post/1257946/


All Articles