Reputation: 3
I am trying to add a button which allows the user to remove a row of data for the database in laravel 5.2 application. This however is producing this error:
FatalErrorException in PageController.php line 53: Class 'App\Http\Controllers\Event' not found
I am not sure why this happens. Below is the code I have used to try and implement the method.
Page controller:
public function delete_event($id)
{ $event=Event::findOrFail($id);
$event->delete();
return redirect('events');
}
This is where I populate the table and create the buttons:
{!! Form::open(['url' => 'delete_event']) !!}
<div class="form-group">
<?php
foreach ($results as $row) {
echo "<tr><td>{$row->name}</td><td>{$row->description}</td><td>{$row->datetime}</td><td>{$row->location}</td><td><a href='/delete_event/{{$row->id}}' class='btn btn-success btn-danger'></a></td></tr>";
}
?>
</div>
This is my route:
Route::get('/delete_event/{id}', 'PageController@delete_event');
Upvotes: 0
Views: 912
Reputation: 5452
You need to import your model in your controller:
use App\Event;
Add that to the top above the class definition.
Upvotes: 1