【发布时间】:2018-03-25 14:16:12
【问题描述】:
我在学习 laravel 时遇到问题,由于无法通过 Google 等方式找到答案,因此决定在这里提出我的问题。
我正在尝试通过 Id 从数据库中返回一个客户端,可能稍后通过名称返回。
这是我的表格:
<<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Klant invoeren</title>
<link rel="stylesheet" href="{{asset('css/app.css')}}">
</head>
<body>
<p><<form action="{{route('client/'.$client->id.'/show/')}}"
method="get">
<div class="row">
<div class="col-md-4"></div>
<div class="form-group col-md-4">
<label for="price">Achternaam:</label>
<input type="text" class="form-control" name="id">
</div>
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="form-group col-md-4">
{{csrf_field()}}
<button type="submit" class="btn btn-success" style="margin-
left:38px">Zoek klant</button>
</div>
</div>
</form></p>
</body>
</html>
重定向到:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Klant invoeren</title>
<link rel="stylesheet" href="{{asset('css/app.css')}}">
</head>
<body>
<div class="container">
<h2>Voer een klant in</h2><br />
<h1>Showing {{ var_dump($client) }}</h1>
</div>
</body>
</html>`
这是来自 Clientcontroller 的 show 方法:
public function show($id)
{
$client = Client::find($id);
return view('clients.show', compact('client'));
}
这是我正在使用的路线:
Route::get('client/{id}/show','ClientController@show');
有人能发现我的错误吗,因为在过去的几个小时里我搞砸了这个。
编辑:更新代码并添加路由,现在收到客户端变量未在
中定义的错误【问题讨论】:
标签: forms laravel variables controller resources