承接 neuecommerce/addresses 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

neuecommerce/addresses

Composer 安装命令:

composer require neuecommerce/addresses

包简介

Addresses is a polymorphic Laravel package, for addressbook management. Adding addresses to any Eloquent model was never this easy.

README 文档

README

GitHub Tests Action Status GitHub Code Analysis Action Status Software License Latest Version on Packagist Total Downloads

Addresses is a polymorphic Laravel package, for addressbook management.

Adding addresses to any Eloquent model was never this easy and the possibilities of address organisation is also possible since you'll be able to assign a custom type like shipping, billing, etc.. to each address, which gives the possibility of having one default address per type of address. For example, have one default shipping address and one default billing address, which is very common on e-commerce applications.

Installation

  1. Install the package via Composer:
composer require neuecommerce/addresses
  1. Publish the migrations (optional):
php artisan vendor:publish --tag="neuecommerce-addresses-migrations"
  1. Publish the configuration file (optional):
php artisan vendor:publish --tag="neuecommerce-addresses-config"
  1. Run the migrations:
php artisan migrate

Implementation

In order to add addresses support to your Eloquent models, you'll need to ensure that your model implements the NeueCommerce\Addresses\Contracts\HasManyAddressesInterface interface and the NeueCommerce\Addresses\Traits\HasManyAddresses trait.

Here's an example of a model with the proper implementation:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use NeueCommerce\Addresses\Contracts\HasManyAddressesInterface;
use NeueCommerce\Addresses\Traits\HasManyAddresses;

class Customer extends Model implements HasManyAddressesInterface
{
    use HasManyAddresses;

    public $table = 'customers';
}

Usage

In this section you'll learn how to use the address package and manage the addresses of your Eloquent Models.

For simplicity, the entity we'll use will be of a Customer entity (the one we created on the previous section):

$customer = Customer::first();

Create a new Address

Creating new addresses is very simple.

Example:
$address = $customer->addresses()->create([
    'type' => 'shipping',
    'display_name' => 'Default Shipping Address',
    'first_name' => 'John',
    'last_name' => 'Done',
    'address_1' => '3327 Colby Ave',
    'city' => 'Everett',
    'country_code' => 'US',
    'state' => 'Washington',
    'postal_code' => '98201',
    'latitude' => '47.972829',
    'longitude' => '-122.20793',
    'is_default' => true,
]);

Update an existing Address

To update an address, you'll need to fetch the address you want to update and then call the update() method on that address instance while providing the updated attributes.

Example:
// Find the address to update
$address = $customer->addresses()->whereType('shipping')->whereDefault()->first();

// Update the address
$address->update([
    'display_name' => 'Home Shipping Address',
]);

Delete an Address

To delete an address, you'll need to fetch the address you want to delete and then call the delete() method on that address instance.

Example:
// Find the address to delete
$address = $customer->addresses()->whereType('shipping')->whereDefault()->first();

// Delete the address
$address->delete();

Testing

composer test

Contributing

Thank you for your interest. Here are some of the many ways to contribute.

License

This package is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 8.1k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固