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 generatedThe POST method is not supported for this route.Supported methods: GET, HEAD.
An error has occurred
<? 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
Related articles
- php - uncaught error: call to undefined method composer
- i would like to know if there is a download method for old php (5640) for windows
- php - about the prepare method of the database handler
- php - get method action method doesn't work
- php - htaccess file description method
- php - a method to display an array in a table
- php setting method (lollipop)
- php - relation method when displaying like department → area → staff
- multiple batch replacement method using php str_replace
- [php] method to overwrite associative array data with the contents of form
- php - cannot process comit method as undefined method
- php - i don't know the location of the method register() called by /register
- php - correspondence method of url in reply when creating bulletin board
- call static method on command when running php in command prompt
- php - display method after storing images in array
- php - i want to separate authentication and non-authentication of method use by user name with session function
Related questions
- php - access mysql on the x server locally
- php - i want to reflect the datetime data saved in mysql in the value of and display it initially
- please explain the source code of cakephp
- i want to store the text obtained from php/xml in mysql
- php: i want to specify a line in the database and display it
- php - i want to display two columns of the database
- how to create a new table with the user name as the table name [php + mysql]
- php - about pg4wp which runs wordpress with postures
- php : MySQL Server won't start on CentOS
- i want to resolve a php error syntax error, unexpected end of file
Although I have only confirmed it, the source described and presented on the reference site is quite different.
Reference site
Proposed source
And
What is it?
If you want a solution from others, I want you to do it properly.