PHP code example of ixudra / addressable

1. Go to this page and download the library: Download ixudra/addressable 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/ */

    

ixudra / addressable example snippets



    'providers'     => array(

        //...
        Ixudra\Addressable\AddressableServiceProvider::class,

    ),



    php artisan migrate --package="ixudra/addressable"



    // Publish all resources from all packages
    php artisan vendor:publish
    
    // Publish only the resources of the package
    php artisan vendor:publish --provider="Ixudra\\Addressable\\AddressableServiceProvider"



    use Illuminate\Database\Eloquent\Model;
    use Ixudra\Addressable\Models\Address;

    class Shop extends Model {

        public function address()
        {
            return $this->morphOne( Address::class, 'reference' );
        }


        public function delete()
        {
            if( !is_null($this->address) ) {
                $this->address->delete();
            }

            parent::delete();
        }

    }



    use Ixudra\Addressable\Services\Factories\AddressFactory;

    class ShopFactory {

        protected $addressFactory;


        /**
         * @codeCoverageIgnore
         */
        public function __construct(AddressFactory $addressFactory)
        {
            $this->addressFactory = $addressFactory;
        }


        public function create($input, $prefix = '')
        {
            $shop = Shop::create( array( 'name' => $input['name'] ) );
            $this->addressFactory->make( $input, $shop, $prefix );

            return $shop;
        }

        public function modify($shop, $input, $prefix = '')
        {
            $shop = $shop->update( array( 'name' => $input['name'] ) );
            $this->addressFactory->modify( $shop->address, $input, $shop, $prefix );

            return $shop;
        }

    }



    {!! Form::open(array('url' => 'shops', 'method' => 'POST', 'id' => 'createShop', 'class' => 'form-horizontal', 'role' => 'form')) !!}

        <div class="well well-large">
            <div class='form-group {{ $errors->has('name') ? 'has-error' : '' }}'>
                {!! Form::label('name', 'Name:', array('class' => 'control-label col-lg-3')) !!}
                <div class="col-lg-6">
                    {!! Form::text('name', $input['name'], array('class' => 'form-control')) !!}
                    {!! $errors->first('name', '<span class="help-block">:message</span>') !!}
                </div>
            </div>
        </div>

        @


    <div class="row">
        <div class="well well-large col-md-12">
            <div class='col-md-10'>
                <div class='col-md-4'>Name:</div>
                <div class='col-md-8'>{{ $shop->name }}</div>
            </div>
        </div>
    </div>

    @