Laravel 5.2模型属性不变
问题描述:
正在开发一个涉及将视频文件从MPEG转换为WEBM的新项目。我的问题是,在转换过程中,我试图更新我的Video
模型属性,但出于某种原因,我无法修改某些属性。Laravel 5.2模型属性不变
例如,我可以修改视频模式的name
,但我不能修改streampath
或converted
领域
class Video extends Model
{
//
public $streampath;
public $converted;
protected $fillable = ['streampath', 'converted'];
/**
* Video constructor.
* @param array $path
*/
public function __construct($path=null)
{
parent::__construct();
if($path) {
$this->path = $path;
}
}
....
这里的转换方法:
public function convert() {
$uniqueId = $this->id;
$tempPath = $this->path;
$outputFileName = Carbon::now()->format('Ymdhis') . '.webm';
$outputPath = 'videos/' . $outputFileName;
$this->setConverted(ConvertStatusEnum::CONVERTING);
// Run the converter
$this->name = 'MY NEW TEST';
$this->setStreampath($outputFileName);
$this->setConverted(ConvertStatusEnum::CONVERTED);
Log::debug($this);
return $this;
}
而这里的这两个属性的设置:
public function setStreampath($streampath)
{
$this->streampath = $streampath;
}
public function setConverted($converted)
{
$this->converted = $converted;
}
任何帮助将不胜感激
答
试试这个。更改$this->property
要$this->attributes['property']
+0
没有。对我的问题的评论修正了它 –
你回来'$ this'你'转换()'方法结束,但你实际上'保存()''荷兰国际集团的模式?另外,你有两个名为'$ streampath'和'$ converted'的公共属性,为什么存在?如果最终保存模型,这些更改将不会出现在数据库中,因为它们在类本身上的实际属性。 '$ fillable'数组只能决定是否可以填充**模型属性**,而不是公共属性。我会大力推荐阅读模型:https://laravel.com/docs/5.2/eloquent –
我在控制器中,但问题似乎不是数据库正在更新 - 当我登录模型时,那些字段没有设置 –
@SteveBauman删除这些公共属性似乎已经诀窍 - 不记得为什么添加这些,肯定是错误的。 –