Skip to content

Instantly share code, notes, and snippets.

@bayareawebpro
Last active September 25, 2017 04:41
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 bayareawebpro/35f02b4dc93ab0743207a375bd0b51e0 to your computer and use it in GitHub Desktop.
Save bayareawebpro/35f02b4dc93ab0743207a375bd0b51e0 to your computer and use it in GitHub Desktop.
<?php
public function scopeActivePlansForUser($query, $user){
$plansArray = $user->subscriptions()->get()->sortBy('ends_at')->pluck('stripe_plan')->toArray();
$ordered = "'".implode("','",$plansArray)."'"; // format order: '1','3',
return $query->whereIn('stripe_id',$plansArray)->orderByRaw(\DB::raw("FIELD(stripe_id, $ordered)"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment