0
votes

When I tried to log in, on my website. It responded with the message:

FatalErrorException in UserController.php line 37:
Class 'App\Http\Controllers\Auth' not found

But, the file there is controllers folder in Http containing Auth where there are four files.

UserController:

namespace App\Http\Controllers;
use Illuminate\Support\Facades\Input;
//use Illuminate\Support\Facades\Flash;
use InvalidConfirmationCodeException;
use Flash;
//use Mail;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class UserController extends Controller
{

public function getDashboard()


   {

         return view('dashboard');
   }


 public function postSignUp(Request $request)
 {

    $email = $request['email'];
    $name = $request['name'];
    $password = bcrypt($request['password']);

    $user = new User();
    $user -> email = $email;
    $user -> name = $name;
    $user -> password = $password;

    Auth::login('$user');

    $user->save();

    return redirect()->route('dashboard')


 }

 public function postSignIn(Request $request)
 {

    if (Auth::attempt(['email' => $request['email'], 'password' => $request['password']]))  {

        return redirect()->route('dashboard');
    }

           return redirect()->back();

 }
}

also, I am getting an error while signup:

MethodNotAllowedHttpException in RouteCollection.php line 218:

And I am trying to solve this error from a very long time but no success till now. Please help me with both the errors.

5

5 Answers

0
votes

change Auth::login($user) --> \Auth::login($user)
and let me know if you are getting anything in database after signup . :)

0
votes

To get rid off

FatalErrorException in UserController.php line 37: Class 'App\Http\Controllers\Auth' not found

Add use Auth at the top

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\User;
use Auth;
0
votes
  1. Change Auth::login($User) to \Auth::login($user), your $user variable is incorrect as well.

  2. Check your signup route, is it doing a POST (most likely it is) and you're sending a GET request?

0
votes

You need add

use Auth;

to your Controller.

0
votes

I highly doubt that the Auth class is inside your Controllers directory. The Auth you are looking for, is probably the Auth facade, can be included this way:

use Illuminate\Support\Facades\Auth;