我的AdminMiddleware代码是::
#include <iostream>
using namespace std;
char askQuestion(int questionNumber, char* question, char* optionA, char* optionB, char* optionC) {
char answer{};
cout << questionNumber << ".)" << question << "\n";
cout << optionA << "\n";
cout << optionB << "\n";
cout << optionC << "\n";
cin >> answer;
return answer;
}
int main()
{
char answer1;
char answer2;
char questionNumber;
questionNumber = 1;
answer1 = askQuestion(questionNumber, "Who is the Big Red Dog?", "A.)Milo", "B.)Clifford", "C.)Jack");
(answer1 == 'B') ? cout << "CORRECT!!!" : cout << "INCORRECT!!!";
cout << endl;
return 0;
}
当我想去::
<?php
namespace App\Http\Middleware;
use Closure;
use Sentinel;
class AdminMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if(Sentinel::check()&&Sentinel::getUser()->roles()->first()->slug =='admin')
return $next($request);
else
return redirect('/accessories');
}
}
它显示如下错误:
试图获取非对象的属性'slug'
答案 0 :(得分:0)
这可能是因为 Sentinel::getUser()->roles()
不是一个对象,意味着:用户没有任何角色
添加另一张支票
if(Sentinel::check() && isset(Sentinel::getUser()->roles) && Sentinel::getUser()->roles()->first()->slug =='admin'){
//Other code
}