使用laravel从表中删除行


Deleting a row from a table using laravel

我正在尝试添加一个按钮,该按钮允许用户删除laravel 5.2应用程序中数据库的一行数据。然而,这会产生以下错误:

PageController.php第53行出现致命错误异常:未找到类"App''Http''Controllers''Event"

我不知道为什么会发生这种事。下面是我用来尝试和实现该方法的代码。

页面控制器:

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> 

这是我的路线:

Route::get('/delete_event/{id}', 'PageController@delete_event'); 

您需要在控制器中导入您的模型:

use App'Event;

将其添加到类定义上方的顶部。