2016-04-15 132 views
0

我试图添加一个按钮,该按钮允许用户在laravel 5.2应用程序中删除数据库的一行数据。然而这是产生这个错误:使用laravel从表中删除一行

FatalErrorException in PageController.php line 53: Class 'App\Http\Controllers\Event' not found

我不知道为什么会发生这种情况。以下是我用来尝试和实施该方法的代码。

页控制器:

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}', '[email protected]_event'); 

回答

1

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

use App\Event; 

是添加到上面的顶类定义。

+0

我有模型,但删除仍然不起作用。@ AngadDubey – Hannah

+0

@Hannah在PageController.php第53行:Class'App \ Http \ Controllers \ Event'找不到'的错误'是因为'FatalErrorException' “事件”模型没有被导入。错误是否改变了? –

+0

实际上它现在是“RouteCollection.php 219行中的MethodNotAllowedHttpException:” – Hannah