Coder Social home page Coder Social logo

al-jazair / laravel-algerian-provinces Goto Github PK

View Code? Open in Web Editor NEW
10.0 0.0 0.0 84 KB

๐Ÿ“ฆ The easiest way to get Eloquent models for the 58 Algerian provinces on Laravel

Home Page: https://packagist.org/packages/elaborate-code/laravel-algerian-provinces

License: MIT License

PHP 100.00%
laravel package algeria provinces cities states wilaya databse structure eloquent

laravel-algerian-provinces's Introduction

Laravel Algerian provinces

Packagist Version Packagist Downloads GitHub Workflow Status GitHub Workflow Status

banner

Algerian provinces Eloquent model for Laravel applications.

Installation

Install the package via composer:

composer require elaborate-code/laravel-algerian-provinces

Requirements:

  1. SQLite.

Publishing config file [Optional]

You can publish the config file with:

php artisan vendor:publish --tag="algerian-provinces-config"

This is the contents of the published config file:

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

That allows you to rename columns names.

Usage

Now you have access to the ElaborateCode\AlgerianProvinces\Models\Wilaya

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');
    }
}

Sushi

This package requires 0 config, and comes with no migrations or seeders thanks to the wonderful package calebporzio/sushi. That allows us to offer a ready to use model without going the extra steps of affecting your database.

However this dependency requires SQLite to be setup on your system!

If you prefer having a table in your database checkout v1 which doesn't depand on calebporzio/sushi.

Testing

vendor/bin/pint

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

laravel-algerian-provinces's People

Contributors

dependabot[bot] avatar ghs-medilies avatar github-actions[bot] avatar medilies avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.