2017-04-26 3 views
2

Hallo ich bin neu zu Laravel ich bin ein Tutorial folgen, um Admin-Seite zu machen, wenn ich Admin Auth Wache verwendet, aber wenn ich versuchte, Admin-Seite "www.school.dev/admin" i sah diesen Fehler
enter image description hereAuth guard [admin] ist nicht definiert

Das ist mein config/Auth.php

<?php 

return [ 

/* 
|-------------------------------------------------------------------------- 
| Authentication Defaults 
|-------------------------------------------------------------------------- 
| 
| This option controls the default authentication "guard" and password 
| reset options for your application. You may change these defaults 
| as required, but they're a perfect start for most applications. 
| 
*/ 

'defaults' => [ 
    'guard' => 'web', 
    'passwords' => 'users', 
], 

/* 
|-------------------------------------------------------------------------- 
| Authentication Guards 
|-------------------------------------------------------------------------- 
| 
| Next, you may define every authentication guard for your application. 
| Of course, a great default configuration has been defined for you 
| here which uses session storage and the Eloquent user provider. 
| 
| All authentication drivers have a user provider. This defines how the 
| users are actually retrieved out of your database or other storage 
| mechanisms used by this application to persist your user's data. 
| 
| Supported: "session", "token" 
| 
*/ 

'guards' => [ 
    'web' => [ 
     'driver' => 'session', 
     'provider' => 'users', 
    ], 

    'api' => [ 
     'driver' => 'token', 
     'provider' => 'users', 
    ], 

    'admin' => [ 
     'driver' => 'session', 
     'provider' => 'admins', 
    ], 
], 

/* 
|-------------------------------------------------------------------------- 
| User Providers 
|-------------------------------------------------------------------------- 
| 
| All authentication drivers have a user provider. This defines how the 
| users are actually retrieved out of your database or other storage 
| mechanisms used by this application to persist your user's data. 
| 
| If you have multiple user tables or models you may configure multiple 
| sources which represent each model/table. These sources may then 
| be assigned to any extra authentication guards you have defined. 
| 
| Supported: "database", "eloquent" 
| 
*/ 

'providers' => [ 
    'users' => [ 
     'driver' => 'eloquent', 
     'model' => App\User::class, 
    ], 
    'admins' => [ 
     'driver' => 'eloquent', 
     'model' => App\Admin::class, 
    ], 
    // 'users' => [ 
    //  'driver' => 'database', 
    //  'table' => 'users', 
    // ], 
], 

/* 
|-------------------------------------------------------------------------- 
| Resetting Passwords 
|-------------------------------------------------------------------------- 
| 
| You may specify multiple password reset configurations if you have more 
| than one user table or model in the application and you want to have 
| separate password reset settings based on the specific user types. 
| 
| The expire time is the number of minutes that the reset token should be 
| considered valid. This security feature keeps tokens short-lived so 
| they have less time to be guessed. You may change this as needed. 
| 
*/ 

'passwords' => [ 
    'users' => [ 
     'provider' => 'users', 
     'table' => 'password_resets', 
     'expire' => 60, 
    ], 
    'admins' => [ 
     'provider' => 'admins', 
     'table' => 'password_resets', 
     'expire' => 60, 
    ], 
    ], 

]; 

Admin Modell

<?php 

namespace App; 

use Illuminate\Notifications\Notifiable; 
use Illuminate\Foundation\Auth\User as Authenticatable; 

class Admin extends Authenticatable 
{ 
    use Notifiable; 

    protected $guard = 'admin'; 

    /** 
    * The attributes that are mass assignable. 
    * 
    * @var array 
    */ 
    protected $fillable = [ 
     'name', 'email', 'password', 'job_title', 
    ]; 

    /** 
    * The attributes that should be hidden for arrays. 
    * 
    * @var array 
    */ 
    protected $hidden = [ 
     'password', 'remember_token', 
    ]; 
} 

