PHP code example of elaborate-code / laravel-algerian-provinces

1. Go to this page and download the library: Download elaborate-code/laravel-algerian-provinces 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/ */

    

elaborate-code / laravel-algerian-provinces example snippets


return [
    'columns_names' => [
        'fr_name' => null, // defaults to fr_name
        'ar_name' => null, // defaults to ar_name
    ],
];

use ElaborateCode\AlgerianProvinces\Models\Wilaya;

$wilayas = Wilaya::all();

$wilayas = Wilaya::find(31); // Model of: ["id" => 31, "fr_name" => "Oran", "ar_name" => "وهران"]

$wilayas = Wilaya::arr(); // Wilaya::all()->toArray()

$fr_names = Wilaya::frNames(); // Wilaya::pluck('fr_name')

$ar_names = Wilaya::arNames(); // Wilaya::pluck('ar_name')

namespace App\Models;

use ElaborateCode\AlgerianProvinces\Models\Wilaya;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class User extends Model
{
    // use as relationship
    
    public function birthWilaya(): BelongsTo
    {
        return $this->belongsTo(Wilaya::class, 'birth_wilaya', 'fr_name');
    }
}
bash
php artisan vendor:publish --tag="algerian-provinces-config"