PHP code example of novius / laravel-publishable

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

    

novius / laravel-publishable example snippets


Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->string('title');
    $table->text('text');
    $table->timestamps();
    $table->publishable(); // Macro provided by the package
});

namespace App\Models;

use \Illuminate\Database\Eloquent\Model;
use \Novius\LaravelPublishable\Publishable;

class Post extends Model {
    use Publishable;
    ...
}

$post = Post::first();
$post->isPublished();

$postsPublished = Post::all();
$postsPublished = Post::query()->published();
$onlyNotPublishedPosts = Post::query()->notPublished();
$onlyDraftedPosts = Post::query()->onlyDrafted();
$onlyExpiredPosts = Post::query()->onlyExpired();
$onlyWillBePublishedPosts = Post::query()->onlyWillBePublished();
bash
php artisan vendor:publish --provider="Novius\Publishable\LaravelPublishableServiceProvider" --tag=lang