06.10.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Eloquent: Mutators 610<br />

13 */<br />

14 protected $dates = ['created_at', 'updated_at', 'deleted_at'];<br />

15 }<br />

When a column is considered a date, you may set its value to a UNIX timestamp, date string (Y-m-d),<br />

date-time string, and of course a DateTime / Carbon instance, and the date’s value will automatically<br />

be correctly stored in your database:<br />

1 $user = App\User::find(1);<br />

2<br />

3 $user->deleted_at = Carbon::now();<br />

4<br />

5 $user->save();<br />

As noted above, when retrieving attributes that are listed in your $dates property, they will<br />

automatically be cast to Carbon²²² instances, allowing you to use any of Carbon’s methods on your<br />

attributes:<br />

1 $user = App\User::find(1);<br />

2<br />

3 return $user->deleted_at->getTimestamp();<br />

By default, timestamps are formatted as 'Y-m-d H:i:s'. If you need to customize the timestamp<br />

format, set the $dateFormat property on your model. This property determines how date attributes<br />

are stored in the database, as well as their format when the model is serialized to an array or JSON:<br />

1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!