Alright so, for my school project I have to delete a container out of my database. I’ve made forms before that would delete rows but this time i’m running into a error that I cannot resolve.
I’ve gone through many posts on multiple forums but at this point I’m raging non stop cuz there seems to be no fix
Error: Property [ID] does not exist on this collection instance.
index.blade.php ->
<form action="{{ route('container.destroy',$container->ID) }}" action="POST">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<button type="submit" title="Delete Post">Delete</button>
</form>
web.php ->
Route::resource('container',AppHttpControllerscontainerController::class);
containerController.php ->
public function index(Request $request)
{
$container = Container::all();
return view('container.index')->with('container',$container);
}
public function destroy($id)
{
$container = Container::find($id);
$container->delete();
return redirect('container')->with('status', 'Container is Opgehaald');
}
The model is Container and has the following tables:
ID
ContainerPortal
PlaatsAvailable
Herkomst
Bestemming
VervoerderAankomst
VervoerderVertrek
OphaalDatum
Move0
Move1
Move2
Move3
Move4
Move5
updated_at
created_at
index.blade.php:
@extends('layouts.app')
@section('content')
<h3 class="text-center p-4 fontOne">Alle Containers</h3>
<a href="/run" class="btn btn-outline-success btn-block p-3 fontOne" style="margin: 0 auto; display:block;">Voeg Extra Container toe</a>
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Container</th>
<th scope="col">Portal</th>
<th scope="col">Herkomst</th>
<th scope="col">Bestemming</th>
<th scope="col">Ophaal Datum</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody>
@if(!$containers)
<p>Kon geen containers vinden</p>
@else
@foreach($containers as $container)
<tr>
<th scope="col">Container: {{$container->ID}}</th>
<td>Container Portal: {{$container->ContainerPortal}}</td>
<td>Herkomst: {{$container->Herkomst}}</td>
<td>Bestemming: {{$container->Bestemming}}</td>
<td>Ophaal Datum: {{$container->OphaalDatum}}</td>
<td>
<form action="{{ route('container.destroy',$container->ID) }}" action="POST">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<button type="submit" title="Delete Post">Delete</button>
</form>
</td>
</tr>
@endforeach
@endif
</tbody>
</table>
@endsection
Tried multiple solutions from stack overflow and other forums, I’m working with the most updated Laravel so I don’t know what the issue could be
Update
After using my brain properly I saw a typo in the form, it was action="POST" instead of method="POST"
2
Answers
in your web.php not need define this line:
for solve problem need to pass container to your blade, for this you should write this code in your
containerController
actionedit
/show
(which one use in your project):in your blade change form like bellow:
and i think everything work very well.
also for getting more information, can read laravel document
Resource Controllers
and for view defined route run this command
You are passing $container in index function, not $containers…
change like below :