douyinmian8151 2016-03-31 05:51
浏览 55

Handler.php第102行中的NotFoundHttpException:模型[App \ ...]没有查询结果

I tried to edit/update my data in database. But always get this error.

NotFoundHttpException in Handler.php line 102: No query results for model [App\Produk]

Here's the function in controller:

public function edit($id)
{
    $data = Produk::findOrFail($id);
    return view('pages.admin.edit')->with('data',$data);
}
public function update($id, Request $request)
{
    $data = Produk::findOrFail($id);
    $data->update($request->all());
    return redirect('pages.admin.lihat');
}

And here's my edit.blade.php form:

    {!! Form::model($data,['method'=>'PATCH','url' => 'admin/update']) !!}

<div class="contact-form">
<div class="form-group">
    {!! Form::label('Nama Produk') !!}
    {!! Form::text('nama', null, 
        array('required', 
              'class'=>'form-control', 
              'placeholder'=>'Nama Produk')) !!}
</div>

<div class="form-group">
    {!! Form::label('Jumlah Produk') !!}
    {!! Form::number('jumlah', null, 
        array('required', 
              'class'=>'form-control', 
              'placeholder'=>'Jumlah Produk')) !!}
</div>

<div class="form-group">
    {!! Form::label('Harga') !!}
    {!! Form::text('harga', null, 
        array('required', 
              'class'=>'form-control', 
              'placeholder'=>'Harga')) !!}
</div>

<div class="form-group">
    {!! Form::label('Gambar') !!}
    {!! Form::text('images', null, 
        array('required', 
              'class'=>'form-control', 
              'placeholder'=>'Gambar')) !!}
</div>

<div class="form-group">
    {!! Form::submit('Edit', 
      array('class'=>'btn btn-primary')) !!}
</div>

</div>
{!! Form::close() !!}

I use this in my routes (the first one is for the store function so nothing to do with this update):

Route::post('admin/success','ProdukController@simpan');

Route::resource('admin','ProdukController');

And the Produk Model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Produk extends Model
{
    protected $fillable =[

        'nama',
        'jumlah',
        'harga',
        'images'

    ];
}
  • 写回答

2条回答 默认 最新

  • douyao1994 2016-03-31 07:01
    关注

    that happens cause data with that id doesn't exits $data = Produk::findOrFail($id) . you can use Produk::find($id);or data = Produk::where('id', $id)->first(); (it won't throw an error)

    read more at documentation

    评论

报告相同问题?

悬赏问题

  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM