PHP code example of marcotisi / soft-enable

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

    

marcotisi / soft-enable example snippets




Post::where('enabled', true)->get();



namespace App;

use Illuminate\Database\Eloquent\Model;
use MarcoTisi\SoftEnable\SoftEnable;

class Post extends Model
{
    use SoftEnable;
}



Schema::table('posts', function ($table) {
    $table->bool('enabled')->default(1);
});



namespace App;

use Illuminate\Database\Eloquent\Model;
use MarcoTisi\SoftEnable\SoftEnable;

class Post extends Model
{
    use SoftEnable;
    
    const ENABLED = 'is_enabled';
}


// Enable the model
Post::find(1)->enable();

// Disable the model
Post::find(1)->disable();


$posts = Post::withDisabled()->get();


$posts->comments()->withDisabled()->get();


if ($posts->first()->isEnabled()) {
    // ...
}


if ($posts->first()->isDisabled()) {
    // ...
}