1

I have created separate table called subscribers in mysql changed config/auth.php settings to 'model' => App\Subscribers::class, 'table' => 'subscribers'. I have login form on home page, that submits to the home page. so in routes i have below

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

Route::post('/', 'LoginController@validate');

my LoginController

namespace App\Http\Controllers;

use App\Http\Requests;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    public function validate()
    {
        // attempt to do the login
        $auth = Auth::attempt(
            [
                'email'  => strtolower(Input::get('email')),
                'password'  => Hash::make(Input::get('password'))
            ]
        );
        if ($auth) {
            return Redirect::to('dashboard');
        }

    }
}

when i login i get below error

Declaration of App\Http\Controllers\LoginController::validate() should be compatible with App\Http\Controllers\Controller::validate(Illuminate\Http\Request $request, array $rules, array $messages = Array, array $customAttributes = Array)

8
  • Rename your function to something else then 'validate'. I think that's why you are having this issue. Don't forget to change your route to. Commented Oct 26, 2015 at 18:14
  • okay let me try, also in my if Auth::attempt() IDE is telling me that function is not defined. would you know what do i need to put for 'use' at the top? Commented Oct 26, 2015 at 18:17
  • why are you not using the builtin authentication from laravel? laravel.com/docs/5.1/authentication. Or do you want to do something special regarding authentication? Commented Oct 26, 2015 at 18:25
  • i was building it while learning laravel at the same time, and i had already built subscriber model and db table with lot of info, so i wanted to just auth with that table instead. Commented Oct 26, 2015 at 18:28
  • its not showing error after changing the function but just gives me blank page when i hit login Commented Oct 26, 2015 at 18:28

1 Answer 1

1

You can't use 'validate' as a name for a function. It will conflict with:

App\Http\Controllers\Controller::validate

Also add an 'else' to your if statement so if your authentication fails you can redirect the user back to the login screen for example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.