How to delete a single record in Laravel 5

0 votes

Using Laravel 5 I m trying to delete a single record within a controller, here is my code:

public function destroy($id)
{
     $employee = Employee::find($id);
     $employee->delete();
     return Redirect::route('noorsi.employee.index');
}

My view page code is:

<td><a href="employee/{{$employee->id}}/destroy" class="btn btn-default">Delete</a></td>

My route is:

Route::delete(employee.'/{id}', array('as' => 'noorsi.employee.destroy','uses' => Employeecontroller.'@destroy'));

That did not work.

How do I fix the implementation ?

Dec 2, 2020 in Laravel by kartik
• 37,520 points
1,949 views

1 answer to this question.

0 votes

Hello @kartik,

Delete an existing Model

$user = User::find(1);
$user->delete();

Deleting An Existing Model By Key

User::destroy(1);
User::destroy([1, 2, 3]);
User::destroy(1, 2, 3);

In every cases, the number between brackets represents the object ID, but you may also run a delete query on a set of models:

$affectedRows = User::where('votes', '>', 100)->delete();
answered Dec 2, 2020 by Niroj
• 82,840 points

Related Questions In Laravel

0 votes
1 answer

How to call a controller function inside a view in laravel 5

Hello @kartik, Just try this in your view ...READ MORE

answered Sep 25, 2020 in Laravel by Niroj
• 82,840 points
8,404 views
0 votes
1 answer

How to mock a static facade methods in Laravel?

Hey, Facades provide a "static" interface to classes ...READ MORE

answered Mar 19, 2020 in Laravel by Niroj
• 82,840 points
6,519 views
0 votes
2 answers

How to delete or clear caching in Laravel?

You can call an Artisan command outside ...READ MORE

answered Dec 16, 2020 in Laravel by Rajiv
• 8,910 points
95,484 views
0 votes
1 answer

How can we create a record in Laravel using eloquent?

We need to create a new model ...READ MORE

answered Mar 20, 2020 in Laravel by Niroj
• 82,840 points
1,199 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
22,972 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
2,973 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,902 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,427 views
+1 vote
1 answer

How to check if a record already exists in a laravel?

Hey, As a newbie it is most common ...READ MORE

answered Mar 31, 2020 in Laravel by Niroj
• 82,840 points
32,660 views
0 votes
1 answer

How to update a pivot table using Eloquent in laravel 5?

Hello @kartik, The code below solved my problem: $messages ...READ MORE

answered Sep 24, 2020 in Laravel by Niroj
• 82,840 points
4,334 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP