,

In Laravel crud, when you’re deleting data from the table, it shows only the successfully deleted messages instead of deleting data from a table. How can we fix it?

Posted by

Laravel Crud Table

Whether you’re a beginner or learning Laravel from scratch and facing such kind of error in your Laravel crud, I have attached on the above image. When you have all inserted data at your crud table and you want to delete the particular record from the data table, when you click on the delete button but the selected record doesn’t delete from the data table. However, it shows a message like “data deleted successfully!” from the table without showing an error. so, you will first check the route and see, if you have mentioned or not the id with the delete option.

If everything will be same as it is then you will check the controller, again you’re unable to detect the error then you will apply the Log::info($wish); option on the delete function so, you will apply Log::info($wish); before where the delete function is not working and this way, you can easily detect the error where how much limit the delete function is passing or hampering and you will find the delete function that I have mentioned on the below code image:

 /**
     * Remove the specified resource from storage.
     *
     * @param  \App\wish  $wish
     * @return \Illuminate\Http\Response
     */
    public function destroy(wish $wish)
    {   
        Log::info($wish);
        $wish->delete();
  
        return redirect()->route('forms.main')
                        ->with('danger','Wish deleted successfully!');
    }
} 

So, you will look at your delete or destroy function whatever you have mentioned by the name of the function and detect that you have not mentioned the $id under the delete function then you will mention the public function destroy(wish $wish,$id) and give a correct path to the $id that I have mentioned below the code function image:

/**
     * Remove the specified resource from storage.
     *
     * @param  \App\wish  $wish
     * @return \Illuminate\Http\Response
     */
    public function destroy(wish $wish,$id)
    {   
        $wish = wish::find($id);
        $wish->delete();
  
        return redirect()->route('forms.main')
                        ->with('danger','Wish deleted successfully!');
    }
} 

After applying $wish = wish::find($id); and correcting its path, you will refresh the page and again delete the particular record then it will successfully delete the record from the data table. it’s really worked for me and I’m sure, it will really work for you.

guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x