Skip to content

Instantly share code, notes, and snippets.

@EricMcWinNer
Created September 11, 2020 15:00
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/87ed414e0b108cd8351aa1cfe40ad96d to your computer and use it in GitHub Desktop.
Save EricMcWinNer/87ed414e0b108cd8351aa1cfe40ad96d 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
foreach($candidates as $candidate) {
// Do what you want with $candidate
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment