i have this error when user return from login to home page i can’t understand what is it i am doing MultiAuth in laravel 5 and also help me if i can use login function and other registration function that is already available for users table i have no idea how to do that with already written functions
this is my login function
public function login() { $data = Input::all(); // Applying validation rules. $rules = array( 'email' => 'required|email', 'password' => 'required|min:6', ); $validator = Validator::make($data, $rules); if ($validator->fails()){ // If validation falis redirect back to login. return Redirect::to('admin/login')->withInput(Input::except('password'))->withErrors($validator); } else { $userdata = array( 'email' => Input::get('email'), 'password' => Input::get('password') ); } // doing login. if (Auth::validate($userdata)) { if (Auth::attempt($userdata)) { return Redirect::intended('admin'); } } else { // if any error send back with message. Session::flash('error', 'Something went wrong'); return Redirect::to('admin/login'); } }
this is my AdminController
<?php namespace AppHttpControllersAdmin; use IlluminateHttpRequest; use AppHttpRequests; use AppHttpControllersController; class AdminController extends Controller { // public function __construct(){ // // $this->middleware('admins'); // } public function index(){ // $user = Auth::user(); // dd($user); return view('admin.home'); } }
Advertisement
Answer
Add to your controller:
protected $guard = 'admin'; public function login() { $data = Input::only(['email', 'password']); // Applying validation rules. $rules = array( 'email' => 'required|email', 'password' => 'required|min:6', ); $validator = Validator::make($data, $rules); if ($validator->fails()){ // If validation falis redirect back to login. return Redirect::to('admin/login') ->withInput(Input::except('password')) ->withErrors($validator); } if (Auth::->attempt($userdata)) { return Redirect::intended('admin'); } return Redirect::to('admin/login') ->with('error', 'Something went wrong'); }