Guys I'm trying to make a delete button to delete single record, I tried many ways but all fall, so if you can help me guys I'll appreciate it.
Laravel 4.2
here is the view code:
{{ Form::open(['method' => 'delete', 'route' => [ 'orders.destroy', $orders->id ]]) }}
{{ Form::hidden('id', $orders->id) }}
{{ Form::submit('Delete', ['class' => 'btn btn-danger']) }}
{{ Form::close() }}
Controller code:
public function destroy($id)
{
$orders = orders::findOrFail($id);
$orders->delete();
return Redirect::route('orders.index');
}
route:
Route::get('orders/delete', [
'uses' => 'Admin\OrdersController@destroy',
'as' => 'admin.orders'
]);
Error:
Undefined variable: orders (View:../app/views/orders/show.blade.php)
I've solve it, so here is my solution:
Route:
Route::get('orders/delete/{id}',array
('as'=>'delete',
'uses'=>'Admin\OrdersController@delete'));
Add to controller uses
use DB;
Controller:
public function delete($id)
{
DB::table('orders')->where('id',$id)->delete();
return Redirect::back()->withMessage('Record has been deleted');
}
Show Blade:
<a href="{{route('delete', array($order->id))}}" class="btn btn-danger">Delete</a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.