php - 尝试更新时 Handler.php 中的 NotFoundHttpException

标签 php html laravel http

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

它给我这个错误:

Handler.php 第 103 行中的 NotFoundHttpException: 没有模型 [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]+');

资源 Controller

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>

        ...

路线列表 routelist

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

最佳答案

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

关于php - 尝试更新时 Handler.php 中的 NotFoundHttpException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38427931/

相关文章:

c# - 如何从 WebBrowser 控件获取 HTML

php - 将用户的时区应用于 Laravel 中的模型属性

php - 流或文件 "/storage/logs/laravel.log"无法打开 : failed to open stream: Permission denied

php - UTF-8贯穿始终

php - 拉维尔 |编辑页面上的复选框状态

javascript - 动画不适用于所有 anchor 标记

php - 如何使用 laravel 将表单中的数据发布到数据库中?

php - 图像未从 php 插入到 mysql 数据库

php - 基于两个下拉菜单显示数据库结果

javascript - 具有绝对定位子 div 的父 div 拒绝为 100% 高度