2016-04-25 23 views
0

laravel 5で私はPasswordControllerとResetsPasswordsを試みるが、常に私はルートproblemeを持ってlaravel 5 PasswordControllerルート

Route.php

Route::controllers(['uses' => 'Auth/PasswordController']); 

Route::get('home/ResetsPasswords',array('as'=>'getEmail' ,'uses' => 'home/[email protected]')); 

Route::post('home/ResetsPasswords',array('as'=>'postEmail' ,'uses' => 'home/[email protected]')); 

Route::get('home/ResetsPasswords/{token}',array('as' => 'getReset','uses' => 'home/[email protected]')); 

Route::post('home/ResetsPasswords/{token}', array( 'as' => 'postReset','uses' => 'home/[email protected]')); 

Route::get('home/ResetsPasswords',array('as'=>'getEmailSubject' ,'uses' => 'home/[email protected]')); 

Route::get('home/ResetsPasswords',array('as'=>'redirectPath' ,'uses' => 'home/[email protected]')); 

PasswordController.php

<?php 

namespace App\Http\Controllers\Auth; 

use App\Http\Controllers\Controller; 
use Illuminate\Foundation\Auth\ResetsPasswords; 
class PasswordController extends Controller 
{ 


    use ResetsPasswords; 


    public function __construct() 
    { 
     $this->middleware('guest'); 
    } 
} 

ResetsPasswords.php

<?php 

namespace App\Http\Controllers\Auth; 

use App\Http\Controllers\Controller; 
use Illuminate\Foundation\Auth\ResetsPasswords; 

class PasswordController extends Controller 
{ 
    /* 
    |-------------------------------------------------------------------------- 
    | Password Reset Controller 
    |-------------------------------------------------------------------------- 
    | 
    | This controller is responsible for handling password reset requests 
    | and uses a simple trait to include this behavior. You're free to 
    | explore this trait and override any methods you wish to tweak. 
    | 
    */ 

    use ResetsPasswords; 

    /** 
    * Create a new password controller instance. 
    * 
    * @return void 
    */ 
    public function __construct() 
    { 
     $this->middleware('guest'); 
    } 
} 

<?php 

namespace App\Http\Controllers\Auth; 

use App\Http\Controllers\Controller; 
use Illuminate\Foundation\Auth\ResetsPasswords; 

class PasswordController extends Controller 
{ 
    /* 
    |-------------------------------------------------------------------------- 
    | Password Reset Controller 
    |-------------------------------------------------------------------------- 
    | 
    | This controller is responsible for handling password reset requests 
    | and uses a simple trait to include this behavior. You're free to 
    | explore this trait and override any methods you wish to tweak. 
    | 
    */ 

    use ResetsPasswords; 

    /** 
    * Create a new password controller instance. 
    * 
    * @return void 
    */ 
    public function __construct() 
    { 
     $this->middleware('guest'); 
    } 
} 


