在laravel 4.2中无法删除记录

时间:2017-05-14 19:11:24

标签: php html laravel-4

伙计我正在尝试删除单个记录的删除按钮,但是我尝试了很多方法,但是一切都失败了,所以如果你能帮助我们,我会很感激。

Laravel 4.2

这是视图代码:

 {{ Form::open(['method' => 'delete', 'route' => [ 'orders.destroy', $orders->id ]]) }}
 {{ Form::hidden('id', $orders->id) }}
 {{ Form::submit('Delete', ['class' => 'btn btn-danger']) }}
 {{ Form::close() }}

控制器代码:

public function destroy($id)
{
$orders = orders::findOrFail($id);
$orders->delete();
return Redirect::route('orders.index');
}   

路线:

Route::get('orders/delete', [
'uses' => 'Admin\OrdersController@destroy',
'as'   => 'admin.orders'
]);

错误:

Undefined variable: orders (View:../app/views/orders/show.blade.php)

1 个答案:

答案 0 :(得分:0)

我已经解决了,所以这是我的解决方案:

路线:

use DB;

添加到控制器使用

public function delete($id)
   {
    DB::table('orders')->where('id',$id)->delete();
    return Redirect::back()->withMessage('Record has been deleted');
   }

控制器:

<a href="{{route('delete', array($order->id))}}" class="btn btn-danger">Delete</a>

显示刀片:

if