Laravel : How to hide url parameter?

Hola picture Hola · Oct 10, 2016 · Viewed 20.6k times · Source

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>

Answer

Imran Hossain picture Imran Hossain · Oct 10, 2016

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