App\Http\Controllers\Auth not found.

Published 2 years ago by gman01

Hi,

I'm trying to get all rows where user = logged in user, but keep getting:

Class 'App\Http\Controllers\Auth' not found, I've tried adding it in to the top of the controller.

<?php

use Illuminate\Support\Str;

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

use App\Client;

use App\Note;

use App\Product;

use App\Http\Requests\ClientRequest;

use App\Http\Requests;

use Carbon\Carbon;

class MyClientsController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    public function index() {
      
         $clients = Client::where('id', Auth::user()->id)->get();

         return view('my_clients.index', compact('clients'));
    }
}

onmyown

Where have you added it? I don't see it...

nate.a.johnson

You need to add a use statement at the top or use the helper function auth() in place of the facade.

InaniELHoussain

use Illuminate\Support\Facades\Auth;

gman01

I had tried adding it at the top but I still get the same error.

gman01

OK I got it.

InaniELHoussain

@gman01 solved?

caagsoftware

Probably the issue is in the Kernel.php in http folder

gman01

Yes I was calling something else as well that was conflicting with it.

InaniELHoussain

actually you've not been importing the Auth facade, so he tried to look for an Auth class that existing in the current directory. Good to know that is solved

Please sign in or create an account to participate in this conversation.