2015-10-14 28 views
4

請幫助即時在laravel創建一個登錄和註冊頁面時收到此錯誤5.1級「應用程序驗證」未找到laravel

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

這裏是我的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']), 
     ]); 
    } 
} 

和我註冊視圖

<!-- 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> 

所有代碼都來自laravel文檔。這就是爲什麼我不知道它爲什麼失敗。請檢查我的錯誤。謝謝

也這是我的路線控制器

// Authentication routes... 
Route::get('auth/login', 'Auth\[email protected]'); 
Route::post('auth/login', 'Auth\[email protected]'); 
Route::get('auth/logout', 'Auth\[email protected]'); 

// Registration routes... 
Route::get('auth/register', 'Auth\[email protected]'); 
Route::post('auth/register', 'Auth\[email protected]'); 

附:我的應用程序在 http://localhost:8080/QADapps/auth/register 的域下有什麼問題嗎? 我也動的index.php和的.htaccess從公衆到根目錄

+0

你有'Validator'或你'app'文件夾中的'User'類? –

+0

你好,確切位置在哪裏? – Nixxx27

+0

'app/Validator.php'。如果這個文件不存在,你可以試試下面的@delatbabel答案。 –

回答

5

實際上,你需要或者這樣:

use Validator; 

或本:

use Illuminate\Support\Facades\Validator; 

照亮\確認\驗證是基礎類包含功能,但使用您需要拉入門面類的靜態方法。

外觀類照亮的\ Support \外立面\驗證化名爲驗證在配置/ app.php

+0

嗨,當我使用都沒有發生,它只是重定向我註冊頁面。但沒有保存到db – Nixxx27

+0

你應該檢查你的User :: create()調用的結果,我看不到你的數據庫結構,但可能有一個數據庫錯誤那裏。 – delatbabel

+0

我試過User :: create()並將一個數據保存到我的數據庫中。 – Nixxx27

相關問題