Answer the question
In order to leave comments, you need to log in
How to update laravel base record?
Please help me understand how to update the record in the database.
I started studying the framework, I read manuals for a week - my head swells already, so the banal READ DOCKS is not suitable :)
I made a primitive admin panel:
the form for adding a record
deleting a record
somehow I need to edit a record now
I just can’t figure out how to do it
the form itself into which a record is submitted for editing
<div class="col-md-6 col-md-offset-3">
{!! Form::open([
'route'=>'admin.abouts.store', // роут здесь неправильный понятно, пытаюсь ставить апдейт вместо сторе ошибка что пропущен параметр. Я понимаю что нужно айди элемента передать, но не пойму как это сделать
'files' => true
]) !!}
<div class="form-group">
{!! Form::label('description', 'Описание') !!}
{!! Form::text('description', $item->description, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
<img src="{{$item->icon}}" alt="">
</div>
<div class="form-group">
{!! Form::label('icon', 'Картинка') !!}
{{ Form::file('image') }}
</div>
<div class="form-group">
{!! Form::submit('Добавить') !!}
</div>
{!! Form::close() !!}
</div>
| | POST | admin/abouts | admin.abouts.store | App\Http\Controllers\[email protected] | web,auth |
| | GET|HEAD | admin/abouts | admin.abouts.index | App\Http\Controllers\[email protected] | web,auth |
| | GET|HEAD | admin/abouts/create | admin.abouts.create | App\Http\Controllers\[email protected] | web,auth |
| | GET|HEAD | admin/abouts/{abouts} | admin.abouts.show | App\Http\Controllers\[email protected] | web,auth |
| | DELETE | admin/abouts/{abouts} | admin.abouts.destroy | App\Http\Controllers\[email protected] | web,auth |
| | PUT|PATCH | admin/abouts/{abouts} | admin.abouts.update | App\Http\Controllers\[email protected] | web,auth |
| | GET|HEAD | admin/abouts/{abouts}/edit | admin.abouts.edit | App\Http\Controllers\[email protected] | web,auth
Answer the question
In order to leave comments, you need to log in
{!! Form::open([
'route' => ['admin.abouts.update', $item->id],
'method' => 'PUT',
'files' => true,
'role' => 'form', // ;)
]) !!}
[email protected]
can do something like this in the controller:$item = About::findOrFail($id)->update($request->all()); // Вернет true или false
// Если используете пакет laracasts/flash то еще можно дополнить код так:
flash()->success('The model has been updated!');
return redirect()->back();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question