PHP code example of divineomega / laravel-extendable-basket
1. Go to this page and download the library: Download divineomega/laravel-extendable-basket 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/ */
divineomega / laravel-extendable-basket example snippets
# app/Basket.php
namespace App;
use DivineOmega\LaravelExtendableBasket\Models\Basket as BasketModel;
class Basket extends BasketModel
{
public function items(): HasMany
{
return $this->hasMany('App\BasketItem');
}
}
# app/BasketItem.php
namespace App;
use DivineOmega\LaravelExtendableBasket\Models\BasketItem as BasketItemModel;
class BasketItem extends BasketItemModel
{
public function basket(): BelongsTo
{
return $this->belongsTo('App\Basket');
}
}
# app/Product.php
namespace App;
use Illuminate\Database\Eloquent\Model;
use DivineOmega\LaravelExtendableBasket\Interfaces\Basketable;
class Product extends Model implements Basketable {
// ...
}
$basket = Basket::getCurrent();
$basket = Basket::getNew();
// Get new basket
$basket = new Basket();
// Get current basket
$userBasketId = Auth::user()->basket_id;
$basket = Basket::find($userBasketId);
# app/Basket.php
namespace App;
use DivineOmega\LaravelExtendableBasket\Models\Basket as BasketModel;
class Basket extends BasketModel
{
public function items()
{
return $this->hasMany('App\BasketItem');
}
public function getTotal()
{
$deliveryCost = 3.99;
return $this->getSubtotal() + $deliveryCost;
}
}
php artisan migrate
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.