PHP code example of yhbyun / nova-kakao-address

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

    

yhbyun / nova-kakao-address example snippets




namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    public static function boot()
    {
        parent::boot();

        static::creating(function ($model) {
            if ($model->address) {
                $data = json_decode($model->address);
                $model->address = $data->address;
                $model->address_1level = $data->address_1level;
                $model->address_2level = $data->address_2level;
                $model->address_3level = $data->address_3level;
                $model->address_others = $data->address_others;
                $model->latitude = $data->latitude;
                $model->longitude = $data->longitude;
            }

            return true;
        });

        static::updating(function ($model) {
            if ($model->address) {
                $data = json_decode($model->address);
                $model->address = $data->address;
                $model->address_1level = $data->address_1level;
                $model->address_2level = $data->address_2level;
                $model->address_3level = $data->address_3level;
                $model->address_others = $data->address_others;
                $model->latitude = $data->latitude;
                $model->longitude = $data->longitude;
            } else {
                $model->address = null;
                $model->address_1level = null;
                $model->address_2level = null;
                $model->address_3level = null;
                $model->address_others = null
                $model->latitude = null;
                $model->longitude = null;
            }

            return true;
        });
    }
...



namespace App\Nova;

use Laravel\Nova\Fields\ID;
use Yhbyun\NovaKakaoAddress\KakaoAddress;

class Post extends Resource
{
     public static $model = 'App\Post';

     public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            KakaoAddress::make('Address')
                ->rules('