简体   繁体   English

流明模型静态启动方法不起作用?

[英]Lumen Model Static Boot Method Not Working?

I am using lumen 5.6 and implementing global scopes for query builder and using the boot method to call the scope class. 我正在使用lumen 5.6并为查询生成器实现全局范围,并使用boot方法调用范围类。 Can someone have an idea why protected static function boot() not working in lumen 5.6 Below is my code? 有人可以知道为什么protected static function boot()lumen 5.6不起作用lumen 5.6以下是我的代码吗?

<?php

use App\Scopes\FilterSites;
use Illuminate\Database\Eloquent\Model;


class AccountTag extends Model {

var $useTable = 'tags_tbl';
var $primaryKey = 'tag_id';

protected static function boot()
{
    parent::boot();

    static::addGlobalScope(new FilterSites);
}

Uncomment the line where $app->withEloquent(); 取消注释$app->withEloquent();所在行$app->withEloquent(); is written in bootstrap/app.php . 是用bootstrap/app.php编写的。 The withEloquent() method registers the DatabaseServiceProvider and bootstrap Eloquent ORM . withEloquent()方法注册DatabaseServiceProvider并引导Eloquent ORM

You can test that your global filter is applied by registering a route that returns the sql statement for selecting all items in the model. 您可以通过注册返回用于选择模型中所有项目的sql语句的路由来测试是否应用了全局过滤器。

In routes/web.php , routes/web.php

$router->get('/account-tags', function () {
    return App\AccountTag::toSql();
});

When you browse the endpoint, the returned query should have a where clause matching FilterSites 浏览端点时,返回的查询应具有匹配FilterSites的where子句

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM