i erstellen Sie eine neue Tabelle mit dem Namen der SchülerFehler in der benutzerdefinierten Authentifizierung in Laravel 5.2
public function up()
{
Schema::create('students', function (Blueprint $table) {
// $table->increments('id');
$table->engine = 'InnoDB';
$table->string('roll_no');
$table->string('name');
$table->string('father_name');
$table->string('address');
$table->string('cnic');
$table->string('phone_no');
$table->string('father_phone_no');
$table->string('email')->unique();
$table->string('password');
// $table->string('dept_id');
$table->timestamps();
$table->primary('roll_no');
// $table->foreign('dept_id')->references('dept_id')->on('departments')->onDelete('cascade');
});
}
dann ich ein Studentenmodell erstellen, das
class student extends Authenticatable
{
//
}
dann Änderungen in meinem Auth i leer
ist. pHP-Datei<?php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'student' => [
'driver' => 'session',
'provider' => 'students',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'student' => [
'driver' => 'eloquent',
'model' => App\student::class,
],
],
'passwords' => [
'users' => [
'provider' => 'users',
'email' => 'auth.emails.password',
'table' => 'password_resets',
'expire' => 60,
],
'students' => [
'provider' => 'students',
'email' => 'student.auth.emails.password',
'table' => 'password_resets',
'expire' => 60,
],
],
];
dann füge ich ein Middleware-RedirectifNotStudent
public function handle($request, Closure $next, $guard = 'student')
{
if (!Auth::guard($guard)->check()) {
return redirect('/student/login');
}
return $next($request);
}
dann füge ich diese Zeile Datei kernel.php
'student' => \App\Http\Middleware\RedirectIfNotstudent::class,
nach, dass ich ein Login, Logout, Registrierungsfunktion in diesem Verzeichnis StudentAuth hinzufügen/AuthController
protected $redirectTo = '/student';
protected $guard = 'student';
public function showLoginForm()
{
if (Auth::guard('student')->check())
{
return redirect('/student');
}
return view('student.auth.login');
}
public function showRegistrationForm()
{
return view('student.auth.register');
}
public function resetPassword()
{
return view('student.auth.passwords.email');
}
public function logout(){
Auth::guard('student')->logout();
return redirect('/student/login');
}
Danach habe ich Mitarbeiter-Controller in Student/Mitarbeiter wie folgt hinzufügen
class Employee extends Controller
{
public function __construct(){
$this->middleware('student');
}
public function index(){
return view('Student.home');
}
}
dies meine Route Datei
Route::get('/student/login','StudentAuth\[email protected]');
Route::post('/student/login','StudentAuth\[email protected]');
Route::get('/student/password/reset','StudentAuth\[email protected]');
Route::group(['middleware' => ['student']], function() {
//Login Routes...
Route::get('/student/logout','StudentAuth\[email protected]');
// Registration Routes...
Route::get('student/register', 'StudentAuth\[email protected]');
Route::post('student/register', 'StudentAuth\[email protected]');
Route::get('/student', 'Student\[email protected]');
});
Route::group(['middleware' => 'web'], function() {
// Route::auth();
Route::get('/home', '[email protected]');
builtin Authentifizierung funktioniert gut, aber ich möchte ein anderes für Schüler und dieser Fehler auftreten
Authentication user provider [] is not defined.
Sie sicher, dass dies der Fehler ist ?? –