dpxpz37157 2016-01-22 03:15
浏览 465
已采纳

laravel5.2 Auth :: guest()返回错误“Class'App \ Http \ Controllers \ Auth'not found”

I am trying to use the inbuilt Auth for login in laravel and register. These automatically generated pages work so well, now I use Auth::guest() to check if the user is authorized to return a view: index else to login page.

But it shows:

Class 'App\Http\Controllers\Auth' not found".

Here's the code:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;

class StepsController extends Controller
{
    public function step1()
    {
        if (Auth::guest())
        {
            return redirect('login');
        }else {
            return view('index');
        }
    }
}
  • 写回答

1条回答 默认 最新

  • dt888999 2016-01-22 03:31
    关注

    You need to "import" the definition of the facade of Auth and remove the use App\Http\Controllers\Auth because does not exists.

    Just add at the top (just before the class declaration):

    use Auth;
    

    And remove the other:

    Having this:

    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    use App\Http\Requests;
    use App\Http\Controllers\Controller;
    use Auth;
    
    class StepsController extends Controller
    {
    ....
    

    Hope it helps.

    PS: If you want to learn Laravel with a good guide, step-by-step, please check here: Learn Laravel

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug