PHP code example of laravel-creative / draftable

1. Go to this page and download the library: Download laravel-creative/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/ */

    

laravel-creative / draftable example snippets


use DraftableModel;
 $model->saveAsDraft() 

$article->saveWithDraft();

$article::setUser($user);

 $draftsArticles=Article::setUser($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() 

 $unPublishedDrafts=Article::getUnPublishedDraft();
   $draftsArticle->publish(); 
 
  $draftsArticles=Article::getUnPublishedDraft();
  foreach($draftsArticles as $draftsArticle)
  {
   $draftsArticle->publish();
  }

$article->saveWithDraft();

$article = Article::first();
$articleDrafts=$article->drafts;
 $draft->model() 

$articleDrafts[0]->model()
 $draft->restore() 

$article = Article::first();
$articleDraft=$article->drafts()->first();
$articleDraft->restore();
 php
php artisan migrate
 php
 $faker = Factory::create();
 $article=new Article();
 $article->title=$faker->paragraph(1);
 $article->content=$faker->paragraph;
 $article->saveAsDraft();