Admin-Controller

<?php 

namespace App\Http\Controllers\Backend; 

use Illuminate\Http\Request; 
use App\Http\Controllers\Controller; 

class AdminController extends Controller 
{ 
    public function __construct() { 
     $this->middleware('auth:admin'); 
    } 

    /** 
    * Display a listing of the resource. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function index() 
    { 
     return view('backend.dashboard'); 
    } 

    /** 
    * Show the form for creating a new resource. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function create() 
    { 
     // 
    } 

    /** 
    * Store a newly created resource in storage. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return \Illuminate\Http\Response 
    */ 
    public function store(Request $request) 
    { 
     // 
    } 

    /** 
    * Display the specified resource. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function show($id) 
    { 
     // 
    } 

    /** 
    * Show the form for editing the specified resource. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function edit($id) 
    { 
     // 
    } 

    /** 
    * Update the specified resource in storage. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function update(Request $request, $id) 
    { 
     // 
    } 

    /** 
    * Remove the specified resource from storage. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function destroy($id) 
    { 
     // 
    } 
} 

Routen/web.php

<?php 

/* 
|-------------------------------------------------------------------------- 
| Web Routes 
|-------------------------------------------------------------------------- 
| 
| Here is where you can register web routes for your application. These 
| routes are loaded by the RouteServiceProvider within a group which 
| contains the "web" middleware group. Now create something great! 
| 
*/ 

Route::get('/', 'Frontend\[email protected]'); 

/* 
|-------------------------------------------------------------------------- 
| Admin Routes 
|-------------------------------------------------------------------------- 
*/ 
Auth::routes(); 

Route::get('admin', 'Backend\[email protected]'); 



Route::get('/home', '[email protected]'); 

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. 
    * 
    * These middleware are run during every request to your application. 
    * 
    * @var array 
    */ 
    protected $middleware = [ 
     \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, 
     \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, 
     \App\Http\Middleware\TrimStrings::class, 
     \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, 
    ]; 

    /** 
    * The application's route middleware groups. 
    * 
    * @var array 
    */ 
    protected $middlewareGroups = [ 
     'web' => [ 
      \App\Http\Middleware\EncryptCookies::class, 
      \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 
      \Illuminate\Session\Middleware\StartSession::class, 
      // \Illuminate\Session\Middleware\AuthenticateSession::class, 
      \Illuminate\View\Middleware\ShareErrorsFromSession::class, 
      \App\Http\Middleware\VerifyCsrfToken::class, 
      \Illuminate\Routing\Middleware\SubstituteBindings::class, 
     ], 

     'api' => [ 
      'throttle:60,1', 
      'bindings', 
     ], 
    ]; 

    /** 
    * The application's route middleware. 
    * 
    * These middleware may be assigned to groups or used individually. 
    * 
    * @var array 
    */ 
    protected $routeMiddleware = [ 
     'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 
     'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 
     'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 
     'can' => \Illuminate\Auth\Middleware\Authorize::class, 
     'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 
     'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 
    ]; 
} 
+0

Bitte führen Sie 'Composer dump-autoload' aus, vielleicht löst es Ihr Problem – Buglinjo

+0

Sie haben versehentlich das Admin-Modell unter der Admin-Controller-Überschrift eingefügt –

+0

Könnte sein, dass der Guard-Name in Ihrem Admin-Modell falsch ist. Geschützt $ guard = 'admin' ;? Probieren Sie "Admins"? –

Antwort

5

Klar die Config-ca che php artisan config:clear oder es php artisan config:cache umbauen.

+1

Das hat mein Problem tatsächlich behoben danke: D aber nicht verstehen, wie könnte das passieren Ich meine, es ist wie Caching-System ON, auch wenn ich einen alten Fehler hatte, wird es still bleiben, bis ich den Cache entferne und kann ich dies ausschalten auf diesen Befehl immer wieder verwenden? –

Verwandte Themen