you are trying to use implicit route model binding.
have you told laravel to use the slug field and not the id field?
https://laravel.com/docs/5.4/routing#route-model-binding
see Customizing the key name
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
hi friends, I have a problem with the update method of my administration panel;
Instead of updating the data of the current products, this what it does is create new ones and it will not let me delete them later (neither the updated ones nor the previous ones).
It is as if he created clones that can not be erased, but with the variation of only one. I do not know if I can explain ...
productscontroller
public function update(SaveProductRequest $request, Products $products)
{
$products->fill($request->all());
$products->slug = str_slug($request->get('name'));
$products->visible = $request->has('visible') ? 1 : 0;
$updated = $products->save();
$message = $updated ? 'Producto actualizado correctamente!' : 'El Producto NO pudo actualizarse!';
return redirect()->route('products.index')->with('message', $message);
}
public function destroy(Products $products)
{
$deleted = $products->delete();
$message = $deleted ? 'Producto eliminado correctamente!' : 'El producto NO pudo eliminarse!';
return redirect()->route('admin.products.index')->with('message', $message);
}
web.php
Route::post('products/{products}', [
'as' => 'admin.products.update',
'uses' => 'ProductController@update'
]);
Route::delete('products/destroy/{products}', [
'as' => 'admin.products.destroy',
'uses' => 'ProductController@destroy'
]);
form
{!! Form::model($products, array('route' => array('products.update', $products->slug))) !!}
<input type="hidden" name="_method" value="PUT">
<div class="form-group">
<label class="control-label" for="category_id">Categoría</label>
{!! Form::select('category_id', $categories, null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
<label for="name">Nombre:</label>
{!!
Form::text(
'name',
$products->name,
array(
'class'=>'form-control',
'placeholder' => 'Ingresa el nombre...',
'autofocus' => 'autofocus'
)
)
!!}
</div>
<div class="form-group">
<label for="extract">Extracto:</label>
{!!
Form::text(
'extract',
$products->extract,
array(
'class'=>'form-control',
'placeholder' => 'Ingresa el extracto...',
)
)
!!}
</div>
<div class="form-group">
<label for="description">Descripción:</label>
{!!
Form::textarea(
'description',
$products->description,
array(
'class'=>'form-control'
)
)
!!}
</div>
<div class="form-group">
<label for="price">Precio:</label>
{!!
Form::text(
'price',
$products->price,
array(
'class'=>'form-control',
'placeholder' => 'Ingresa el precio...',
)
)
!!}
</div>
<div class="form-group">
<label for="image">Imagen:</label>
{!!
Form::text(
'image',
$products->image,
array(
'class'=>'form-control',
'placeholder' => 'Ingresa la url de la imagen...',
)
)
!!}
</div>
<div class="form-group">
<label for="visible">Visible:</label>
<input type="checkbox" name="visible" {{ $products->visible == 1 ? "checked='checked'" : '' }}>
</div>
<div class="form-group">
{!! Form::submit('Actualizar', array('class'=>'btn btn-primary')) !!}
<a href="{{ route('products.index') }}" class="btn btn-warning">Cancelar</a>
</div>
{!! Form::close() !!}
edit; i cant delete any product
also... if you have hidden field method type of PUT then you need to use put in your web.php and not post
Please or to participate in this conversation.