Laravel 5 视图中的Auth::check()始终返回false
我试图只向登录用户显示部分内容。内容永远不会显示。下面是一段代码:Laravel 5 视图中的Auth::check()始终返回false,laravel-5,Laravel 5,我试图只向登录用户显示部分内容。内容永远不会显示。下面是一段代码: @if(Auth::check()) <a href="{{ route('backend.blog.edit', $id) }}"> Edit </a> @endif 我找到了解决办法 public function map(Router $router) { $this->mapApiRoutes(); $this->
@if(Auth::check())
<a href="{{ route('backend.blog.edit', $id) }}">
Edit
</a>
@endif
我找到了解决办法
public function map(Router $router)
{
$this->mapApiRoutes();
$this->mapWebRoutes();
Route::group(['middleware' => 'web'], function ($router) {
if (! app()->runningInConsole()) {
foreach (ProductCategory::all() as $category) {
$router->get($category->uri, ['as' => $category->name, function () use ($category, $router) {
return $this->app->call(
'App\Http\Controllers\PageController@show', [
'category' => $category,
'parameters' => $router->current()->parameters()
]);
}]);
}
}
});
}
我找到了解决办法
public function map(Router $router)
{
$this->mapApiRoutes();
$this->mapWebRoutes();
Route::group(['middleware' => 'web'], function ($router) {
if (! app()->runningInConsole()) {
foreach (ProductCategory::all() as $category) {
$router->get($category->uri, ['as' => $category->name, function () use ($category, $router) {
return $this->app->call(
'App\Http\Controllers\PageController@show', [
'category' => $category,
'parameters' => $router->current()->parameters()
]);
}]);
}
}
});
}
您是否尝试了auth()->check()而不是auth::check()?您确定此控制器通过
auth
中间件吗?@MinaAbadir否。您可能是因为我的问题。我如何做到这一点,并且仍然允许客人?@RogerCreasy你是对的,我的意思是中间件web
谢谢。我尝试在我的RouteServiceProvider
中添加web中间件。它仍然不起作用..您是否尝试了auth()->check()而不是auth::check()?您确定此控制器通过auth
中间件吗?@MinaAbadir否。您可能对我的问题有所了解。我如何做到这一点,并且仍然允许客人?@RogerCreasy你是对的,我的意思是中间件web
谢谢。我尝试在我的RouteServiceProvider
中添加web中间件。它仍然不起作用。再解释一下解决方案,这样OP就可以从中学习,而不仅仅是复制粘贴。再解释一下解决方案,这样OP就可以从中学习,而不仅仅是复制粘贴。