Skip to content

Instantly share code, notes, and snippets.

@EricMcWinNer
Last active September 11, 2020 14:57
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 EricMcWinNer/18b543d3848c6abb98accdd36b7a76ad to your computer and use it in GitHub Desktop.
Save EricMcWinNer/18b543d3848c6abb98accdd36b7a76ad to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use App\Models\PoliticalParty;
class RandomController extends Controller {
/**
* Gets candidates
*/
public function getCandidates() {
$party = PoliticalParty::find(1);
$candidates = $party->candidates; // Returns a Laravel Collection
return response(['candidates' => $candidates], 200); // Returns JSON object containing an array of candidates
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment