参数1传递给App \ Http \ Controllers \ Auth \ LoginController :: authenticated()

时间:2018-04-29 06:23:38

标签: php laravel validation laravel-5

帮助我理解并解决此类错误。

错误:

  

Symfony \ Component \ Debug \ Exception \ FatalThrowableError(E_RECOVERABLE_ERROR)   输入错误:传递给App \ Http \ Controllers \ _Auth \ _Att;控制器\ _Auth \ _ \ _ \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n请将实例化为@ \ _对照\ Http \ _Request \ _Permid \ _Percid第104行的proj \ easywash \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Auth \ AuthenticatesUsers.php

登录控制器:

    <?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Auth;
class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/home';

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

    public function authenticated(Request $request, $user)
        {
            if (!$user->verified) {
                auth()->logout();
                return back()->with('warning', 'You need to confirm your account. We have sent you an activation code, please check your email.');
            }
            return redirect()->intended($this->redirectPath());
        }

    public function userLogout()
    {
        Auth::guard('web')->logout();
        return redirect('/home');
    }
}

注册控制器:

<?php

namespace App\Http\Controllers\Auth;
use App\User;
use App\Mail\VerifyMail;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use App\VerifyUser;
use Auth;
use DB;
use Mail;
use Illuminate\Http\Request;

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = '/home';

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

    /**
     * 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|string|max:255',
            'email' => 'required|string|email|max:255|unique:users',
            'password' => 'required|string|min:6|confirmed',

        ]);
    }

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

                $verifyUser = VerifyUser::create([
                    'user_id' => $user->id,
                    'token' => str_random(40)
                ]);

                Mail::to($user->email)->send(new VerifyMail($user));

                return $user;


    }

    public function verifyUser($token)
    {
        $verifyUser = VerifyUser::where('token', $token)->first();
        if(isset($verifyUser) ){
            $user = $verifyUser->user;
            if(!$user->verified) {
                $verifyUser->user->verified = 1;
                $verifyUser->user->save();
                $status = "Your e-mail is verified. You can now login.";
            }else{
                $status = "Your e-mail is already verified. You can now login.";
            }
        }else{
            return redirect('/login')->with('warning', "Sorry your email cannot be identified.");
        }

        return redirect('/login')->with('status', $status);
    }
    protected function registered(Request $request, $user)
    {
        $this->guard()->logout();
        return redirect('/login')->with('status', 'We sent you an activation code. Check your email and click on the link to verify.');
    }


   }

2 个答案:

答案 0 :(得分:1)

我也有与您相同的problem,我用此answer解决了这个问题。


答案

在LoginController上更改您的use语句:

use Illuminate\Http\Request;
// And try to comment out the next line
// use App\Http\Requests;

您正在从AuthenticatesUsers特征中覆盖this方法,该特征将接收Illuminate\Http\Request,而不是App\Http\Controllers\Auth\Request

答案 1 :(得分:0)

目录->应用->控制器->身份验证-> RegisterController

protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => Hash::make($data['password']),
    ]);`enter code here`
}
用户模型上的

control + x代码和control + v

因此请使用终端php artisan route:list