【问题标题】:NotFoundHttpException in Handler.php while trying to update尝试更新时 Handler.php 中的 NotFoundHttpException
【发布时间】:2016-11-20 13:00:56
【问题描述】:

我正在尝试使用我的 create.blade.php 中的表单重用来更新我的表中的一个人。从 Laracast 视频到第 13 集,我一直关注 T 的所有内容,但在尝试更新时遇到了障碍。

它给了我这个错误:

NotFoundHttpException in Handler.php line 103: No query results for model [App\Models\ContactPerson]

我的 ContactPerson 是我数据库中的表。

这是我到目前为止的代码,

路线

Route::post('create', 'ResourceController@store');

Route::resource('/pages', 'ResourceController');

Route::get('pages/{id}/edit', 'ResourceController@edit')->where('id', '[0-9]+');

Route::patch('pages/{id}', 'ResourceController@update')->where('id', '[0-9]+');

资源控制器

use App\Models\ContactPerson;
use App\Http\Requests;
use Request;  


    public function store(Requests\CreateNewContactRequest $request)
    {
        ContactPerson::create($request->all());

        return redirect('resource');
    }

    public function edit($id)
    {
       $user = ContactPerson::findOrFail($id);

       return view('pages.edit')->with(compact('user'));

    }

    public function update(Request $request, $id)
    {

       //unset($request['_method']); A friend recommended doing this since he had the same problems, but it didn't work for me (MethodNotAllowed error)
       //unset($request['_token']);

       $user = ContactPerson::findOrFail($id);

       //ContactPerson::where('Contact_ID', $id->Id)->update($request->all()); 

        $user->update($request->all());

        return redirect('pages.resource');
    }
}

edit.blade.php(在 pages 文件夹内)

@extends('app')

@section('content')
    {!! Form::model($user, ['method' => 'PATCH', 'action' => ['ResourceContoller@update', $user->id]]) !!}

      //I've tried setting it to where instead of 'action' it's 'url' => 'pages/edit', $user->id  but still not working.

        <div class="form">
            {!! Form::label('first', 'First Name: ') !!}
            {!! Form::text('First_Name', null, ['class' => 'form']) !!}
        </div>

        ...

路线列表

我一直被困在这个错误和MethodNowAllowed 错误之间,因为它现在大约 3-4 天不喜欢 PUT/PATCH 方法。任何帮助都会很棒!

【问题讨论】:

  • 到目前为止,我没有看到任何与 PhpStorm 相关的内容...顺便说一句 - 当这不起作用时,您在浏览器中看到什么 URL?所有其他 URL 是否有效(执行相同/类似操作)?
  • 出现错误后进入“页面/编辑”。这是迄今为止我唯一的更新方法,所有其他方法都有效,创建和视图。

标签: php html laravel http


【解决方案1】:

您在 edit.blade.php 中有拼写错误, 'action' => 'ResourceController@update'

【讨论】:

  • Dileep,谢谢,在我的代码中是正确的。我在堆栈上更改了它,因为这是 Jeffrey Way 在他的教程中的内容,我将其命名为 'url' =&gt; 'pages/edit。我在这里的某个地方读到它可能是一个解决方案,但不是。
猜你喜欢
  • 2016-11-10
  • 2016-01-15
  • 2018-12-01
  • 2016-06-17
  • 1970-01-01
  • 2014-10-17
  • 2015-12-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多