I'm at a bit of a loss here. I have the following code:
// app/Post.php
<?php
namespace Korona;
use Illuminate\Database\Eloquent\Model;
use Cache;
class Post extends Model
{
use Traits\Commentable;
public function save(array $options = [])
{
Cache::forget('posts.' . $this->id);
return parent::save($options);
}
}
The trait is:
// app/Traits/Commentable.php
namespace Korona\Traits;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
trait Commentable
{
public function updateTouchedTimestamp()
{
$this->touched_at = Carbon::now();
$this->save(['timestamps' => false]);
}
}
Now, the $options array ('timestamps' => false) gets to the Post class alright. But when I output $options in Illuminate\Database\Eloquent\Model::save(), the array is empty. I don't know why the $options array gets lost on the way from Post's parent::save($options) to the base class's save($options) method.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire