php - [路由 : time. 更新] [URI: time/{time}] 缺少必需的参数

标签 php laravel laravel-blade

我正在使用 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/

相关文章:

javascript - 单击时包含基于 HTML 的 Blade View

javascript - 如何在将 ajax 发送到 php 后关闭页面重新加载以及如何修复此代码

php - Laravel“类型错误 : While Updating Records with PUT/PATCH Methods

Laravel 多数据库连接连接表

php - 逃离刀锋

php - Laravel - 通过 View 传递对象并在 Blade 中使用

php - 在 JavaScript 中将字符串转换为 Date()

php - ajax GET - 来自 php 未通过的结果

php - 如何通过键添加/附加新项目 Laravel Collection

php - Laravel 5 本地化 : exclude/public/directory