0

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 Answer 1

0

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
{
....
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, I solve this problem with your answer. "use App\Http\Controllers\Auth;" need to be deleted. I will view your course :)
Ohh sure! I'm going to edit my answer to reflect that. Best wishes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.