为了账号安全,请及时绑定邮箱和手机立即绑定

缺少 [Route: emps.show] [URI: emps/{emp}] 所需的参数。

缺少 [Route: emps.show] [URI: emps/{emp}] 所需的参数。

PHP
一只斗牛犬 2022-12-23 16:17:53
这是我的 empcontroller.blade.php     * Display the specified resource.     *     * @param  \App\employee  $employee     * @return \Illuminate\Http\Response     */    public function show(employee $employee)    {        $employees = employee::all();        return view ('emps.show',compact('employees'))->with('i');    }这是我的 show.blade.php@extends('emps.layout')@section('content')<div class="row">    <div class="col-sm-12 col-md-12 col-xs-12">            <div class="pull-right">               <a href="{{route('emps.index')}}">Back</a>            </div>    </div>    <table class="table table-borderd table-hover">        <tr>            <th>Name:</th>            <th>Age:</th>            <th>Mobile no:</th>            <th>Departmetn:</th>            <th>State:</th>        </tr>        @foreach ($employees as $employee)    <tr>        <td>{{++$i}}</td>        <td>{{$employee->name}} </td>        <td>{{$employee->age}}</td>        <td>{{$employee->mobile}} </td>        <td>{{$employee->department}}</td>        <td>{{$employee->state}}</td>     </tr>        @endforeach    </table>    </div></div>@endsection这是我的 route.webRoute::resource('emps', 'empcontroller');这是我的 index.blade.php<div class="pull-left"><a href="{{route('emps.create')}}">Add New product</a><a href="{{route('emps.show')}}">show employees</a></div>当我点击节目时,员工会抛出此错误 [Route: emps.show] [URI: emps/{emp}] 缺少必需的参数。(视图:D:\xampp\htdocs\crud1\resources\views\emps\index.blade.php)
查看完整描述

1 回答

?
元芳怎么了

TA贡献1798条经验 获得超7个赞

问题出在这行代码中:

<a href="{{route('emps.show')}}">show employees</a>

您必须将参数传递给员工的 ID 以仅显示该员工。

像这样 :

<a href="{{route('emps.show', ['id'=>$someId])}}">show employees</a>

还有一件事,在 show 方法中你得到所有的员工并返回他们,这不是 show 方法应该做的,它是返回所有员工的索引方法 show 方法只显示一条记录

另一件事是关于命名约定,类名应以大写字母开头Employee


查看完整回答
反对 回复 2022-12-23
  • 1 回答
  • 0 关注
  • 66 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信