我正在尝试使用 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>
...
我一直在这个错误和 MethodNowAllowed
错误之间徘徊,因为它现在大约 3-4 天不喜欢 PUT/PATCH 方法。任何帮助都会很棒!
最佳答案
你在 edit.blade.php 中有一个拼写错误, 'action' => 'ResourceController@update'
关于php - 尝试更新时 Handler.php 中的 NotFoundHttpException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38427931/