我正在使用 laravel 6。我在同一个应用程序中有类似的 Controller 和类似的 View ,它工作正常。对比之后还是找不到错误。
Facade\Ignition\Exceptions\ViewException
Missing required parameters for [Route: time.update] [URI: time/{time}].
(View: C:\xampp\htdocs\cms\resources\views\timeslot\edit.blade.php)
http://cms.test/time/4/edit
Error: return new static("Missing required parameters for [Route {$route->getName()}] [URI: {$route->uri()}].");
编辑链接:
<a href="{{route('time.edit',$timeslot->id)}}">{{$timeslot->timeslot_title}}</a>
Controller :
public function edit(Timeslot $timeslot){
return view('timeslot.edit',compact('timeslot'));
}
public function update(TimeslotRequest $request, Timeslot $timeslot){
$timeslot->update($request->all());
}
编辑表单:
@extends('layouts.admin')
@section('content')
<h1>Edit Timeslot Details </h1>
<form action="{{route('time.update',$timeslot->id)}}" method="POST">
@method('PATCH')
@include('timeslot.form')
<button type="submit" class="btn btn-primary">Update Timeslot</button>
</form>
@endsection
最佳答案
route()
第二个参数是一个关联数组。如果您通过模型,它可以自动获取时间段 ID。假设您的 route 的模型名称是“timeslot”。
<a href="{{route('time.edit', ['timeslot' => $timeslot]}}">{{$timeslot->timeslot_title}}</a>
关于php - [路由 : time. 更新] [URI: time/{time}] 缺少必需的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61563149/