PHP code example of skore-labs / laravel-status

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

    

skore-labs / laravel-status example snippets




namespace App;

use Illuminate\Database\Eloquent\Model;
use SkoreLabs\LaravelStatus\Contracts\Statusable;
use SkoreLabs\LaravelStatus\Traits\HasStatuses;

class Post extends Model implements Statusable
{
    use HasStatuses;

    // Your model logic here...
}

    /**
     * Get the statuses enum used for some utilities.
     * 
     * @return string|\Spatie\Enum\Enum
     */
    public static function statusesClass()
    {
        return \App\Statuses\PostStatuses::class;
    }

// Post has status Published
$post->hasStatus('published');

// Post has status Published or Was Published
$post->hasStatus(['published', 'was published']);

// Set post status to Was Published
$post->setStatus('was published');

// Change if post has status Published to Was Published.
$post->setStatus(['published' => 'was published']);

$post->status = 'was published';

// Better use status method for this
if ($post->hasStatus('published')) {
    $post->status = 'was published';
}

// When save it check and attach the status
$post->save();

// Change if post has status Published to Was Published.
$post->setStatusWhen('published', 'was published');

Post::status('published');
Post::where('user_id', Auth::id())->status('published');

Post::statuses();

// You can use Status model as well
Status::getFrom(Post::class);
// Also specify value to return like '->value('id')'
Status::getFrom(Post::class, 'id');
// Or return the object with columns like '->first(['id', 'name'])'
Status::getFrom(Post::class, ['id', 'name']);

// Default status for post is Published, so it returns Published
Post::getDefaultStatus();

// You can use Status model query scope as well
Status::query()->defaultFrom(Post::class)->first();

php artisan vendor:publish --provider="SkoreLabs\LaravelStatus\ServiceProvider"