11

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>
4
  • 2
    Use POST instead. Commented Oct 10, 2016 at 4:57
  • stackoverflow.com/questions/32076500/… or laracasts.com/discuss/channels/laravel/… Commented Oct 10, 2016 at 4:58
  • Then How I send the value to ? I have edited the Qus..Can you check again please? @RaxWeber Commented Oct 10, 2016 at 5:43
  • Instead of using <a> you've to build a form and using that you've to make a post request. Commented Oct 10, 2016 at 6:04

3 Answers 3

22

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);      
}
Sign up to request clarification or add additional context in comments.

1 Comment

nice one @imran
1

here is no way you hide parameter in url, rather then you convert parameter value encrypt or hash is up to you,

other-way is save value in session first, then call the value from session without define parameter in url.

because laravel route only working to pattern of url /string /id, post get. dynamic value you must be writing / getting using pattern method.

Thanks.

Comments

1

You cannot hide a parameter in URL. If you don't want to show the ID then try using SLUG. I hope you understand what is a SLUG. If you don't then here it is. If you course title is My new Course Title then its slug would be my-new-course-title. And make sure it is unique like an ID in the table. It is also good for SEO, readable and looks good.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.