Skip to content

Commit e9df0dd

Browse files
committed
first commit
0 parents  commit e9df0dd

21 files changed

+1302
-0
lines changed

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
3+
All notable changes to `LaravelAddress` will be documented in this file.
4+
5+
## Version 1.0
6+
7+
### Added
8+
- Everything

composer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "bkfdev/laravel-address",
3+
"description": ":package_description",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "Author Name",
8+
"email": "[email protected]",
9+
"homepage": "http://author.com"
10+
}
11+
],
12+
"homepage": "https://github.com/bkfdev/laravel-address",
13+
"keywords": ["Laravel", "LaravelAddress"],
14+
"require": {
15+
"illuminate/support": "~9"
16+
},
17+
"require-dev": {
18+
"phpunit/phpunit": "~9.0",
19+
"orchestra/testbench": "~7"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"Bkfdev\\Addressable\\": "src/"
24+
}
25+
},
26+
"autoload-dev": {
27+
"psr-4": {
28+
"Bkfdev\\Addressable\\Tests\\": "tests"
29+
}
30+
},
31+
"extra": {
32+
"laravel": {
33+
"providers": [
34+
"Bkfdev\\Addressable\\LaravelAddressServiceProvider"
35+
],
36+
"aliases": {
37+
"LaravelAddress": "Bkfdev\\Addressable\\Facades\\LaravelAddress"
38+
}
39+
}
40+
}
41+
}

config/laravel-address.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
return [
4+
// Addresses Database Tables
5+
'tables' => [
6+
'addresses' => 'addresses',
7+
],
8+
9+
// Addresses Models
10+
'models' => [
11+
'address' => \Bkfdev\Addressable\Models\Address::class,
12+
],
13+
14+
];

