Illuminate\Database\Eloquent\Model::destroy PHP Method

destroy() public static method

Destroy the models for the given IDs.
public static destroy ( array | integer $ids ) : integer
$ids array | integer
return integer
    public static function destroy($ids)
    {
        // We'll initialize a count here so we will return the total number of deletes
        // for the operation. The developers can then check this number as a boolean
        // type value or get this total count of records deleted for logging, etc.
        $count = 0;
        $ids = is_array($ids) ? $ids : func_get_args();
        $instance = new static();
        // We will actually pull the models from the database table and call delete on
        // each of them individually so that their events get fired properly with a
        // correct set of attributes in case the developers wants to check these.
        $key = $instance->getKeyName();
        foreach ($instance->whereIn($key, $ids)->get() as $model) {
            if ($model->delete()) {
                $count++;
            }
        }
        return $count;
    }

Usage Example

Example #1
0
 /**
  * Delete a entity in modal by id.
  *
  * @param $id
  *
  * @return int
  */
 public function delete($id)
 {
     $id = $this->decrypt($id);
     $this->model->destroy($id);
     $this->resetModel();
     return $model->delete();
 }
All Usage Examples Of Illuminate\Database\Eloquent\Model::destroy
Model