Исключение при использовании промежуточного ПО Entrust в Laravel 5.1

Я установил вверять пакет в моем приложении Laravel 5.1, добавив его в мой файл composer.json и запустив обновление композитора и следуя всем инструкциям к письму. Я пытаюсь использовать их промежуточное ПО для защиты некоторых маршрутов, но получаю следующее исключение:

ReflectionException in Container.php line 741:
Class App\Http\Zizaco\Entrust\Middleware\EntrustPermission does not exist

Вот содержимое моего файла composer.json:

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"LaravelCollective/html": "5.1",
"zizaco/entrust": "dev-laravel-5",
"yajra/laravel-datatables-oracle": "~5.0",
"davejamesmiller/laravel-breadcrumbs": "~3.0",
"intervention/image": "dev-master",
"doctrine/dbal": "2.5.1",
"thujohn/twitter": "~2.0",
"fzaninotto/faker": "^1.5",
"cviebrock/image-validator": "2.0.*@beta"},
"require-dev": {
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"},
"autoload": {
"classmap": [
"database",
"app/Http/Helpers"],
"psr-4": {
"App\\": "app/"}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"],
"pre-update-cmd": [
"php artisan clear-compiled"],
"post-update-cmd": [
"php artisan optimize"],
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""],
"post-create-project-cmd": [
"php artisan key:generate"]
},
"config": {
"preferred-install": "dist"}
}

Вот соответствующее содержимое моего файла config / app.php:

'providers' => [

/*
* Laravel Framework Service Providers...
*/
Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
Illuminate\Auth\AuthServiceProvider::class,
Illuminate\Broadcasting\BroadcastServiceProvider::class,
Illuminate\Bus\BusServiceProvider::class,
Illuminate\Cache\CacheServiceProvider::class,
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
Illuminate\Routing\ControllerServiceProvider::class,
Illuminate\Cookie\CookieServiceProvider::class,
Illuminate\Database\DatabaseServiceProvider::class,
Illuminate\Encryption\EncryptionServiceProvider::class,
Illuminate\Filesystem\FilesystemServiceProvider::class,
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
Illuminate\Hashing\HashServiceProvider::class,
Illuminate\Mail\MailServiceProvider::class,
Illuminate\Pagination\PaginationServiceProvider::class,
Illuminate\Pipeline\PipelineServiceProvider::class,
Illuminate\Queue\QueueServiceProvider::class,
Illuminate\Redis\RedisServiceProvider::class,
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
Illuminate\Session\SessionServiceProvider::class,
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,

/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Collective\Html\HtmlServiceProvider::class,

'yajra\Datatables\DatatablesServiceProvider', // data grid
'DaveJamesMiller\Breadcrumbs\ServiceProvider',
'Zizaco\Entrust\EntrustServiceProvider',
'Intervention\Image\ImageServiceProvider',
'Thujohn\Twitter\TwitterServiceProvider',
'Cviebrock\ImageValidator\ImageValidatorServiceProvider'
],

/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| This array of class aliases will be registered when this application
| is started. However, feel free to register as many as you wish as
| the aliases are "lazy" loaded so they don't hinder performance.
|
*/

