php - Retriving old values with many-to-many association -
i use old
function @ view files retrieve old values when editing entity. example:
{!! form::model($shop, [ 'action' => ['shopcontroller@update', $shop->id], 'method' => 'patch']) !!} {!! form::text('name', old('name')) !!} {!! form::submit('save', array('class' => 'btn')) !!} {!! form::close() !!}
this works fine simple fields, not seem work 'many many' (belongstomany) relations. supposing relation of kind results in array of objects, how can retrieve them in view without generating lot of code?
i thinking this, in multiselect, shop has many-to-many relation products:
{!! form::select('products[]', $allproducts, old('products[]')) !!}
this not seem work because there no products
in model, through relation model like: shopproduct
.
anyone know clever way this?
Comments
Post a Comment