承接 mstfblci/laravel-addresses 相关项目开发

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

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

mstfblci/laravel-addresses

最新稳定版本:1.0.0

Composer 安装命令:

composer require mstfblci/laravel-addresses

包简介

Module for storing addresses.

README 文档

README

An easy way to manage Turkey addresses for Eloquent models in Laravel. Inspired by the following packages:

Installation

Require the package by running

composer require madonetr/laravel-addresses

Publish configuration and migration

php artisan vendor:publish --provider="Madonetr\Addresses\AddressesServiceProvider"

This command will publish a config/addresses.php and a migration file.

You can modify the default fields and their rules by changing both of these files.

After publishing you can run the migrations

php artisan migrate

Usage

You can use the HasAddresses trait on any model.

<?php

namespace App\Models;

use Madonetr\Addresses\Traits\HasAddresses;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasAddresses;

    // ...
} 

After doing this you can use the following methods.

Add an address to a model

$post = Post::first();
$post->addAddress([
	'label' 				=> 'My address', // required
	'type'					=> 'Individual', // defaults to: null
	'name'					=> 'Mustafa Balci', // defaults to: null
	'company'				=> 'Madonetr', // defaults to: null
	'vat_id'				=> '12314123', // defaults to: null - integer
	'vat_office'				=> 'Yalova Vergi Dairesi', // defaults to: null
	'address' 				=> 'Main Street', // defaults to: null
	'postal_code'				=> '10001', // defaults to: null
	'city'					=> 'Yalova', // defaults to: null
	'state'					=> 'New Madonetr State', // defaults to: null
	'country'				=> 'Turkey', // defaults to: null
	'is_primary'				=> true, // defaults to: false
	'is_billing'				=> false, // defaults to: false
	'is_shipping'				=> false, // defaults to: false
]);

Update an existing address

$post = Post::first();
$address = $post->getPrimaryAddress();

$post->updateAddress($address, ['label' => 'My new address']);

Delete an address from a model

$post = Post::first();
$address = $post->addresses()->first();

if ($post->deleteAddress($address)) {
	//do something
}

Determine if a model has any addresses

$post = Post::first();

if ($post->hasAddresses()) {
	//do something
}

Determine if a model has (one of) the given address(es).

use Madonetr\Addresses\Models\Address;

$post = Post::find();
$address = Address::first();

if ($post->hasAddress($address)) {
	//do something
}

//OR
if ($post->hasAddress($address->id)) {
	//do something
}

//OR
$addresses = Address::where('city', 'Yalova')->get();
if ($post->hasAddress($addresses)) {
	//do something
}

//OR
$addresses = Address::where('state', 'New Madonetr State')->pluck('id')->toArray();
if ($post->hasAddress($addresses)) {
	//do something
}

This will return true when one of the given addresses belongs to the model.

Getters

You can use the following methods to retrieve addresses and certain attributes.

Get the primary address of the model.

$post = Post::first();

$primaryAddress = $post->getPrimaryAddress();

Get the billing address of the model.

$post = Post::first();

$billingAddress = $post->getBillingAddress();

Get the shipping address of the model.

$post = Post::first();

$shippingAddress = $post->getShippingAddress();

Get the labels of all addresses of the model.

$post = Post::first();

$labels = $post->getAddressLabels();

License

Licensed under MIT license.

Author

Written by Mustafa Balci in Turkey.

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-17