PHP code example of saidy / voyager-dependent-dropdown

1. Go to this page and download the library: Download saidy/voyager-dependent-dropdown 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/ */

    

saidy / voyager-dependent-dropdown example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class TraineeInfo extends Model
{
    use HasFactory;
    public $timestamps = false;
    protected $primaryKey = 'trainee_id';

    protected $table = 'trainee_info';

    public $additional_attributes = ['trainee_full_name'];

    public function getTraineeFullNameAttribute()
    {
        return "{$this->trainee_name}: ({$this->trainee_id})";
    }

    public static function postingUpazilaRelationship($id)
    {
        /**
         *
         *	return [
         *		'posting_upazila' => xxx,
         *		'division_id' => yyy,
         *		'district_id' => yyy
         *	]
         *
         */

        return
            self::where('trainee_info.trainee_id', '=', $id)
            ->select(
                'trainee_info.posting_upazila',
                'division.division_id',
                'division.division_id as posting_division',
                'district.district_id',
                'district.district_id as posting_district'
            )
            ->join('upazila', 'upazila.upazila_id', '=', 'trainee_info.posting_upazila')
            ->join('district', 'upazila.district_id', '=', 'district.district_id')
            ->join('division', 'district.division_id', '=', 'division.division_id')
            ->first();
    }
}