Laravel 5 Class admin不存在

时间:2015-03-31 08:16:38

标签: php laravel

Laravel 5和这个管理类有问题,问题是所有东西都在localhost上运行,现在我在服务器上部署了它(做了很多修复但没有触及它)它不起作用

当我进入页面' / 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');
});

2 个答案:

答案 0 :(得分:15)

固定!

忘记同步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',
    ];

答案 1 :(得分:1)

其他信息

app / Htpp / Kernel.php不是console / Kernel.php