PHP code example of pawelmysior / laravel-publishable

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

    

pawelmysior / laravel-publishable example snippets


$table->timestamp('published_at')->nullable();


 
namespace App;
  
use Illuminate\Database\Eloquent\Model;
use PawelMysior\Publishable\Publishable;
 
class Post extends Model
{
    use Publishable;
}

// Get only published posts
Post::published()->get();
 
// Get only unpublished posts
Post::unpublished()->get();
 
// Check if the post is published
$post->isPublished();
 
// Check if the post is unpublished
$post->isUnpublished();
 
// Publish the post
$post->publish();
 
// Unpublish the post
$post->unpublish();

// Publish the post without firing model events
$post->publishQuietly();
 
// Unpublish the post without firing model events
$post->unpublishQuietly();