maa-solutions/simple-address

A simple address extension for Eloquent models

v1.2.0 2024-08-13 07:08 UTC

This package is auto-updated.

Last update: 2024-12-13 07:49:31 UTC


README

Latest Version on Packagist Total Downloads GitHub Issues License

A Laravel package to easily manage addresses associated with your Eloquent models.

Introduction

The Simple Address package enables you to attach and manage addresses to any of your Eloquent models. Whether you want to track shipping addresses for orders, store addresses for users, or office addresses for companies, this package provides a clean and simple solution.

Installation

To get started with Simple Address, install it via Composer:

composer require maa-solutions/simple-address

Usage

Implement the Addressable interface in your Eloquent model and add its HasAddresses trait:

class MyModel extends Model implements Addressable
{
    use HasAddresses;

    ...
}

Now, you can easily manage addresses for your model instances:

use MaaSolutions\SimpleAddress\Facades\SimpleAddress;

...

public function create(Request $request)
{
    $validated_address = SimpleAddress::validate($request->all());

    $myModel = MyModel::create($request->validated());

    SimpleAddress::create(for: $myModel, with: $validated_address);
}

public function update(Request $request, MyModel $myModel)
{
    SimpleAddress::update(for: $myModel, with: $request->all());
}