如何正确列出已删除的事件?

时间:2015-10-18 13:00:26

标签: laravel-4 laravel-5 eloquent laravel-5.1

我有import numpy as np import ctypes from ctypes import CDLL, POINTER, c_int, byref, c_char, c_double import sys from numpy.core import array, asarray, zeros, empty, transpose, \ intc, single, double, csingle, cdouble, inexact, complexfloating, \ newaxis, ravel, all, Inf, dot, add, multiply, identity, sqrt, \ maximum, flatnonzero, diagonal, arange, fastCopyAndTranspose, sum, \ isfinite, size libs = ["libLAPACK.dylib","libmkl_rt.so","libmkl_intel_lp64.so","liblapack.so"] lib = None for l in libs: try: lib = CDLL(l) print "Loaded " + l + " for dgesvd" break except OSError: pass if lib==None: raise OSError, "Couldn't find lapack library for GESVD patch" 我需要删除的记录,但我还需要从数据透视表中删除他们的Model,所以我尝试列出已删除的事件,但它没有工作

以下是我添加活动的方式:

id

我在<?php namespace App; use Illuminate\Database\Eloquent\Model; class Criteria extends Model { protected $table = 'criterias'; public static function boot() { parent::boot(); static::deleted(function($criteria) { DB::table('criteria_criteria')->where('criteria_id', '=', $criteria->id)->delete(); }); } } ,知道怎么做?

1 个答案:

答案 0 :(得分:0)

我认为你没有使用它的关系。请使用您的数据透视表创建一个relationship

public function criteria()
{
    return $this->belongsToMany('App\Criteria');
}

这将自动管理数据透视表上的删除查询。它还有一个好处,您可以使用其syncdetach方法添加和删除数据透视表记录。

有关详细信息,您可以通过搜索关键字pivot阅读此tutorial