Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@myathtut-zafir
Created June 20, 2020 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myathtut-zafir/f7237900787ee59ec58abe48c6e9d29d to your computer and use it in GitHub Desktop.
Save myathtut-zafir/f7237900787ee59ec58abe48c6e9d29d to your computer and use it in GitHub Desktop.
Seed
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Traits\APIResponser;
use App\Http\Controllers\Controller;
use App\Http\Resources\IncludedRepresentativeElectionRegion;
use App\Http\Resources\RepresentativeElectionRegionSeed;
use App\Models\Category;
use App\Models\Faq;
use App\Models\Party;
use App\Models\PyiThuElectionRegion;
use App\Models\Representative;
use Illuminate\Support\Facades\DB;
class ParliamentSeedApiController extends Controller
{
use APIResponser;
function getPyithuElectionSeed()
{
$parties = Party::with(['representatives' =>
function ($query) {
$query->where('election_region_type', "App\Models\PyiThuElectionRegion")
->where('is_famous', 1);
}
])->get()->sortByDesc(function ($query) {
return $query->representatives->count();
});
$parties = $parties->values()->all();
$representatives = [];
foreach ($parties as $party) {
foreach ($party->representatives as $representative) {
$representative->party_id = $party['id'];
$representative->party_color = $party['party_color'];
$representative->english_name = $party['english_name'];
array_push($representatives, $representative);
}
}
return $this->respondCollection('success to get category.', RepresentativeElectionRegionSeed::collection($representatives));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment