/** * Get a status by id. * @param $id * @return null */ public static function getStatusById($id) { try { $status = Status::where('id', $id)->firstOrFail(); return $status; } catch (Exception $e) { return null; } }
private static function seed() { $statuses = ['draft', 'published', 'hidden']; foreach ($statuses as $status) { if (!Status::exists($status)) { Status::create(['name' => $status]); } } return true; }
/** * Get posts with a status of 'published' * @param $query * @return mixed */ public function scopePublished($query) { $status = Status::getStatusByName('published'); return $query->where('status_id', $status->id); }