I Verfahren folgende Ressourcensteuerung mit zerstören:Laravel 5.5-Controller @ DI destroy nicht Modell injizieren
public function destroy(ClinicImage $clinicImage)
{
$clinicImage->delete();
return redirect()->back()->with('success', 'Изображение удалено');
}
Auch habe ich Gitter mit folgenden Zeilen:
<td>
<div class="btn-group btn-group">
<button type="button" data-url="{{route('admin.clinic-image.destroy', [$clinic->id, $image->id])}}" class="btn btn-danger">
<i class="fa fa-remove fa-fw"></i>
</button>
</div>
</td>
Und schließlich habe ich Funktion Form auf die Schaltfläche klicken senden:
$('.table').find('.btn.btn-danger').click(function(){
var form = makeForm({_method: 'DELETE'},{action: $(this).data('url')});
form.submit();
});
function makeForm(data, options) {
var form = document.createElement('form');
form.method = 'POST';
var token = document.createElement('input');
token.name = '_token';
token.value = jQuery('meta[name="csrf-token"]').attr('content');
form.appendChild(token);
jQuery.each(data, function(key, value){
var input = document.createElement('input');
input.name = key;
input.value = value;
form.appendChild(input);
});
if(Object.keys(options).length) {
jQuery.each(options, function(option, value){
form[option] = value;
});
}
document.body.appendChild(form);
return form;
}
Wenn ich das senden Formular /admin/clinic/1/clinic-image/1
, ich fo llowing error: Type error: Argument 1 passed to App\Http\Controllers\Admin\ClinicImageController::destroy() must be an instance of App\ClinicImage, string given
Also meine Frage ist: Warum DI meine Route und Modell-ID nicht erkennen?
Sie senden zwei Parameter und expection nur ein, versuchen Sie dies: public function zerstören ($ Klinik, ClinicImage $ klinikImage) – Roots