无法删除 laravel 4.2 中的记录



伙计们,我正在尝试制作一个删除按钮来删除单个记录,我尝试了很多方法,但都失败了,所以如果你能帮助我,我将不胜感激。

拉维尔 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' => 'AdminOrdersController@destroy',
'as'   => 'admin.orders'
]);

错误:

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

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

路线:

Route::get('orders/delete/{id}',array
('as'=>'delete',
'uses'=>'AdminOrdersController@delete'));

添加到控制器用途

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>

相关内容

  • 没有找到相关文章

最新更新