/** * @param boolean checks that the user is an admin, returns false if not. Automatically sets the closing time to be one week out from now. */ public function setActiveAttribute($value) { if (!Auth::user()->can('administrate-background_images')) { return false; } $this->attributes['active'] = $value; if ($value) { //Setting it active $last = BackgroundImage::whereNotNull('display_date')->active()->orderBy('display_date', 'desc')->first(); if (!$last) { $last = Carbon::yesterday(); } else { $last = $last->display_date; } $this->attributes['display_date'] = $last->add(new \DateInterval('P1D'))->format('Y-m-d'); } else { //Setting it inactive $this->attributes['display_date'] = null; } return true; }