Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class 'App\Validator' not found laravel

please help im getting this error when creating an login and registration page in laravel 5.1

FatalErrorException in AuthController.php line 44:
Class 'App\Validator' not found

here is my AuthController.php

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use App\Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'getLogout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }
}

and my register view

<!-- resources/views/auth/register.blade.php -->

<form method="POST" action="/QADapps/auth/register">
    {!! csrf_field() !!}

    <div>
        Name
        <input type="text" name="name" value="{{ old('name') }}">
    </div>

    <div>
        Email
        <input type="email" name="email" value="{{ old('email') }}">
    </div>

    <div>
        Password
        <input type="password" name="password">
    </div>

    <div>
        Confirm Password
        <input type="password" name="password_confirmation">
    </div>

    <div>
        <button type="submit">Register</button>
    </div>
</form>

all of the codes are from laravel documention. that's why i dont know why it fails. please check where i get the error. thank you

also this is my routes controller

// Authentication routes...
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

// Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');

P.S. my app is under the domain of http://localhost:8080/QADapps/auth/register is there any issue because of that? i also move index.php and .htaccess from public into the root directory

like image 765
Nixxx27 Avatar asked Oct 14 '15 03:10

Nixxx27


1 Answers

You actually need either this:

use Validator;

or this:

use Illuminate\Support\Facades\Validator;

Illuminate\Validation\Validator is the underlying class containing the functionality but to use the static methods you need to pull in the facade class.

The facade class Illuminate\Support\Facades\Validator is aliased to Validator in config/app.php

like image 69
delatbabel Avatar answered Sep 23 '22 02:09

delatbabel