【发布时间】:2014-08-29 12:38:48
【问题描述】:
我遇到的问题是我想保存模型,但我有一个写入实例的方法调用,并且由于某种原因 Laravel 正在尝试更新 那个 列。
俱乐部模式(相关代码):
use Illuminate\Database\Eloquent\SoftDeletingTrait;
class Club extends Eloquent
{
use SoftDeletingTrait;
protected $table = 'clubs';
protected $fillable = array('name', 'address', 'city', 'state', 'zip', 'contact_name', 'contact_email', 'contact_phone', 'contact_photo', 'club_code', 'logo');
public function getCurrentCampaign($id = 0)
{
if (!$id)
{
if ($this->currentCampaign)
{
return $this->currentCampaign;
}
$id = $this->id;
}
$now = date('Y-m-d H:i:s');
$this->currentCampaign = DB::table('campaigns')
->where('club_id', $id)
->where('start_date', '<=', $now)
->where('end_date', '>=', $now)
->pluck('id');
return $this->currentCampaign;
}
}
问题存在于“俱乐部设置”页面上,用户可以在其中编辑一些内容 - 我有一些更新在不同的表上运行,然后我使用 $club->save()。我发现即使在getCurrentCampaign之后直接调用它也会抛出错误。
$club = Club::findOrFail($clubID);
$club->getCurrentCampaign();
$club->save(); // Error
错误信息:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'currentCampaign' in 'field list' (SQL: updateclubssetupdated_at= 2014-07-08 12:49:17,currentCampaign= 27 whereid= 23)
考虑到currentCampaign 不在$fillable 数组中,我不知道发生了什么。我是否误解了它的工作原理?
谢谢
编辑:为清楚起见,$club 中加载了一些不同的内容,而不仅仅是广告系列。我只是提供一个用于说明目的。
【问题讨论】:
标签: php orm model laravel-4 eloquent