普通网友 2014-05-06 10:40
浏览 72

Laravel 4 - 隐藏URL中的变量。

I have the following Route:

 Route::resource('projects.deliveries.tasks', 'TaskController');

And of course if I want to create a task, my URL looks like this:

 http:://test.dev/projects/1/deliveries/3/tasks/create

For Project Number 1 and delivery number 3.

http://i.imgur.com/RlHHY31.jpg

But I don't want the number to show up in the URL, because tasks should be creatable, without authentication or login.

Is there a way to hide these numbers, so that I get a clean URL like this:

http:://test.dev/projects/delivereis/tasks/create

And Laravel understands from my logic, that it is Project 1 and devivery 3 for which a task is to be created?

  • 写回答

1条回答 默认 最新

  • duancong7358 2014-05-07 06:15
    关注

    If you want to do this, you should probably specify your routes manually. Using Route::resource() is great if you're absolutely going to use the resource as intended (with verbose routes) but it doesn't provide you with much flexibility. In fact for most projects it's actually recommended that you do define all your routes manually to give you the most control (and it's also great self-documentation in your routes.php file).

    Route::get('projects/deliveries/tasks/create', ['as' => 'projects.deliveries.tasks.create', 'uses' => 'TasksController@create']);
    Route::post('projects/deliveries/tasks', ['as' => 'projects.deliveries.tasks.store', 'uses' => 'TasksController@store']);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序