PHP code example of cape-and-bay / draftable

1. Go to this page and download the library: Download cape-and-bay/draftable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cape-and-bay / draftable example snippets


use DraftableModel;
 $model->saveAsDraft() 

 $faker = Factory::create();
 $article = new Article();
 $article->title = $faker->paragraph(1);
 $article->content = $faker->paragraph;
 $article->saveAsDraft();

$article->saveWithDraft();

$article::setOwner($user);

 $draft_articles = Article::setOwner($user)->getAllDrafts();

$article->saveAsDraft();
$article->draft->setData('publish_date', Carbon::now()->addDay());
//you can get the data with this method
$article->draft->getData('publish_date');

 Model::getAllDrafts() 

 $drafts = Article::getAllDrafts();
 Model::getPublishedDraft() 

 $publishedDrafts = Article::getPublishedDraft();
 Model::getUnPublishedDraft() 

 $unpublished_draft_articles = Article::getUnPublishedDraft();

$draft_articles->publish();

# Publish all drafts
$draft_articles = Article::getUnPublishedDraft();
foreach($draft_articles as $draft_articles) {
    $draft_articles->publish();
}

$article->saveWithDraft();

$article = Article::first();
dump($article->drafts);

$draft->model()
#
$article_drafts[0]->model()
 $draft->restore() 

$article = Article::first();
$article_draft = $article->drafts()->first();
$article_draft->restore();
 php
php artisan migrate