1
votes

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)

1
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.Jirennor
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?Vishal Desai
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?Jirennor
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.Vishal Desai
its not showing error after changing the function but just gives me blank page when i hit loginVishal Desai

1 Answers

1
votes

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.