我正在尝试使用 laravel 构建用户和客户端页面,我创建了一个可用于创建用户的页面,现在我想在单击这些用户时创建一个类似的页面,但我不断遇到此问题。为了将客户端映射到用户,我将 user_id 作为路由查询
路由 addClient/100 不支持 GET 方法。支持的方法:POST。
web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
use App\Http\Controllers\ClientController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/addUser',function(){
return view('addUser');
});
Route::post('/addUser',[UserController::class, 'addUser']);
Route::get('/clients/{id}', [App\Http\Controllers\HomeController::class, 'client'])->name('clienthome');
Route::post('/addClient/{id}',function($id){
return view('addClient',compact('id'));
});
Route::post('/add_Client',[ClientController::class, 'addClient']);
这是addclient.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Add Client</title>
<link rel="stylesheet" href="/Bootstrap/css/bootstrap.css">
<style>
.container{
height: 100vh;
display: flex;
align-items: center;
}
.mb3{
margin-top: 5%;
}
</style>
</head>
<body>
<div class="container justify-content-center">
<form action="{{url('add_Client')}}" method="post">
@csrf
<div class="mb3">
<label for="exampleFormControlInput1" class="form-label">Name</label>
<input type="text" name = "name" class="form-control" id="exampleFormControlInput1" required>
</div>
<div class="mb3">
<label for="exampleFormControlTextarea1" class="form-label">Address</label>
<textarea class="form-control" name = "address" id="exampleFormControlTextarea1" rows="2" required></textarea>
</div>
<div class="mb3">
<label for="exampleFormControlInput1" class="form-label">Country</label>
<input type="text" name = "country" class="form-control" id="exampleFormControlInput1" required>
</div>
<div class="mb3">
<label for="exampleFormControlInput1" class="form-label">Mobile</label>
<input type="number" name = "number" class="form-control" id="exampleFormControlInput1" required>
</div>
<div class="mb3">
<label for="staticEmail" class="col-sm-2 col-form-label">User_id</label>
<div class="col-sm-10">
<input type="number" name = "user_id" readonly class="form-control-plaintext" id="staticEmail" value={{$id}}>
</div>
</div>
<div class="mb3">
<button type="submit" class="btn btn-outline-success">Add Client</button>
</div>
</form>
</div>
<script src="/Bootstrap/js/bootstrap.js"></script>
</body>
</html>
这个网址甚至没有改变
您已在
post
中将路线定义为 web.php
,而不是 get
。
像这样改变你的路线,
Route::get('/addClient/{id}',function($id){
return view('addClient',compact('id'));
});