2016-02-24 45 views
1

我是Laravel/Lumen和ORM的新人。 我已經得到了數據庫上此操作:更新後的雄辯retrive updated_at

$items = Item::where('id', $this->id) 
    ->where('is_shown', 1);  
    ->update([ 
      'is_shown' => 0, 
     ]); 

我怎麼可以檢索更新操作後updated_at列值,無需額外的查詢?

回答

0

只需使用

$items->updated_at; 

可以看到該對象的所有屬性與

dd($items); 

更新: 嘗試:更新

$items = Item::whereId($this->id)->whereIsShown(0)->get(); 
foreach($items as $item){ 
    dump($item); 
} 

+0

@mihai後()調用$項目是行數更新,而不是一個對象。我得到:'ErrorException:試圖獲取非對象的屬性' – user3396065

+0

更好和正確的方法來解決這個問題可以在這裏找到https://stackoverflow.com/questions/41625247/laravel-get-record-id-from -update-query你也可以在這裏查看https://stackoverflow.com/questions/43093965/return-collection-after-update –