简体   繁体   中英

Laravel Destroy() is not removing any record from DB

Database Image

This is my controller's index method. When i run the code it does nothing.

public function index()
{
  Customer::destroy(1);
  return view('customer');
}

Model:

<?php namespace App;

use Illuminate\Database\Eloquent\Model;

class Customer extends Model {
protected  $guarded = [];
public  $timestamps=false;
}

Try using delete instead of destroy like this:

Customer::findOrFail(1)->delete();

or you can try directly from database using eloquent query builder:

Customer::where('id', 1)->delete();

You can also write your code like this

public function getDeleteTag($id)
    {

        DB::table('tags')
            ->where('id','=',$id)
            ->delete();

    return Response::json(['message' => 'Tag has been deleted successfully!']);

    }

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM