2015-09-16 6 views
0

Я пытаюсь войти в систему пользователя в своем приложении, но я не могу войти.Невозможно выполнить входную функцию в laravel 5

Я пробую много способов решить эту проблему, но все еще не исправил.

Скажите, пожалуйста, где я ошибаюсь.

Ошибка is--

вызов функции члена попытке() на не-объект

ControllePage--

<?php 
namespace App\Http\Controllers; 
use DB; 
use Route; 
use User; 
use Hash; 
use Auth; 
use Input; 
use Validator; 
use Authenticatable; 
use Redirect; 
use Illuminate\Http\Request; 

class UsersController extends BaseController 
{ 
    /** 
    * Perform validations on user data 
    * Hash Password 
    * Create 
    * @return Response 
    */ 


    public function loginUserAuth() { 


       $rules = array(
      'email' => 'required|email', // make sure the email is an actual email 
      'password' => 'required|min:5' // password can only be alphanumeric and has to be greater than 3 characters 
     ); 

     // run the validation rules on the inputs from the form 
     $validator = Validator::make(Input::all(), $rules); 
     if ($validator->fails()) { 
      print_r($validator->messages()); 
       die; 
      return Redirect::to('/login') 
       ->withInput(Input::except('password')) // send back the input (not the password) so that we can repopulate the form 
       ->with('errors',$validator->messages()); 
     } else { 
      $userdata = array(
       'email'  => Input::get('email'), 
       'password' => Hash::make('password') 
      ); 
      // attempt to do the login 
      if (Auth::user()->attempt($userdata,true)) { 
       // validation successful! 
       // redirect them to the secure section or whatever 
       // return Redirect::to('secure'); 
       // for now we'll just echo success (even though echoing in a controller is bad) 
       print_r("error"); 
       die; 
       return Redirect::intended('/'); 
      } else { 
       // validation not successful, send back to form 
       print_r("error11"); 
       die; 
       return Redirect::to('/login')->with('loginerrors','Invalid username or password'); 
      } 
     } 
} 

Пожалуйста, помогите.

ответ

2

Вы не аутентификацией пользователя еще, так что вы используете:

if (Auth::attempt($credentials)) {... 

Не:

if (Auth::user()->attempt($credentials)) {... 

http://laravel.com/docs/5.0/authentication#authenticating-users

+0

Спасибо Markdwhite и CodeRomeos, теперь его работа. – aniruddh

+0

@aniruddh Пожалуйста, примите ответ, если он работает на вас – markdwhite

2

эта ошибка показывает, потому что вы используете Auth: : пользователь(), который возвращает нуль , попробуйте это: -

Auth::attempt($userdata) 
Смежные вопросы