Created
June 20, 2020 10:21
-
-
Save myathtut-zafir/f7237900787ee59ec58abe48c6e9d29d to your computer and use it in GitHub Desktop.
Seed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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