Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Table users (model App\User)
- id
- email
- active (0/1)
- join_date
- address etc
- phone
- Table subscriptions (model App\Subscription)
- id
- user_id
- box_id (what the person is subscribed to get)
- amount
- SELECT users.*, subscriptions.*
- FROM subscriptions
- JOIN users ON users.id = subscriptions.user_id
- WHERE users.active = 1
- */
- class Subscription extends Model
- {
- public static function allActive()
- {
- // This works except it doesn't use the eloquent relationship
- return static::where('users.active', 1)
- ->join('users', 'users.id', '=', 'subscriptions.user_id')
- ->select('users.*','subscriptions.*')
- ->get();
- }
- public function user()
- {
- return $this->belongsTo(User::class);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement