PHP code example of nestermaks / laravel-pricelist

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

    

nestermaks / laravel-pricelist example snippets



// config for Laravel Pricelist
return [

    /////////////////////////////////////////////
    //Locales for Astrotomic/laravel-translatable
    /////////////////////////////////////////////
    'locales' => [
        'en',
        'ru',
        'uk',
    ],


    ///////////////////
    //API routes prefix
    ///////////////////
    'api' => 'nestermaks-api',


    //////////////////////////
    //Pricelists routes prefix
    //////////////////////////
    'pricelists' => 'pricelists',


    ///////////////////////////////
    //Pricelist items routes prefix
    ///////////////////////////////
    'items' => 'pricelist-items',


    ////////////////////////////////////////////////
    //Items amount shown when index method is called
    ////////////////////////////////////////////////
    'pricelists-per-page' => 10,
    'pricelist-items-per-page' => 10,


    ///////////////////////////////////////////////
    //Validation rules for store and update methods
    ///////////////////////////////////////////////
    'store-pricelists' => [
        'title' => ['ctive' => ['boolean']
    ],


];


namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Nestermaks\LaravelPricelist\HasPricelist;

class Offer extends Model
{
    use HasPricelist;
    ...
}

$offer = Offer::first();
$pricelist = Pricelist::first();

$offer->addPricelist($pricelist);

$offer->removePricelist($pricelist);

$offer->pricelists();

Pricelist::getActiveItems();

PricelistItem::getActiveItems();

Pricelist::relatedItems();

PricelistItem::relatedItems();

$pricelists = Pricelist::all();
$pricelist = Pricelist::first();
$pricelist_items = PricelistItem::all();
$pricelist_item = PricelistItem::first();

$pricelist->attachItems($pricelist_items);

$pricelist_item->attachItems($pricelists);

$pricelist->detachItems($pricelist_items);

$pricelist_item->detachItems($pricelists);

$pricelist->getItemOrder($pricelist_item);

$pricelist_item->getItemOrder($pricelist);

$pricelist->changeItemOrder($pricelist_item, 3);

$pricelist_item->changeItemOrder($pricelist, 3);
bash
php artisan vendor:publish --tag=pricelist-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=pricelist-translations
bash
php artisan vendor:publish --tag=pricelist-config