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 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的