【发布时间】:2015-03-21 04:29:43
【问题描述】:
我正在尝试设置中间件。 我遵循了这些说明:
http://mattstauffer.co/blog/laravel-5.0-middleware-filter-style
我的代码是
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\RedirectResponse;
class LoadVars {
$comingevents = App\Number::where('item','events')->get(array('quantity'));
我收到了这个错误:
LoadVars.php 第 24 行中的 FatalErrorException: 找不到类“App\Http\Middleware\App\Number”
在模型中,当我定义关系时,我使用 App\Number 并且效果很好。
在中间件方法中使用类的正确方法是什么?
【问题讨论】:
-
您已经通过在其前面加上反斜杠来指定绝对命名空间:
\App\Number,否则它将相对于您当前所在的命名空间(App\Http\Middleware)进行解释。或者您可以在顶部使用use App\Number;,然后使用Number::where(...);访问它 -
感谢您的提示。它帮助我了解新的 L5 命名空间规则。
标签: php class laravel middleware laravel-5