0

This is a extension of this question. I am trying to follow the accepted answer for multi auth, adding one more user table admin to my Laravel project. I have done all thing as he said, adding the guards, controller, middleware and routes for admin model. But when I enter the locolhost/admin/register, which is set previously in routes.php, and enter the information for registration, I got an error of View [admin.auth.register] not found. Given the routes.php according to that questions:

Route::group(['middleware' => ['web']], function () {
#Route::auth();
Route::get('web-login', 'Auth\AuthController@webLogin');
Route::post('web-login', ['as'=>'web-login','uses'=>'Auth\AuthController@webLoginPost']);

Route::get('/admin/login','AdminAuth\AuthController@showLoginForm');
Route::post('/admin/login','AdminAuth\AuthController@login');
Route::get('/admin/logout','AdminAuth\AuthController@logout');

// Registration Routes...
Route::get('admin/register', 'AdminAuth\AuthController@showRegistrationForm');
Route::post('admin/register', 'AdminAuth\AuthController@register');

Route::get('/admin', 'AdminController@index');
Route::get('/', function () {
return view('welcome');
});

And the AdminAuth/AuthController.php:

   public function showLoginForm()
{
    if (view()->exists('auth.authenticate')) {
        return view('auth.authenticate');
    }

    return view('admin.auth.login');
}
public function showRegistrationForm()
{
    return view('admin.register');
}  

Just showLoginForm is defined, but the register function has not. Do you know how should I define it? Thanks in advance!

EDIT:

Here is what I have tried:

    public function register(Request $request)
{
    $validator = $this->validator($request->all());

    if ($validator->fails()) {
        $this->throwValidationException(
            $request, $validator
        );
    }

    Auth::login($this->create($request->all()));

    return redirect($this->redirectPath());
}

But I got an NotFoundHttpException error. Do you have any idea of it? Thanks!!!

Community
  • 1
  • 1
user5779223
  • 1,270
  • 3
  • 17
  • 34

1 Answers1

0

The error says that you don't have a table called "admins". Make sure you do have it or change the table value to a correct one in your model.

Limit 1 is added to SQL because the auth system is trying to load a single admin (user) record, not a collection.

MaGnetas
  • 4,688
  • 3
  • 30
  • 50
  • Thanks for your answer! But there is indeed a `Admin.php` file and the corresponding migration file. When I input `php artisan migrate`. The output is nothing to migrate. How can I check more? Thanks! – user5779223 May 16 '16 at 18:40
  • Can you connect to database using any SQL tool and see if the table admins exists? I use MySQL workbench but it can be any other - navicat, sqlyog, phpmyadmin etc – MaGnetas May 16 '16 at 18:41
  • Which can used in homestead? – user5779223 May 16 '16 at 18:42
  • are you familiar with mysql? You can use inline mysql but that's slightly trickier. Basically any tool I mentioned can connect to mysql in homestead too – MaGnetas May 16 '16 at 18:44
  • It really doesn't exist. But why? I have done the migration already. – user5779223 May 16 '16 at 18:51
  • look into migrations table, see if it's there. Also check your laravel error log – MaGnetas May 16 '16 at 18:54
  • I remigrate and it works this time. But when I register a new ac. No admin is created and I am redirected to the previous page. Do you have any idea? – user5779223 May 16 '16 at 19:20
  • There can be quite many reasons. You'll have to debug it yourself. Pay attention to Guards and (controller) properties. – MaGnetas May 16 '16 at 19:25
  • Seems that the reason is in the `routes.php`: `The reason behind it is because Route::get('/') isn’t under middleware group web if you inspect in routes.php file. Move it under web middleware group and it will work.` But seems now laravel change it to `Route::auth();` simply. Do you know how to deal with this case? Thanks! – user5779223 May 16 '16 at 19:55
  • I believe you might wanna have a look at app/Http/Kernel.php. You can assign global middleware (applied to any request), per group or set it separately (via routes or controller). If middleware is the case you can set it the way auth needs it to be – MaGnetas May 16 '16 at 20:42
  • Now I think I can narrow down my question and I rewrote it. Could you please take a look at it? – user5779223 May 17 '16 at 12:04