Home>

You are about to create an administrator page.
>Referenced site Link contents
Add admin related settings to the reference site auth.php. Is ready

When trying to move to the administrator-only screen on the login screen

Error message generated
The POST method is not supported for this route.Supported methods: GET, HEAD.


An error has occurred

web.php
<? php
Auth :: routes ();
Route :: group (['prefix' =>'admin'],

 function () {
    Route :: get ('/', function () {return redirect ('/ admin/images/list');});
    Route :: get ('login', 'Admin \ LoginController @ showLoginForm')->name ('admin_login');
    Route :: post ('login', 'Admin \ LoginController @ login');
});
Route :: group (['prefix' =>'admin', 'middleware' =>'auth: admin'],

 function () {
    Route :: get ('images/list', 'Admin \ ImagesController @ index')->name ('item_list');
});
creat_admins_table.php
<? php
use Illuminate \ Support \ Facades \ Schema;
use Illuminate \ Database \ Schema \ Blueprint;
use Illuminate \ Database \ Migrations \ Migration;
class CreateAdminsTable extends Migration
{
    public function up ()
    {
        Schema :: create ('admins', function (Blueprint $table) {
            $table->bigIncrements ('id');
            $table->string ('name');
            $table->string ('email')->unique ();
            $table->timestamp ('email_verified_at')->nullable ();
            $table->string ('password');
            $table->rememberToken ();
            $table->timestamps ();
        });
    }
    public function down ()
    {
        Schema :: dropIfExists ('admins');
    }
}
<? php
namespace App;
use Illuminate \ Notifications \ Notifiable;
use Illuminate \ Foundation \ Auth \ User as Authenticatable;
class Admin extends Authenticatable
{
    use Notifiable;
 $fillable = [
    'name', 'email', 'password',
];
protected $hidden = [
    'password', 'remember_token',
];
}


app/Excepsions/Handler.php

<? php
namespace App \ Exceptions;
use Exception;
use Illuminate \ Auth \ AuthenticationException;
use Illuminate \ Foundation \ Exceptions \ Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
   // default
    public function render ($request, Exception $exception)
    {
        return parent :: render ($request, $exception);
    }

    if ($request->expectsJson ()) {
        return response ()->json (['error' =>'Unauthenticated.'],

 401);//->json = return in json format
    }
    if (in_array ('admin', $exception->guards (), true)) {
        return redirect ()->guest (route ('admin.login'));
    }
    return redirect ()->guest (route ('login'));
}
}


LoginController.php

<? php
namespace App \ Http \ Controllers \ Admin;
use Illuminate \ Support \ Facades \ Auth;
use Illuminate \ Http \ Request;
use Illuminate \ Foundation \ Auth \ AuthenticatesUsers;
use App \ Http \ Controllers \ Controller;
use App \ Admin;

class LoginController extends Controller
{
    use AuthenticatesUsers;
    protected $redirectTo = '/ images/list';
    public function showLoginForm ()
    {
        return view ('admin.login');
    }
    protected function guard ()
    {
        return \ Auth :: guard ('admin');
    }

    public function logout (Request $request)
    {
        Auth :: guard ('admin')->logout ();
        $this->performLogout ($request);
        return redirect ()->route ('admin_login');
    }
}

views/admin/login.blade.hp

<! DOCTYPE HTML>
<html lang = "en">
  <head>
// omitted<meta name = "csrf-token" content = "{{csrf_token ()}}">
    <title></title>
        <script src = "{{secure_asset ('js/app.js')}}" defer></script>
    <link rel = "stylesheet" href = "https://87c1ac065f9145e183015d2ea2786408.vfs.cloud9.us-east-2.amazonaws.com/css/layout.css">
  </head>
  <body>
      
// Omitted omission
                      {{__ ('Login')}}  
                        
                           <form method = "post" action = "{{route ('admin_login')}}" name = "login">
                           @csrf
                              
                                  <label for = "email">{{__ ('Email address')}}</label>
                                  
                                  <input type = "email" name = "email" value = "{{old ('email')}}" required autocomplete = "email" autofocus>
                             // omitted
                            </form>
                        
        
    
  </body>
 </html>


views/admin/images/list

@extends ('admin.admin_layout')
@section ('title', 'Image list')
@section ('content')
    
        
             Image list 
        
        
            
                 Create new 
            
            
                <form action = "{{route ('item_list')}}" method = "get">
                    
                        <label>Product name</label>
                        
                            <input type = "text" name = "cond_title" value = "{{$cond_title}}">
                        
                        
                            {{csrf_field ()}}
                            <input type = "submit" value = "search">
                        
                    
                </form>
            
        
        // omitted
        
        {{$items->links ()}}
        
    
@endsection


Tried
I checked the Laravel official reference to see if the version of use is different

  • Answer # 1

    Although I have only confirmed it, the source described and presented on the reference site is quite different.

    Reference site

    Route :: group (['prefix' =>'admin'], function () {
        Route :: get ('/', function () (return redirect ('/ admin/home');});
        Route :: get ('login', 'Admin \ LoginController @ showLoginForm')->name ('admin.login');
        Route :: post ('login', 'Admin \ LoginController @ login');
    });

    Proposed source

    Route :: group (['prefix' =>'admin'], function () {
        Route :: get ('/', function () {return redirect ('/ admin/images/list');});
        Route :: get ('login', 'Admin \ LoginController @ showLoginForm')->name ('admin_login');
        Route :: post ('login', 'Admin \ LoginController @ login')->name ('admin_login');
    });
    Route :: group (['prefix' =>'admin', 'middleware' =>'auth: admin'], function () {
        Route :: get ('images/list', 'Admin \ ImagesController @ index')->name ('item_list');
    });

    And

    What is it?
    If you want a solution from others, I want you to do it properly.