-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Description
BaseController.php
class BaseAgentController extends Controller
{
/**
* @var $user Collection
*/
protected $user;
public function __construct()
{
//执行中间件获取用户信息
$this->middleware(function ($request, $next) {
$this->user = collect(Auth::user())->except(['permissions', 'roles']);
return $next($request);
});
}
}
IndexController.php
class IndexController extends BaseAgentController
{
public function index(Request $request)
{
$user = $this->user;//这个地方有时能够获取到数据,有的时候不能获取到数据,获取到的是NULL
return view('admin.index.index', compact('user'));
}
}
如上在父类的CONTROLLER中的构造函数使用中间件方法给对象属性设置值,在子类的CONTROLLER中有的时候获取不到设置的属性值
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels