gpt4 book ai didi

php - Laravel 5 类管理员不存在

转载 作者:可可西里 更新时间:2023-10-31 23:07:20 26 4
gpt4 key购买 nike

Laravel 5 和这个管理类有问题,问题是一切都在本地主机上工作,现在在我将它部署在服务器上之后(做了很多修复但没有触及这个)它不起作用。

当我转到“/moderate”页面时出现错误,该页面应该只有管理员才能看到。

错误:

in Container.php line 776
at ReflectionClass->__construct('admin') in Container.php line 776
at Container->build('admin', array()) in Container.php line 656
at Container->make('admin', array()) in Application.php line 572
at Application->make('admin') in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Authenticate.php line 47
at Authenticate->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Router.php line 690
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 660
at Router->dispatchToRoute(object(Request)) in Router.php line 618
at Router->dispatch(object(Request)) in Kernel.php line 157
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 108
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 83
at Kernel->handle(object(Request)) in index.php line 53

AdminController 位置(App/Http/Controllers/):

<?php namespace App\Http\Controllers;

use App\Post;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class AdminController extends Controller {

/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$posts = Post::oldest()->where('status', '=', '0')->get();
return view('admin.index', compact('posts'));
}

/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function trash()
{
$posts = Post::oldest()->where('status', '=', '2')->get();
return view('admin.trash', compact('posts'));
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function changeStatus($id, $status)
{
$post = Post::findOrFail($id);

if($post->status != $status){
$post->status = $status;
$post->save();
}

return redirect('/moderate');
}


}

路线:

// Admin only

Route::group(['middleware' => ['auth', 'admin']], function()
{
Route::get('/moderate', 'AdminController@index');
Route::get('/posts/{id}/status/{status}', 'AdminController@changeStatus');
Route::get('/trash', 'AdminController@trash');
});

最佳答案

已修复!

忘记同步 Kernel.php

    protected $routeMiddleware = [
'auth' => 'App\Http\Middleware\Authenticate',
'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
'guest' => 'App\Http\Middleware\RedirectIfAuthenticated',
// This was missing
'admin' => 'App\Http\Middleware\VerifyAdmin',
];

关于php - Laravel 5 类管理员不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29363811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com