PHP code example of brnysn / laravel-world

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

    

brnysn / laravel-world example snippets


return [
    'use_uuid' => false,
];

use Brnysn\World\Traits\HasWorldAddress;

class {class_name} extends Model
{
    use HasWorldAddress;
}

// Get Data
use Brnysn\World\Models\Country;
use Brnysn\World\Models\State;
use Brnysn\World\Models\City;

$country = Country::find(1);
$state = State::find(1);
$city = City::find(1);

// Get Relationship
$country->states;
$state->cities;
$city->state;
$city->country;

// Query
$country->states()->where('name', 'like', '%state%')->get();
$state->cities()->where('name', 'like', '%city%')->get();

// Set Address of a model with HasWorldAddress trait
$model->changeCountry($country);
$model->changeState($state);
$model->changeCity($city);
$model->changeAddress($country, $state, $city);

// Get details of address of a model with HasWorldAddress trait
$model->country->name;
$model->state->name;

bash
php artisan vendor:publish --tag="world-config"
bash
php artisan vendor:publish --tag="world-migrations"
php artisan migrate
bash
php artisan db:seed --class="Brnysn\\World\\Database\\Seeders\\WorldSeeder"