2016-08-14 93 views
0

正在開發一個涉及將視頻文件從MPEG轉換爲WEBM的新項目。我的問題是,在轉換過程中,我試圖更新我的Video模型屬性,但出於某種原因,我無法修改某些屬性。Laravel 5.2模型屬性不變

例如,我可以修改視頻模式的name,但我不能修改streampathconverted領域

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; 
} 

任何幫助將不勝感激

+0

你回來'$ this'你'轉換()'方法結束,但你實際上'保存()''荷蘭國際集團的模式?另外,你有兩個名爲'$ streampath'和'$ converted'的公共屬性,爲什麼存在?如果最終保存模型,這些更改將不會出現在數據庫中,因爲它們在類本身上的實際屬性。 '$ fillable'數組只能決定是否可以填充**模型屬性**,而不是公共屬性。我會大力推薦閱讀模型:https://laravel.com/docs/5.2/eloquent –

+0

我在控制器中,但問題似乎不是數據庫正在更新 - 當我登錄模型時,那些字段沒有設置 –

+0

@SteveBauman刪除這些公共屬性似乎已經訣竅 - 不記得爲什麼添加這些,肯定是錯誤的。 –

回答

0

試試這個。更改
$this->property

$this->attributes['property']

+0

沒有。對我的問題的評論修正了它 –