user(); if ($user === null || $user->hasPermission('admin/posts') === false) { $builder ->where('publish_at', '<=', now()); } } /** * Return if the current model is visible. * * @param Model $model The model. * @return boolean Allow model to be visible. */ public static function viewable(Model $model) { if (Carbon::parse($model->publish_at)->isFuture() === true) { $user = auth()->user(); if ($user === null || $user->hasPermission('admin/posts') === false) { return false; } } return true; } /** * Return if the current model is creatable. * * @return boolean Allow creating model. */ public static function creatable() { $user = auth()->user(); return ($user !== null && $user->hasPermission('admin/posts') === true); } /** * Return if the current model is updatable. * * @param Model $model The model. * @return boolean Allow updating model. */ public static function updatable(Model $model) { $user = auth()->user(); return ($user !== null && $user->hasPermission('admin/posts') === true); } /** * Return if the current model is destroyable. * * @param Model $model The model. * @return boolean Allow deleting model. */ public static function destroyable(Model $model) { $user = auth()->user(); return ($user !== null && $user->hasPermission('admin/posts') === true); } /** * Transform the model * * @param Model $model The model to transform. * @return array The transformed model. * @throws InvalidCastException Cannot cast item to model. */ public function transform(Model $model) { $result = $model->toArray(); $result['attachments'] = $model->attachments()->get()->map(function ($attachment) { return MediaConductor::model(request(), $attachment->media); }); return $result; } }