A
A
Alexander2016-06-27 20:04:40
Laravel
Alexander, 2016-06-27 20:04:40

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>

Routes
|        | 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

The link localhost/admin/abouts/21/edit comes

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mokhirjon Naimov, 2016-06-27
@alexmixaylov

{!! Form::open([
    'route'  => ['admin.abouts.update', $item->id],
    'method' => 'PUT',
    'files'  =>  true,
    'role'   => 'form', // ;)
]) !!}

// Well, you [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();

A
Alexander, 2016-06-27
@alexmixaylov

Thanks again
, everything saves the fields normally, but the picture does not change the new one

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question