{"id":33945181,"url":"https://github.com/optixsolutions/eloquent-draftable","last_synced_at":"2026-04-08T19:31:23.077Z","repository":{"id":45978387,"uuid":"133484703","full_name":"optixsolutions/eloquent-draftable","owner":"optixsolutions","description":"Add draftable functionality to your eloquent models","archived":false,"fork":false,"pushed_at":"2023-01-17T17:30:05.000Z","size":40,"stargazers_count":28,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-02T12:11:12.186Z","etag":null,"topics":["draft","eloquent","laravel","publish","schedule"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/optixsolutions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-15T08:25:48.000Z","updated_at":"2025-09-22T18:05:06.000Z","dependencies_parsed_at":"2023-02-10T11:01:01.497Z","dependency_job_id":null,"html_url":"https://github.com/optixsolutions/eloquent-draftable","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/optixsolutions/eloquent-draftable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optixsolutions%2Feloquent-draftable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optixsolutions%2Feloquent-draftable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optixsolutions%2Feloquent-draftable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optixsolutions%2Feloquent-draftable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/optixsolutions","download_url":"https://codeload.github.com/optixsolutions/eloquent-draftable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optixsolutions%2Feloquent-draftable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31571599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["draft","eloquent","laravel","publish","schedule"],"created_at":"2025-12-12T17:39:39.662Z","updated_at":"2026-04-08T19:31:23.070Z","avatar_url":"https://github.com/optixsolutions.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Eloquent Draftable\n\n![Packagist Version](https://img.shields.io/packagist/v/optix/eloquent-draftable)\n![GitHub Workflow Status](https://img.shields.io/github/workflow/status/optixsolutions/eloquent-draftable/Run%20tests)\n![StyleCI](https://styleci.io/repos/133484703/shield)\n\nAdd draftable functionality to your eloquent models.\n\n## Installation\n\nYou can install this package via composer.\n\n```bash\ncomposer require optix/eloquent-draftable\n```\n\n## Setup\n\n1. Add a nullable timestamp `published_at` column to your model's database table.\n\n    ```php\n    $table-\u003etimestamp('published_at')-\u003enullable();\n    ```\n\n2. Include the `Optix\\Draftable\\Draftable` trait in your model.\n\n    ```php\n    class Post extends Model\n    {\n        use Draftable;\n    }\n    ```\n\n## Usage\n\n**Query scopes**\n\nWhen the `Draftable` trait is included in a model, a global scope will be registered to automatically exclude\ndraft records from query results. Therefore, in order to query draft records you must apply one of the local\nscopes outlined below.\n\n```php\n// Only retrieve published records...\n$onlyPublished = Post::all();\n\n// Retrieve draft \u0026 published records...\n$withDrafts = Post::withDrafts()-\u003eget();\n\n// Only retrieve draft records...\n$onlyDrafts = Post::onlyDrafts()-\u003eget();\n```\n\n**Publish a model**\n\n```php\n$post = Post::withDrafts()-\u003efirst();\n\n// Publish without saving...\n$post-\u003esetPublished(true);\n\n// Publish and save...\n$post-\u003epublish(); // or $post-\u003epublish(true);\n```\n\nWhen you attempt to publish a model that's already been published, the `published_at` timestamp will not be updated.\n\n**Draft a model**\n\n```php\n// Draft without saving...\n$post-\u003esetPublished(false);\n\n// Draft and save...\n$post-\u003edraft(); // or $post-\u003epublish(false);\n```\n\n**Schedule a model to be published**\n\n```php\n$publishDate = Carbon::now()-\u003eaddWeek();\n// $publishDate = '2020-01-01 00:00:00';\n// $publishDate = '+1 week';\n\n// Schedule without saving...\n$post-\u003esetPublishedAt($publishDate);\n\n// Schedule and save...\n$post-\u003epublishAt($publishDate);\n```\n\nThe methods outlined above both require a `$date` parameter of type `DateTimeInterface|string|null`.\n\n**Get the published status of a model**\n\n```php\n// Determine if the model is published...\n$post-\u003eisPublished();\n\n// Determine if the model is draft...\n$post-\u003eisDraft();\n```\n\n## License\n\nThis package is licensed under the [MIT license](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foptixsolutions%2Feloquent-draftable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foptixsolutions%2Feloquent-draftable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foptixsolutions%2Feloquent-draftable/lists"}