路由 Laravel 8 不支持 GET 方法
GET method is not supported for the route Laravel 8
我正在测试我的删除功能,但我如何将它集成到一个按钮这是代码
profile.blade
<div class="modal-body">Select the delete button to continue</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" data-dismiss="modal">Cancel</button>
<button class="btn btn-secondary"type="button" href="/delete">Delete</a>
</div>
</div>
这是我想使用函数的地方
这是路线
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\{
DashboardController,
HomeController,
LoginController,
RegisterController,
FileuploadController,
MemberController
};
Route::middleware(['guest'])->group(function() {
// (url_attern, [Controller_name, method_name])->name(alias)
Route::get('/', [HomeController::class, 'index'])->name('home.index');
Route::get('/attorney', [HomeController::class, 'attorney'])->name('home.attorney');
Route::get('/service', [HomeController::class, 'service'])->name('home.service');
Route::get('/login', [LoginController::class, 'login'])->name('login.login');
Route::post('/login', [LoginController::class, 'auth'])->name('login.auth');
Route::get('/register', [RegisterController::class, 'signin'])->name('register.signin');
Route::post('/register', [RegisterController::class, 'register'])->name('register.register');
});
Route::middleware(['auth'])->group(function() {
Route::get('/logout', [LoginController::class, 'logout'])->name('login.logout');
Route::get('/dashboard', [DashboardController::class, 'dashboard'])->name('dashboard.dashboard');
Route::get('/profile', [DashboardController::class, 'profile'])->name('dashboard.profile');
Route::get('/journal', [DashboardController::class, 'journal'])->name('dashboard.journal');
Route::get('/files', [DashboardController::class, 'files'])->name('dashboard.files');
Route::post('/files', [FileuploadController::class, 'files'])->name('dashboard.files');
Route::get('/directory', [DashboardController::class, 'directory'])->name('dashboard.directory');
Route::get('/calendar', [DashboardController::class, 'calendar'])->name('dashboard.calendar');
Route::post('/delete', [DashboardController::class, 'delete'])->name('dashboard.delete');
});
和函数
public function delete(){
$user = \User::find(Auth::user()->id);
Auth::logout();
if ($user->delete()) {
return Redirect::route('/')->with('global', 'Your account has been deleted!');
}
}
如何使用该功能删除当前登录的用户
我的路线已经在 post 用于删除,但它表明此路线不支持 GET 方法
您必须在带有 POST 动词的表单中实现它,因此
<form action="/logout" method="post">
{{csrf_field()}}
<a href='#' onclick='this.parentNode.submit(); return false;' class="nav-link">
<i class="nav-icon fa fa-sign-out-alt"></i>
<p>Log out</p>
</a>
</form>
路由来自 POST 动词,因此您需要在表单中插入按钮:
<div class="modal-body">Select the delete button to continue</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" data-dismiss="modal">Cancel</button>
<form action="{{ route('dashboard.delete') }}" method="POST">
{{ csrf() }}
<button class="btn btn-secondary" type="submit">Delete</button>
</form>
</div>
</div>
我正在测试我的删除功能,但我如何将它集成到一个按钮这是代码
profile.blade
<div class="modal-body">Select the delete button to continue</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" data-dismiss="modal">Cancel</button>
<button class="btn btn-secondary"type="button" href="/delete">Delete</a>
</div>
</div>
这是我想使用函数的地方
这是路线
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\{
DashboardController,
HomeController,
LoginController,
RegisterController,
FileuploadController,
MemberController
};
Route::middleware(['guest'])->group(function() {
// (url_attern, [Controller_name, method_name])->name(alias)
Route::get('/', [HomeController::class, 'index'])->name('home.index');
Route::get('/attorney', [HomeController::class, 'attorney'])->name('home.attorney');
Route::get('/service', [HomeController::class, 'service'])->name('home.service');
Route::get('/login', [LoginController::class, 'login'])->name('login.login');
Route::post('/login', [LoginController::class, 'auth'])->name('login.auth');
Route::get('/register', [RegisterController::class, 'signin'])->name('register.signin');
Route::post('/register', [RegisterController::class, 'register'])->name('register.register');
});
Route::middleware(['auth'])->group(function() {
Route::get('/logout', [LoginController::class, 'logout'])->name('login.logout');
Route::get('/dashboard', [DashboardController::class, 'dashboard'])->name('dashboard.dashboard');
Route::get('/profile', [DashboardController::class, 'profile'])->name('dashboard.profile');
Route::get('/journal', [DashboardController::class, 'journal'])->name('dashboard.journal');
Route::get('/files', [DashboardController::class, 'files'])->name('dashboard.files');
Route::post('/files', [FileuploadController::class, 'files'])->name('dashboard.files');
Route::get('/directory', [DashboardController::class, 'directory'])->name('dashboard.directory');
Route::get('/calendar', [DashboardController::class, 'calendar'])->name('dashboard.calendar');
Route::post('/delete', [DashboardController::class, 'delete'])->name('dashboard.delete');
});
和函数
public function delete(){
$user = \User::find(Auth::user()->id);
Auth::logout();
if ($user->delete()) {
return Redirect::route('/')->with('global', 'Your account has been deleted!');
}
}
如何使用该功能删除当前登录的用户 我的路线已经在 post 用于删除,但它表明此路线不支持 GET 方法
您必须在带有 POST 动词的表单中实现它,因此
<form action="/logout" method="post">
{{csrf_field()}}
<a href='#' onclick='this.parentNode.submit(); return false;' class="nav-link">
<i class="nav-icon fa fa-sign-out-alt"></i>
<p>Log out</p>
</a>
</form>
路由来自 POST 动词,因此您需要在表单中插入按钮:
<div class="modal-body">Select the delete button to continue</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" data-dismiss="modal">Cancel</button>
<form action="{{ route('dashboard.delete') }}" method="POST">
{{ csrf() }}
<button class="btn btn-secondary" type="submit">Delete</button>
</form>
</div>
</div>