PHP code example of escapework / laravelhelpers

1. Go to this page and download the library: Download escapework/laravelhelpers 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 / laravelhelpers example snippets


use EscapeWork\LaravelHelpers\BaseModel;

class Product extends BaseModel
{

    // ...
}

use EscapeWork\LaravelHelpers\BaseModel;
use EscapeWork\LaravelHelpers\SluggableTrait;

class Product extends BaseModel
{

    use SluggableTrait;
}

protected $sluggableAttr = 'name';

    protected $makeSlugOnUpdate = false;

    public function store()
    {
        $this->product->title = 'Hello World';
        $this->product->save();

        echo $this->product->slug; // prints hello-world
    }
}

$products = $product->search('title', 'this title')->get();

// model
...
    public function setDateAttribute($date)
    {
        $this->_setDateAttribute('date', $date, $format = 'd/m/Y');
    }
...

// whaterer place you need
$model->date = '10/03/1991'; // this format should be the same as the above

// model
...
    public function setPriceBRLAttribute($price)
    {
        $this->_setCurrencyAttribute('priceBRL', $price);
    }

    public function setPriceAttribute($price)
    {
        $this->_setCurrencyAttribute('price', $price, 'USD');
    }
...

// whaterer place you need
$model->priceBRL = '10,90';
$model->price    = '10.90';

var_dump($model->priceBRL); // (float) 10.90';
var_dump($model->price);    // (float) 10.90';

Form::select('product_id', Product::all()->combobox());

Form::select('client_id', Client::all()->combobox(['field' => 'name']); // for using the 'name' field

Form::select('client_id', Client::all()->combobox(['field' => 'name', 'empty_option' => true, 'empty_option_label' => 'Select a client']));

$product = App::make('ProductRepository'); // just a sample, you probably will use dependency injection
$product->findOrFailBy('slug', 'office-chair');

dd($product->title);