【发布时间】:2015-04-25 17:01:29
【问题描述】:
我的模型是:
<?php namespace App\Http\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Province extends Model {
// use SoftDeletes;
public $timestamps = false;
protected $dates = ['deleted_at'];
public function country(){
return $this->belongsTo('App\Http\Models\Country');
}
public function users(){
return $this->hasMany('App\Http\Models\User');
}
public function customers(){
return $this->hasMany('App\Http\Models\Customer');
}
}
控制器:
public function destroy($id)
{
$province = Province::with('country')->where('id', $id)->first();
// dd($province);
$province->delete();
}
拨打http://localhost:8080/pal/public/province/22/delete时。
记录 22 从数据库中物理删除。
缺少什么?
【问题讨论】:
-
你已经注释掉了
use SoftDeletes -
因为在未注释时我收到此错误:调用非对象上的成员函数 delete()
-
是的,可能是因为它已经被软删除并且
first()返回null -
我怎么知道它是否被软删除它的 delete_at = 4/25/2015 11:44:48 AM
-
然后是软删除。手动将值设置为
null以“取消删除”
标签: laravel laravel-4 laravel-5