Laravel:如何隐藏 url 参数? [英] Laravel : How to hide url parameter?

查看:28
本文介绍了Laravel:如何隐藏 url 参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的场景是我想传递一个变量,该变量将从一个页面发送到另一个页面,并在下一页中通过表单存储.所以我已经通过 URL 将变量从第一页传递到第二页.但我想隐藏 URL 中的参数.我该怎么做?

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?

这是我的路线:

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

和控制器:

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>

推荐答案

发布方法

路线

Route::post('/registration',['uses'=>'AppController@getregistration','as'=>'registration']);

查看

{!!Form::open(array('url' => '/registration')) !!}
  {!! Form::hidden('course_id', '1') !!}
  {!! Form::submit('registration') !!}
{!! Form::close() !!}

控制器

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

获取方法

使用加密方式,会在url中显示加密的id

Get method

use encryption method, it will show encrypted id in url

查看

<li> <a  href="{{route('registration',['course_id' => Crypt::encrypt('1') ])}}">A</a> </li>

控制器

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

这篇关于Laravel:如何隐藏 url 参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