使用内连接的Laravel Eloquent语句

时间:2017-07-04 13:57:44

标签: laravel laravel-5 eloquent laravel-eloquent

我有三个型号。

  1. ScheduledMessage指向table scheduled_messages。
  2. SubscribedService指向表subscribed_services。
  3. SubscriptionServicesMsisdn指向表subscription_services_msisdn。
  4. 我有原始的SQL查询,我想转换成雄辩,但想不出办法。

    SQL查询:

    SELECT DISTINCT 
      b.message, c. phone_number, a.username, a.password from subscribed_services a 
    inner join 
      subscription_services_msisdn c on a.id = c.subscribed_services_id 
    inner join 
     scheduled_messages b on a.id = b.subscribed_services_id where DATE(b.scheduled_at) = CURDATE()
    

    有人请帮助转换为雄辩。

    关系

    public function scheduled_messages()
    {
        return $this->hasMany(\App\Models\ScheduledMessage::class, 'subscribed_services_id');
    }
    
    public function subscription_services_msisdns()
    {
        return $this->hasMany(\App\Models\SubscriptionServicesMsisdn::class, 'subscribed_services_id');
    }
    

    谢谢。

0 个答案:

没有答案