PHP code example of marshmallow / address-prefiller

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

    

marshmallow / address-prefiller example snippets


use Marshmallow\Zipcode\Nova\Zipcode;

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),
        $this->addressFields(),
    ];
}

protected function addressFields()
{
    return $this->merge([
        Zipcode::make(__('Zipcode prefiller'), __('Zipcode'), __('Housenumber'))
            /**
             * Let the package know which columns are connected to
             * the fields. The default values are commented after each
             * function call. If your column names match these defaults,
             * you don't need to call all these functions.
             */
            ->zipcode('zipcode')         // default: zipcode
            ->housenumber('housenumber') // default: housenumber
            ->street('street')           // default: street
            ->city('city')               // default: city
            ->province('province')       // default: province
            ->country('country')         // default: country
            ->latitude('latitude')       // default: latitude
            ->longitude('longitude'),    // default: longitude

        /**
         * The fields below will all be prefilled with the collected
         * data if we find a match on the submitted zipcode and house number.
         */
        Hidden::make(__('Zipcode'), 'zipcode')->hideFromIndex(),
        Hidden::make(__('Housenumber'), 'address_2')->hideFromIndex(),
        Text::make(__('Street'), 'address_1')->hideFromIndex(),
        Text::make(__('City'), 'city')->hideFromIndex(),
        Text::make(__('Province'), 'province')->hideFromIndex(),
        Country::make(__('Country'), 'country')->hideFromIndex(),
        Text::make(__('Latitude'), 'latitude')->hideFromIndex(),
        Text::make(__('Longitude'), 'longitude')->hideFromIndex(),
    ]);
}

use Marshmallow\Zipcode\Facades\Zipcode;

return Zipcode::get(
    $request->zipcode,
    $request->housenumber
);

use Marshmallow\Zipcode\Facades\Zipcode;

return Zipcode::street('address_1')
    ->city('city')
    ->province('province')
    ->country('country')
    ->latitude('latitude')
    ->longitude('longitude')
    ->get($request->zipcode, $request->housenumber);