Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 Class admin does not exist

Tags:

php

laravel

Having problem with Laravel 5 and this admin class, the thing is that everything worked on localhost and now after I deployed it on server (made ton of fixes but didn't touched this) it doesn't work.

The Error is coming out when I go to the page '/moderate' which should be visible just by the admin.

Error:

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 location(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');
    }


}

Routes:

// 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');
});
like image 230
Djordje Vanjek Avatar asked Mar 31 '15 08:03

Djordje Vanjek


2 Answers

Fixed!

Forgot to sync 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',
    ];
like image 80
Djordje Vanjek Avatar answered Nov 14 '22 19:11

Djordje Vanjek


Additional info

app/Htpp/Kernel.php not console/Kernel.php

like image 20
umutyerebakmaz Avatar answered Nov 14 '22 18:11

umutyerebakmaz