Php 没有针对模型Laravel 5.4的查询结果

Php 没有针对模型Laravel 5.4的查询结果,php,laravel,Php,Laravel,我对编辑事件有问题。 没有模型[App\HomeModel]{id}的查询结果 我真的不知道如何解决我的问题。 我尝试更改查找失败,但仍然遇到一些问题。 我将findorfail更改为HomeModel::where('id',$id)->first(); 但我还是遇到了一个错误:从空值创建默认对象 具有编辑和更新功能的控制器: <?php /** * Show the form for editing the specified resource. * *

我对编辑事件有问题。 没有模型[App\HomeModel]{id}的查询结果 我真的不知道如何解决我的问题。 我尝试更改查找失败,但仍然遇到一些问题。 我将findorfail更改为HomeModel::where('id',$id)->first(); 但我还是遇到了一个错误:从空值创建默认对象

具有编辑和更新功能的控制器:

<?php
/**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $event = HomeModel::findOrFail($id);
        $event->start;
        $event->end;

        $data = [
            'page_title'    => 'Edit '.$event->title,
            'event'         => $event,
        ];
        return view('edit',$data);
    }
    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {

        $time = explode(" - ", $request->input('daterange'));        
        $event                  = HomeModel::findOrFail($id);
        $event->name            = $request->input('name');
        $event->title           = $request->input('title');
        $event->start      = $time[0];
        $event->end        = $time[1];
        $event->save();

        return redirect('/home/list');

    }
编辑视图:

@extends('layouts.app'))
@节(“内容”)
编辑事件
{{csrf_field()}}
命名事件
标题事件
编辑事件
$(函数(){
$('input[name=“daterange”]”)。daterangepicker({
时间选择器:是的,
时间选择器24小时:对,
slotLabelFormat:'HH:mm:ss',
区域设置:{
格式:“YYYY/MM/DD HH:MM:ss”,
分隔符:“-”,
}
});
});

@endsection
$id
打印到浏览器中,并确保设置正确。然后在数据库中查看是否有与该ID匹配的行。当我单击“编辑”按钮时,ID是正确的,但接下来我看到类似于/list/edit/{ID}的内容。当我发布到DateBase时,我遇到了一个类似的问题,我的控制器方法接收到一个空模型,尽管我确定我提供的ID在数据库中。问题是自动生成的路由规则使用了不同的参数名称。你可能有类似的问题。尝试列出您的路由规则?好的,我修复了它,只需使用where并在edit.bladePrint
$id
中将数组添加到表单中,然后将其输出到浏览器中,并确保设置正确。然后在数据库中查看是否有与该ID匹配的行。当我单击“编辑”按钮时,ID是正确的,但接下来我看到类似于/list/edit/{ID}的内容。当我发布到DateBase时,我遇到了一个类似的问题,我的控制器方法接收到一个空模型,尽管我确定我提供的ID在数据库中。问题是自动生成的路由规则使用了不同的参数名称。你可能有类似的问题。尝试列出您的路由规则?好的,我修复了它,只需在edit.blade中使用where和添加数组即可