1. Go to this page and download the library: Download givanov95/laravel-shipping 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/ */
givanov95 / laravel-shipping example snippets
use Brick\Money\Money;
use Givanov95\Shipping\Contracts\DeliveryMethod;
use Givanov95\Shipping\Contracts\Parcel;
use Givanov95\Shipping\Destination;
use Givanov95\Shipping\DestinationType;
final class PickupFromShop implements DeliveryMethod
{
public function key(): string { return 'pickup'; }
public function destinationTypes(): array { return [DestinationType::Office]; }
public function rules(DestinationType $type): array { return []; }
public function destination(DestinationType $type, array $choice): Destination
{
return new Destination(
method: $this->key(),
type: $type,
countryCode: $choice['country_code'],
pointCode: 'SHOP',
pointName: 'The shop',
);
}
public function price(Destination $destination, Parcel $parcel): ?Money
{
return Money::zero($parcel->getCurrency());
}
}
use Givanov95\Shipping\DeliveryMethods;
use Illuminate\Support\ServiceProvider;
final class PickupServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->callAfterResolving(DeliveryMethods::class, function (DeliveryMethods $methods): void {
$methods->register('pickup', PickupFromShop::class, 'Pick up from the shop');
});
}
}
$methods = app(DeliveryMethods::class);
$methods->has('pickup'); // true
$methods->get('pickup'); // the PickupFromShop instance, or null for an unknown key
$methods->keys(); // ['pickup'], in the order of registration
$methods->labels(); // ['pickup' => 'Pick up from the shop']
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.