我正在使用Laratrust并尝试实现: 我创建了这些文件
应用\ MyMenuFilter.php
CREATE TABLE OWNER
(
OwnerID Int NOT NULL IDENTITY (1,1) PRIMARY KEY,
OwnerName Char(30) NOT NULL,
OwnerEmail VarChar(100) NULL,
OwnerType Char(15) NOT NULL,
);
CREATE TABLE PROPERTY
(
PropertyID Int NOT NULL IDENTITY(1,1) PRIMARY KEY,
PropertyName Char(30) NOT NULL,
Street Char(20) NOT NULL,
City Char(25) NOT NULL,
State Char(10) NOT NULL,
Zip Char(5) NOT NULL,
OwnerID Int NOT NULL,
CONSTRAINT PROP_OWN_FK FOREIGN KEY(OwnerID)
REFERENCES OWNER(OwnerID),
);
CREATE TABLE GG_EMPLOYEE
(
EmployeeID Int NOT NULL IDENTITY(1,1) PRIMARY KEY,
LastName Char(35) NOT NULL,
FirstName Char(35) NOT NULL,
CellPhone Char(20) NOT NULL,
ExperienceLevel Char(25) NOT NULL,
);
CREATE TABLE SERVICE
(
PropertyID Int NOT NULL,
EmployeeID Int NOT NULL,
ServiceDate Char(15) NOT NULL,
HoursWorked Char(5) NOT NULL,
CONSTRAINT SERVICE_PK PRIMARY KEY(PropertyID, EmployeeID, ServiceDate),
CONSTRAINT SER_PRO_FK FOREIGN KEY(PropertyID)
REFERENCES PROPERTY(PropertyID),
CONSTRAINT SER_GG_EMP_FK FOREIGN KEY(EmployeeID)
REFERENCES GG_EMPLOYEE(EmployeeID),
);
我改变了这一点 配置\ adminlte.php
<?php
namespace App;
use JeroenNoten\LaravelAdminLte\Menu\Builder;
use JeroenNoten\LaravelAdminLte\Menu\Filters\FilterInterface;
class MyMenuFilter implements FilterInterface
{
public function transform($item, Builder $builder)
{
if (isset($item['permission']) && Laratrust::can($item['permission'])) {
return false;
}
return $item;
}
}
但是显示此错误:
未找到“App \ Laratrust”类(查看:/var/www/html/multi-auth/vendor/jeroennoten/laravel-adminlte/resources/views/page.blade.php)
答案 0 :(得分:2)
最简单的方式
if (isset($item['permission']) && \Laratrust::can($item['permission'])) {
return false;
}
或者你可以
use Laratrust;
if (isset($item['permission']) && Laratrust::can($item['permission'])) {
return false;
}
use语句应该在类定义之前的顶部,并且条件显然在你的方法中
看来Laratrust是一个驻留在供应商目录中的软件包,这就是为什么试图将它放在\ app位置会抛出错误。
答案 1 :(得分:1)
您不要在命名空间中导入App\Laratrust
。将use App\Laratrust;
添加到您的课程顶部,它应该可以正常工作。