【发布时间】: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 是否有效(执行相同/类似操作)?
-
出现错误后进入“页面/编辑”。这是迄今为止我唯一的更新方法,所有其他方法都有效,创建和视图。