Laravel Angular CRUD (06) :: Delete record by angular js in laravel 5

In the last episode, I have discussed how to edit a record. In this episode, I’ll show you how to delete a record by angular js without page refresh.Let’s see the procedure.

You can read previous posts

You can find this project in my Github repository Laravel Angular CURD

First define the destroy method in TodoController.php file like as below

public function destroy($id)
  $data = ['success' => true, 'msg' => 'delete successfully'];
  return Response::json($data, 200);

Now in our todo-controller.js file let’s add a delete function to perform the delete record operation. This method sends a delete request to our TodoController@destroy method and gets a response. After getting the response we recall the init() function to bind the data.

// DELETE request to todos/{id}
$scope.delete = function (id) {
  if (confirm('Are you sure?')) {
    $http.delete(SERVICEURL + '/todos/' + id + '')
       .success(function (data) {

At last call the delete function in index.blade.php view inside the ng-repeat loop.

<a class="btn btn-danger btn-xs" href="#">Delete</a>

Finished our CRUD system. If your are followed all episode attentively I think it’ll be easier to do this CRUD system in your next laravel project with angular js. From 1-6 episode, I have tagged as 1.0 in my GitHub repository.In next episode, I’ll customize the view controller js for better user experience.

Share on :

Leave a Reply

3 × = twenty four