Ich möchte Grund beglaubigen wenn User Admin ist dann nächste Anfrage sonstAnruf auf eine Elementfunktion isAdmin() auf null in Laravel
User.php
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password','role_id','is_active','photo_id',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function role(){
return $this->belongsTo('App\Role');
}
public function photo(){
return $this->belongsTo('App\Photo');
}
public function isAdmin(){
if ($this->role()->name=="administrator"){
return true;
}
return false;
}
}
zur Startseite umleiten
letzte Funktion ist isAdmin()
admin.php (dies ist Middleware)
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class Admin
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Auth::check()){
if (Auth::user()->isAdmin()){
return $next($request);
}
}
return redirect('/');
}
}
routes.php
<?php
Route::get('/', function() {
return view('welcome');
});
Route::get('/admin',function(){
return view('admin.index');
});
Route::group(['middleware'=>'admin'],function(){
Route::resource('/admin/users','AdminUsersController');
});
Route::auth();
Route::get('/home', '[email protected]');
** es zeigt mir Fehler! **
FatalErrorException admin.php in Leitung 21: Aufruf an eine Elementfunktion isAdmin() auf null
i auch 'admin' =>\App\Http\Middleware\Admin::class,
in kernel.php hinzugefügt und importiert die Klasse in admin.php
PLZ ME , ICH STECKE FEST!!!!!!!!
@HilmiErdemKEREN was soll ich –
@HilmiErdemKEREN 'null' tun, warum seine null.iam angemeldet, dann auch' null' –
@HilmiErdemKEREN u würde mir helfen plz :) –