ResetsPasswords.php 

     <?php 

    //namespace Illuminate\Foundation\Auth; 

    use Illuminate\Http\Request; 
    use Illuminate\Mail\Message; 
    use Illuminate\Support\Facades\Auth; 
    use Illuminate\Support\Facades\Password; 
    use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; 

    trait ResetsPasswords 
    { 
     /** 
     * Display the form to request a password reset link. 
     * 
     * @return \Illuminate\Http\Response 
     */ 
     public function getEmail() 
     { 
      return view('auth.password'); 
     } 

     /** 
     * Send a reset link to the given user. 
     * 
     * @param \Illuminate\Http\Request $request 
     * @return \Illuminate\Http\Response 
     */ 
     public function postEmail(Request $request) 
     { 
      $this->validate($request, ['email' => 'required|email']); 

      $response = Password::sendResetLink($request->only('email'), function (Message $message) { 
       $message->subject($this->getEmailSubject()); 

      }); 

      switch ($response) { 
       case Password::RESET_LINK_SENT: 
        return redirect()->back()->with('status', trans($response)); 

       case Password::INVALID_USER: 
        return redirect()->back()->withErrors(['email' => trans($response)]); 
      } 
     } 

     /** 
     * Get the e-mail subject line to be used for the reset link email. 
     * 
     * @return string 
     */ 
     protected function getEmailSubject() 
     { 
      return isset($this->subject) ? $this->subject : 'Your Password Reset Link'; 
     } 

     /** 
     * Display the password reset view for the given token. 
     * 
     * @param string $token 
     * @return \Illuminate\Http\Response 
     */ 
     public function getReset($token = null) 
     { 
      if (is_null($token)) { 
       throw new NotFoundHttpException; 
      } 

      return view('auth.reset')->with('token', $token); 
     } 

     /** 
     * Reset the given user's password. 
     * 
     * @param \Illuminate\Http\Request $request 
     * @return \Illuminate\Http\Response 
     */ 
     public function postReset(Request $request) 
     { 
      $this->validate($request, [ 
       'token' => 'required', 
       'email' => 'required|email', 
       'password' => 'required|confirmed', 
      ]); 

      $credentials = $request->only(
       'email', 'password', 'password_confirmation', 'token' 
      ); 

      $response = Password::reset($credentials, function ($user, $password) { 
       $this->resetPassword($user, $password); 
      }); 

      switch ($response) { 
       case Password::PASSWORD_RESET: 
        return redirect($this->redirectPath()); 

       default: 
        return redirect()->back() 
           ->withInput($request->only('email')) 
           ->withErrors(['email' => trans($response)]); 
      } 
     } 

     /** 
     * Reset the given user's password. 
     * 
     * @param \Illuminate\Contracts\Auth\CanResetPassword $user 
     * @param string $password 
     * @return void 
     */ 
     protected function resetPassword($user, $password) 
     { 
      $user->password = bcrypt($password); 

      $user->save(); 

      Auth::login($user); 
     } 

     /** 
     * Get the post register/login redirect path. 
     * 
     * @return string 
     */ 
     public function redirectPath() 
     { 
      if (property_exists($this, 'redirectPath')) { 
       return $this->redirectPath; 
      } 

      return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home'; 
     } 
    } 

およびビューの 最初の電子メール/ password.blade.php

<?php 
Click here to reset your password: {{ url('password/reset/'.$token) }} 
?> 

AUTH/password.blade.php

@extends('layouts.master') 

@section('content') 

<div class="container-fluid"> 
<div class="row"> 
<div class="col-md-8 col-md-offset-2"> 
<div class="panel panel-default"> 
<div class="panel-heading">Reset Password</div> 
<div class="panel-body"> 
    @if (session('status')) 
     <div class="alert alert-success"> 
      {{ session('status') }} 
     </div> 
    @endif 

    @if (count($errors) > 0) 
     <div class="alert alert-danger"> 
     <strong>Whoops!</strong> There were some problems with your input.<br><br> 
     <ul> 
      @foreach ($errors->all() as $error) 
        <li>{{ $error }}</li> 
      @endforeach 
     </ul> 
     </div> 
     @endif 

<form class="form-horizontal" role="form" method="POST" action="/password/email"> 
<input type="hidden" name="_token" value="{{ csrf_token() }}"> 

<div class="form-group"> 
<label class="col-md-4 control-label">E-Mail Address</label> 
<div class="col-md-6"> 
<input type="email" class="form-control" name="email" value="{{ old('email') }}"> 
</div> 
</div> 

<div class="form-group"> 
<div class="col-md-6 col-md-offset-4"> 
<button type="submit" class="btn btn-primary"> 
     Send Password Reset Link 
</button> 
</div> 
</div> 
</form> 

</div> 
</div> 
</div> 
</div> 
</div> 

@endsection 

reset.blade.php

