PHP code example of marshmallow / products

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

    

marshmallow / products example snippets


use Marshmallow\Product\Models\Product;
use Marshmallow\Product\Observers\ProductObserver;

public function boot()
{
    Product::observe(ProductObserver::class);
}

use Marshmallow\Product\Models\Product;

$product = Product::factory()->create([
    'name' => 'Example product',
]);

// Eager load the common relationships to prevent N+1 queries.
$products = Product::active()->withRelationships()->get();

foreach ($products as $product) {
    $product->fullname();        // human readable name
    $product->freeStock();       // amount purchasable right now
    $product->getAvailability(); // Product::IN_STOCK | OUT_OF_STOCK | PREORDER
    $product->getCondition();    // 'new'
    $product->route();           // route('product.detail', $product)

    if ($product->hasImage()) {
        $product->firstImagePath();
    }
}

Product::IN_STOCK;
Product::OUT_OF_STOCK;
Product::PREORDER;
bash
php artisan db:seed --class="Marshmallow\Priceable\Database\Seeds\VatRatesSeeder"
bash
php artisan vendor:publish --tag="config"
bash
php artisan marshmallow:resource Product Product
php artisan marshmallow:resource Supplier Product
php artisan marshmallow:resource ProductCategory Product
php artisan marshmallow:resource Price Priceable
php artisan marshmallow:resource VatRate Priceable
php artisan marshmallow:resource Currency Priceable