PHP code example of bmatovu / laravel-publishable

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

    

bmatovu / laravel-publishable example snippets




use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePostsTable extends Migration
{
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            // ...
            $table->timestamp('published_at')->nullable();
        });
    }
}



namespace App\Models;

use Bmatovu\Publishable\Publishable;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use Publishable;
}

$publishedPosts = Post::get();

$publishedPosts = Post::onlyPublished()->get();

$posts = Posts::withDrafts()->get();

$drafts = Posts::onlyDrafts()->get();

if ($post->isPublished()) {
    // ...
}

// Publishing a single model instance...
$post->publish();

// Publishing all related models...
$post->inLifeStyle()->publish();

$post->unpublish();