2016-02-29 219 views
0

我想進行身份驗證用戶登錄並註冊laravel。但是當我提交保存註冊信息..這是顯示php - Laravel 5.2身份驗證不工作

找不到對象!

在此服務器上找不到請求的URL。 引用頁面上的鏈接似乎是錯誤或過時的。請通知該頁面的作者 關於錯誤。 如果您認爲這是服務器錯誤,請與網站管理員聯繫。

這裏是我的authController:

<?php 

namespace App\Http\Controllers\Auth; 

use App\User; 
use 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; 

    /** 
    * Where to redirect users after login/registration. 
    * 
    * @var string 
    */ 


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

    /** 
    * 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', 
     ]); 
    } 


    protected function create(array $data) 
    { 
     return User::create([ 
      'name' => $data['name'], 
      'email' => $data['email'], 
      'password' => bcrypt($data['password']), 
     ]); 
    } 

    protected function getLogin() { 
     return View('auth.login'); 
    } 

    protected function postLogin(LoginRequest $request) { 
     if ($this->auth->attempt($request->only('email', 'password'))) { 
       return redirect()->route('/'); 
      // return view('course.index'); 
     } 

     return redirect('auth/login')->withErrors([ 
      'email' => 'The email or the password is invalid. Please try again.', 
     ]); 
    } 

    /* Register get post methods */ 
    protected function getRegister() { 
     return View('auth.register'); 
    } 

    protected function postRegister(RegisterRequest $request) { 
     $this->user->name = $request->name; 
     $this->user->email = $request->email; 
     $this->user->password = bcrypt($request->password); 
     $this->user->save(); 
     return redirect('auth.login'); 
    } 


    protected function getLogout() 
    { 
     $this->auth->logout(); 
     return redirect('auth.login'); 
    } 
    protected $redirectTo = '/course'; 
    protected $loginPath = '/auth/login'; 

} 

這裏是我的login.blade.php文件:

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

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

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

     <div> 
      <input type="checkbox" name="remember"> Remember Me 
     </div> 

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

Here is my register.blade.php file 

<form method="POST" action="/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> 

這裏是routes.php文件

<?php 

/* 
|-------------------------------------------------------------------------- 
| Routes File 
|-------------------------------------------------------------------------- 
| 
| Here is where you will register all of the routes in an application. 
| It's a breeze. Simply tell Laravel the URIs it should respond to 
| and give it the controller to call when that URI is requested. 
| 
*/ 

Route::get('/', function() { 
    return view('welcome'); 
}); 

Route::get('/all_user',function(){ 
    return view('all_user'); 
}); 

Route::get('all_user/{id}/{name}',function($id,$name){  // Here we pass the peremeter in url all_user 
    return 'User '.$id." ".$name;       // with the parameter id and name 
}); 

Route::get('home','[email protected]'); // Here Home is the URL and it 
              //execute the basiccontroller index page 
Route::get('about','[email protected]'); 

Route::resource('course','courseController'); 

/* 
|-------------------------------------------------------------------------- 
| Application Routes 
|-------------------------------------------------------------------------- 
| 
| This route group applies the "web" middleware group to every route 
| it contains. The "web" middleware group is defined in your HTTP 
| kernel and includes session state, CSRF protection, and more. 
| 
*/ 


Route::group(['middleware' => ['web']], function() { 
    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]'); 
}); 
+0

,當你收到此錯誤?點擊登錄後或註冊按鈕 – Qazi

+0

是的。當我點擊登錄和註冊按鈕來保存時,我看到以下錯誤。 – Hola

回答

0

在你看來

對於登錄:

{{ !! Form::open(array('route'=>route('auth.login'))) !!}} 

對於註冊:

{{ !! Form::open(array('route'=>route('auth.register'))) !! }} 

在你的路由

對於登錄

Route::post('auth/login', array('as'=>'auth.login','uses'=>'Auth\[email protected]')); 

對於註冊

Route::post('auth/register', array('as'=>'auth.register','uses'=>'Auth\[email protected]')); 

而且不要忘記關閉您的形式:

{{ !! Form::close() !! }}