我如何在Laravel中进行全程路线 [英] How do I make a Catch-All Route in Laravel

查看:69
本文介绍了我如何在Laravel中进行全程路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个laravel route.php条目,该条目将捕获到网站特定domain.com/premium-section的所有流量,以便在访问高级内容之前提示人们成为会员.

I need a laravel routes.php entry that will catch all traffic to a specific domain.com/premium-section of the site so that I can prompt people to become members before accessing the premium content.

推荐答案

  1. 在app/Http/routes.php中,我创建了一条路由,该路由将捕获domain.com/premium-section/anywhere/they/try/to/go中的所有流量,并尝试在PremiumSectionController中查找并执行匹配功能
  2. 但是没有任何匹配方法,只是一个包罗万象的东西.

  1. In app/Http/routes.php I create a route that will catch all traffic within domain.com/premium-section/anywhere/they/try/to/go and attempt to find and execute a matching function within PremiumSectionController
  2. But there aren't any matching methods, just a catch-all.

Route::group(['as' => 'premium-section::',
              'prefix' => 'premium-section',
              'middleware' => ['web']],
              function(){
                 Route::any('', 'PremiumSectionController@premiumContentIndex');
                 Route::controller('/', 'PremiumSectionController');

              });

.

    namespace App\Http\Controllers;

    use ...

    class PremiumSectionController extends Controller{

        public function premiumContentIndex(){
           return 'no extra parameters';
        }

        //magically gets called by laravel
        public function missingMethod($parameters = array()){
            return $parameters;
        }

    }

这篇关于我如何在Laravel中进行全程路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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