'aliases' => [

'App'       => Illuminate\Support\Facades\App::class,
'Artisan'   => Illuminate\Support\Facades\Artisan::class,
'Auth'      => Illuminate\Support\Facades\Auth::class,
'Blade'     => Illuminate\Support\Facades\Blade::class,
'Bus'       => Illuminate\Support\Facades\Bus::class,
'Cache'     => Illuminate\Support\Facades\Cache::class,
'Config'    => Illuminate\Support\Facades\Config::class,
'Cookie'    => Illuminate\Support\Facades\Cookie::class,
'Crypt'     => Illuminate\Support\Facades\Crypt::class,
'DB'        => Illuminate\Support\Facades\DB::class,
'Eloquent'  => Illuminate\Database\Eloquent\Model::class,
'Event'     => Illuminate\Support\Facades\Event::class,
'File'      => Illuminate\Support\Facades\File::class,
'Hash'      => Illuminate\Support\Facades\Hash::class,
'Input'     => Illuminate\Support\Facades\Input::class,
'Inspiring' => Illuminate\Foundation\Inspiring::class,
'Lang'      => Illuminate\Support\Facades\Lang::class,
'Log'       => Illuminate\Support\Facades\Log::class,
'Mail'      => Illuminate\Support\Facades\Mail::class,
'Password'  => Illuminate\Support\Facades\Password::class,
'Queue'     => Illuminate\Support\Facades\Queue::class,
'Redirect'  => Illuminate\Support\Facades\Redirect::class,
'Redis'     => Illuminate\Support\Facades\Redis::class,
'Request'   => Illuminate\Support\Facades\Request::class,
'Response'  => Illuminate\Support\Facades\Response::class,
'Route'     => Illuminate\Support\Facades\Route::class,
'Schema'    => Illuminate\Support\Facades\Schema::class,
'Session'   => Illuminate\Support\Facades\Session::class,
'Storage'   => Illuminate\Support\Facades\Storage::class,
'URL'       => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View'      => Illuminate\Support\Facades\View::class,

'Breadcrumbs'   => 'DaveJamesMiller\Breadcrumbs\Facade',
'Datatables' => yajra\Datatables\Datatables::class,
Zizaco\Entrust\EntrustServiceProvider::class,
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
'Image_helper' => 'App\Http\Helpers\Image_helper',
'Twitter' => 'Thujohn\Twitter\Facades\Twitter',
]

Вот содержимое моего файла App \ Http \ Kernel.php:

<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* @var array
*/
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
];

/**
* The application's route middleware.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'clientIpCheck' => 'App\Http\Middleware\ClientIpCheck',
'role' => Zizaco\Entrust\Middleware\EntrustRole::class,
'permission' => Zizaco\Entrust\Middleware\EntrustPermission::class,
'ability' => Zizaco\Entrust\Middleware\EntrustAbility::class,
];
}

И вот как я пытаюсь использовать промежуточное ПО в моем файле rout.php:

// secure admin routes
Route::group(['middleware' => 'permission:access_admin_area'], function()
{
Route::get('admin', ['as' => 'dashboard', 'uses' => 'Admin\AdminController@index']);
});

Я почти уверен, что следовал их инструкциям к письму, все это работало, пока я не попытался использовать их промежуточное программное обеспечение маршрута. Кто-нибудь знает, где я ошибся?

3

Решение

Оказывается, код в инструкции по установке неверен. Определения промежуточного программного обеспечения маршрута должны иметь обратную косую черту на передней панели.

Разбитый пример:

/**
* The application's route middleware.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'clientIpCheck' => 'App\Http\Middleware\ClientIpCheck',
'role' => Zizaco\Entrust\Middleware\EntrustRole::class,
'permission' => Zizaco\Entrust\Middleware\EntrustPermission::class,
'ability' => Zizaco\Entrust\Middleware\EntrustAbility::class,
];

Исправленный пример:

/**
* The application's route middleware.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'clientIpCheck' => 'App\Http\Middleware\ClientIpCheck',
'role' => \Zizaco\Entrust\Middleware\EntrustRole::class,
'permission' => \Zizaco\Entrust\Middleware\EntrustPermission::class,
'ability' => \Zizaco\Entrust\Middleware\EntrustAbility::class,
];

Благодаря XAOC за головы!

8

Другие решения

Проверь это Не удалось подключить промежуточное ПО ENTRUST

Или попробуйте создать свой MiddleWares Manully

1- Перейти к Zizaco\Entrust\Middleware в vendor каталог

2- Скопировать все MiddleWares от Middleware каталог

3- Вставить все в App\Http\Middleware и изменить путь в $routeMiddleware[] в ваше приложение middleware dir

Примечание: не забудьте изменить пространство имен после копирования

0

По вопросам рекламы [email protected]