当我尝试将数据传递到编辑页面时,我收到了此错误。请帮助我
Connection.php第729行中的QueryException:
SQLSTATE [42S22]:未找到列:1054'字段列表'中的未知列'1'(SQL:从1
选择phonebooks
)
PhonebookController.php
public function edit($id)
{
$data = Phonebooks::all($id);
echo"$data";
return view('phonebook.edit', compact('$data'));
}
edit.blade.php
<html>
<body>
<form method="POST" action="{{ URL::to('phonebook') }}" >
<input type="text" name="id" value="{{$id}}"/>
<input type="text" name="phoneNo" value="{{old('phoneNo')}}"/>
<input type="text" name="email" value="{{old('email')}}" />
<input type="submit" value="Save"/>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
</body>
</html>
答案 0 :(得分:2)
你应该试试这个:
public function edit($id)
{
$data = Phonebooks::find($id);
return view('phonebook.edit', compact('data'));
}
<html>
<body>
<form method="POST" action="{{ URL::to('phonebook') }}" >
<input type="text" name="id" value="{{$data->id}}"/>
<input type="text" name="phoneNo" value="{{old('phoneNo')}}"/>
<input type="text" name="email" value="{{old('email')}}" />
<input type="submit" value="Save"/>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
</body>
</html>
答案 1 :(得分:0)
public function edit($id)
{
$data = Phonebooks::find($id);
return view('phonebook.edit', compact('data'));
}
If you use Laravel Form Model then not required to pass any hidden data and assign individual values. Below is link how you can use Form model. Even not require passing CSRF token on hidden.
{!! Form::model($post, ['method' => 'PATCH','url' => ['/admin/posts',$post->id], ]) !!}
{!! Form::text('phoneNo', null, ['class' => 'form-control']) !!}
{!! Form::email('email', null, ['class' => 'form-control']) !!}
{!! Form::submit('Save', ['class' => 'btn btn-primary form-control']) !!}
希望这对你有帮助!