dtcu5885 2018-05-11 13:05
浏览 6
已采纳

坚持使用Laravel Routing

Goal: Use Subdomain as a param and a unlimited amount of GET Params in "normal .. ?param=style" and "/param/style".

Current "web.php"

Route::group(array('domain' => "{bucketIdentifier}.$domainToUse"), function () {   
    Route::get('/{bucketIdentifier?}', 'BucketController@receive');
    Route::post('/{bucketIdentifier?}', 'BucketController@receive');
    Route::put('/{bucketIdentifier?}', 'BucketController@receive');
    Route::delete('/{bucketIdentifier?}', 'BucketController@receive');
    Route::patch('/{bucketIdentifier?}', 'BucketController@receive');
});

If you send a request to xyz.mydomain.com, i get the bucketIdentifier to query the DB. Works as designed.

If you send a GET Request with "?myparam=12&other=42" i can get the Param, works like designed.

But how can i also use "/myparam/12/other/42" for routed. With this setup i will get 404 as response.

Other aporoach (does not work)

Route::group(array('domain' => "{bucketIdentifier}.$domainToUse"), function () {   
    Route::get('/{query}', 'BucketController@receive')->where('query','.+');
    Route::post('/{query}', 'BucketController@receive')->where('query','.+');
    Route::put('/{query}', 'BucketController@receive')->where('query','.+');
    Route::delete('/{query}', 'BucketController@receive')->where('query','.+');
    Route::patch('/{query}', 'BucketController@receive')->where('query','.+');
});

Now i have the bucketIdentifier als "query" param (;

  • 写回答

4条回答 默认 最新

  • duankeng2026 2018-05-11 15:54
    关注

    To have a route that catches any path (including just /) you can use:

    Route::get('/{any}', 'BucketController@receive')->where('any', '.*');
    Route::post('/{any}', 'BucketController@receive')->where('any', '.*');
    Route::put('/{any}', 'BucketController@receive')->where('any', '.*');
    Route::delete('/{any}', 'BucketController@receive')->where('any', '.*');
    Route::patch('/{any}', 'BucketController@receive')->where('any', '.*');
    

    Or since you send all methods to the same controller:

    (::any registeres the routes for all methods: [get post put patch delete options])

    Route::any('/{any}', 'BucketController@receive')->where('any', '.*');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答