@extends('layouts.master') 

@section('content') 

<div class="container-fluid"> 
<div class="row"> 
<div class="col-md-8 col-md-offset-2"> 
<div class="panel panel-default"> 
<div class="panel-heading">Reset Password</div> 
<div class="panel-body"> 

@if (count($errors) > 0) 
    <div class="alert alert-danger"> 
    <strong>Whoops!</strong> There were some problems with your input.<br><br> 
    <ul> 
     @foreach ($errors->all() as $error) 
       <li>{{ $error }}</li> 
     @endforeach 
     </ul> 
     </div> 
@endif 

<form class="form-horizontal" role="form" method="POST" action="/password/reset"> 
<input type="hidden" name="_token" value="{{ csrf_token() }}"> 
<input type="hidden" name="token" value="{{ $token }}"> 

<div class="form-group"> 
<label class="col-md-4 control-label">E-Mail Address</label> 
<div class="col-md-6"> 
<input type="email" class="form-control" name="email" value="{{ old('email') }}"> 
</div> 
</div> 

<div class="form-group"> 
<label class="col-md-4 control-label">Password</label> 
<div class="col-md-6"> 
<input type="password" class="form-control" name="password"> 
</div> 
</div> 

<div class="form-group"> 
<label class="col-md-4 control-label">Confirm Password</label> 
<div class="col-md-6"> 
<input type="password" class="form-control" name="password_confirmation"> 
</div> 
    </div> 

<div class="form-group"> 
<div class="col-md-6 col-md-offset-4"> 
<button type="submit" class="btn btn-primary"> 
      Reset Password 
</button> 
</div> 
</div> 
</form> 

</div> 
</div> 
</div> 
</div> 
</div> 

@endsection 

と最後に私のログインビュー

<a href="{{action("[email protected]")}}">Mot de passe oublié?</a> 

ので、エラーが

未定義のメソッドLaravel \ルーティング\ルートへの呼び出し::コントローラ()

であるあなたは私を助けてくださいすることができます/私は、ルート、多くの時間が、常に同じ問題を変更してみてください! !!!!!!
は、あなたがこれを削除する必要が

答えて

0

これはlaravel 5

Route::controllers([ 
    'auth' => 'Auth\AuthController', 
    'password' => 'Auth\PasswordController', 
]); 

これをするためにありますララベル用です。5.2

Route::group(['middleware' => ['web']], function() { 
    Route::controllers([ 
     'auth' => 'Auth\AuthController', 
     'password' => 'Auth\PasswordController', 
    ]); 
}); 
+0

同じメッセージも、私はそれを変更 ' ルート::コントローラ([ 'AUTH' =>「認証\金 ); 定義されていないメソッドを呼び出すLaravel \ Routing \ Route :: controllers() – sabrine

0

私はあなたがこれを使用する場合、エラーが来るあなたはroutes.phpの

use Illuminate\Routing\Route; 

Route::controllers([ 
    'auth' => 'Auth\AuthController', 
    'password' => 'Auth\PasswordController', 
]); 

で使用していると思います。下記の1にも作品 としてそれを残してはいけないが、何もルート をインポートする必要があります。未定義のメソッドを照らし\ルーティング\ルート::コントローラ()

へ コールは、このエラーの使用にこの

use Illuminate\Support\Facades\Route; 


Route::controllers([ 
    'auth' => 'Auth\AuthController', 
    'password' => 'Auth\PasswordController', 
]); 

注意を避けるために、

Route::controllers([ 
     'auth' => 'Auth\AuthController', 
     'password' => 'Auth\PasswordController', 
    ]); 
+0

私はルート内に何もインポートしませんでした 私はイルミネイトを使用してください\サポート\ Facades \ Route; 同じエラーメッセージ – sabrine

+0

トレースを使用しているエラー –

+0

あなたが使用しているlaravelのバージョン?ララベル5または5.1または5.2 –