PHP code example of lambdadigamma / laravel-publishable

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

    

lambdadigamma / laravel-publishable example snippets


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

namespace App\Models;

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

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

$post = Post::first();
$post->publish();
$post->publishAt(now()->addHour(1));
$post->scheduleFor(new Carbon('2021-04-01 10:00:00'));
$post->unpublish();

$postsWithNotPublished = Post::query()->withNotPublished();
$onlyNotPublishedPosts = Post::query()->onlyNotPublished();