PHP code example of escapework / laravel-steroids

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

    

escapework / laravel-steroids example snippets


use EscapeWork\LaravelSteroids\Model;

class Product extends Model
{
}

use EscapeWork\LaravelSteroids\Presentable;

class Product extends Model
{
    use Presentable;

    protected $presenter = 'App\Presenters\ProductPresenter';
}

use EscapeWork\LaravelSteroids\Presenter;

class ProductPresenter extends Presenter
{
    public function title()
    {
        // $this->model gives you access to your model inside the presenter
        return ucwords($this->model->title);
    }
}

$product = Product::find(1);
echo $product->present->title;

use EscapeWork\LaravelSteroids\Sluggable;

class Product extends Model
{
    use Sluggable;
}

class User extends Model
{
    use Sluggable;
    protected $sluggableAttr  = 'name';
    protected $sluggableField = 'username';
}

use EscapeWork\LaravelSteroids\Cacheable;

class Product extends Model
{
    use Cacheable;

    protected $cacheable = [
        // here you need to put your cache keys that need to be cleared
        'products.actives',
        'products.all',

        // you can also use some attribute to be replaced
        // in this case, the {category_id} will be replaced with $product->category_id,
        'products.category.{category_id}'
    ];
}

use EscapeWork\LaravelSteroids\Sortable;

class Banner extends Model
{
    use Sortable;
}

Banner::create(['title' => 'First Banner'])->order;  // 1
Banner::create(['title' => 'Second Banner'])->order; // 2

protected $sortable = [
    'field' => 'order',
];

use EscapeWork\LaravelSteroids\Ordenable;

class Product extends Model
{
    use Ordenable;

    protected $ordenables = [
        'price',
        'hits'
    ];

    protected $ordenableDefault = [
        'field'     => 'created_at',
        'direction' => 'desc',
    ];
}

$products = Product::where(...)->order('price', 'desc')->get();