Tuesday, October 18, 2016

How to pass parameter from one page to another in Laravel? | How to hide parameter from URL/ Route in Laravel?

laravel parameter passing


In this session I'm gonna write about how you can pass parameter from one page to another and while passing the value how you can hide it. Let's start the discussion...


1.  Suppose I want to send a parameter through a button from the first page to another page. Here, suppose course_id .

 <li> <a  href="{{route('registration',['course_id' => Crypt::encrypt('1') ])}}">IELTS</a> </li>
2. Now We're going to encrypt the parameter first and send it to through the route 'registration' .

3. Let's write the route :

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

4. Controller Part :

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

So when we send the variable course_id from the first page to second page, you'll see the course_id as encrypted in route.

5. Now if we want to save the course_id in database inside of  our second page. You can do like that:

 <input type="hidden" name="course_id" value="{{ $course_id }}" class="form-control" >
So this is how you can send a parameter from one page to another and save into database in second page.










Related Articles

0 comments:

Post a Comment