contributing.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Contributing
2+
3+
Contributions are welcome and will be fully credited.
4+
5+
Contributions are accepted via Pull Requests on [Github](https://github.com/bkfdev/laravel-address).
6+
7+
# Things you could do
8+
If you want to contribute but do not know where to start, this list provides some starting points.
9+
- Add license text
10+
- Remove rewriteRules.php
11+
- Set up TravisCI, StyleCI, ScrutinizerCI
12+
- Write a comprehensive ReadMe
13+
14+
## Pull Requests
15+
16+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
17+
18+
- **Document any change in behaviour** - Make sure the `readme.md` and any other relevant documentation are kept up-to-date.
19+
20+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
21+
22+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
23+
24+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
25+
26+
27+
**Happy coding**!
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Support\Facades\Schema;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Database\Migrations\Migration;
8+
9+
class CreateAddressesTable extends Migration
10+
{
11+
public function up()
12+
{
13+
Schema::create(config('laravel-address.tables.addresses'), function (Blueprint $table) {
14+
// Columns
15+
$table->increments('id');
16+
$table->morphs('addressable');
17+
$table->string('label')->nullable();
18+
$table->string('country_code', 2)->nullable();
19+
$table->string('street')->nullable();
20+
$table->string('state')->nullable();
21+
$table->string('city')->nullable();
22+
$table->string('postal_code')->nullable();
23+
$table->decimal('latitude', 10, 7)->nullable();
24+
$table->decimal('longitude', 10, 7)->nullable();
25+
$table->boolean('is_primary')->default(false);
26+
$table->timestamps();
27+
$table->softDeletes();
28+
});
29+
}
30+
31+
public function down()
32+
{
33+
Schema::dropIfExists(config('laravel-address.tables.addresses'));
34+
}
35+
}

license.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# The license
2+
3+
Copyright (c) Author Name <[email protected]>
4+
5+
...Add your license text here...

phpunit.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="Package">
14+
<directory suffix=".php">./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory>src/</directory>
20+
</whitelist>
21+
</filter>
22+
</phpunit>

readme.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# LaravelAddress
2+
3+
[![Latest Version on Packagist][ico-version]][link-packagist]
4+
[![Total Downloads][ico-downloads]][link-downloads]
5+
[![Build Status][ico-travis]][link-travis]
6+
[![StyleCI][ico-styleci]][link-styleci]
7+
8+
Laravel Address is a package to manage addresses that belong to your models. You can add addresses to any eloquent model with ease.
9+
10+
## Installation
11+
12+
1. Install the package via composer:
13+
14+
```shell
15+
composer require bkfdev/laravel-address
16+
```
17+
18+
2. Publish resources (migrations and config files):
19+
20+
```shell
21+
php artisan vendor:publish --provider="Bkfdev\Addressable\AddressesServiceProvider"
22+
```
23+
24+
3. Run migrations:
25+
26+
```shell
27+
php artisan migrate
28+
```
29+
30+
4. Done!
31+
32+
## Usage
33+
34+
To add addresses support to your eloquent models simply use `\Bkfdev\Addressable\Traits\Addressable` trait.
35+
36+
### Manage your addresses
37+
38+
```php
39+
// Get instance of your model
40+
$user = new \App\Models\User::find(1);
41+
42+
// Create a new address
43+
$user->addresses()->create([
44+
'label' => 'Default Address',
45+
'country_code' => 'dz',
46+
'street' => '56 john doe st.',
47+
'state' => 'Canterbury',
48+
'city' => 'Christchurch',
49+
'postal_code' => '7614',
50+
'latitude' => '31.2467601',
51+
'longitude' => '29.9020376',
52+
'is_primary' => true,
53+
]);
54+
55+
// Create multiple new addresses
56+
$user->addresses()->createMany([
57+
[...],
58+
[...],
59+
[...],
60+
]);
61+
62+
// Find an existing address
63+
$address = app('addressable.address')->find(1);
64+
65+
// Update an existing address
66+
$address->update([
67+
'label' => 'Default Work Address',
68+
]);
69+
70+
// Delete address
71+
$address->delete();
72+
73+
// Alternative way of address deletion
74+
$user->addresses()->where('id', 123)->first()->delete();
75+
```
76+
77+
### Manage your addressable model
78+
79+
The API is intuitive and very straight forward, so let's give it a quick look:
80+
81+
```php
82+
// Get instance of your model
83+
$user = new \App\Models\User::find(1);
84+
85+
// Get attached addresses collection
86+
$user->addresses;
87+
88+
// Get attached addresses query builder
89+
$user->addresses();
90+
91+
// Scope Primary Addresses
92+
$primaryAddresses = app('addressable.address')->isPrimary()->get();
93+
94+
// Scope Addresses in the given country
95+
$algerianAddresses = app('addressable.address')->inCountry('dz')->get();
96+
97+
```
98+
99+
## Changelog
100+
101+
Refer to the [Changelog](CHANGELOG.md) for a full history of the project.
102+
103+
## Support
104+
105+
Please raise a GitHub issue.
106+
107+
## Testing
108+
109+
```bash
110+
$ composer test
111+
```
112+
113+
## Contributing
114+
115+
Please see [contributing.md](contributing.md) for details and a todolist.
116+
117+
## Security
118+
119+
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
120+
121+
## Credits
122+
123+
- [Author Name][link-author]
124+
- [All Contributors][link-contributors]
125+
126+
## License
127+
128+
MIT. Please see the [license file](license.md) for more information.
129+
130+
[ico-version]: https://img.shields.io/packagist/v/bkfdev/laravel-address.svg?style=flat-square
131+
[ico-downloads]: https://img.shields.io/packagist/dt/bkfdev/laravel-address.svg?style=flat-square
132+
[ico-travis]: https://img.shields.io/travis/bkfdev/laravel-address/master.svg?style=flat-square
133+
[ico-styleci]: https://styleci.io/repos/12345678/shield
134+
[link-packagist]: https://packagist.org/packages/bkfdev/laravel-address
135+
[link-downloads]: https://packagist.org/packages/bkfdev/laravel-address
136+
[link-travis]: https://travis-ci.org/bkfdev/laravel-address
137+
[link-styleci]: https://styleci.io/repos/12345678
138+
[link-author]: https://github.com/bkfdev
139+
[link-contributors]: ../../contributors

src/Facades/LaravelAddress.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Bkfdev\Addressable\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
class LaravelAddress extends Facade
8+
{
9+
/**
10+
* Get the registered name of the component.
11+
*
12+
* @return string
13+
*/
14+
protected static function getFacadeAccessor(): string
15+
{
16+
return 'laravel-address';
17+
}
18+
}

src/LaravelAddress.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Bkfdev\LaravelAddress;
4+
5+
class LaravelAddress
6+
{
7+
// Build wonderful things
8+
}

0 commit comments

Comments
 (0)