CourseApi.php 970 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Http\Api;
  3. use App\Models\CourseMember;
  4. use Illuminate\Support\Facades\Log;
  5. class CourseApi{
  6. public static function getStudentChannels($courseId){
  7. $channels = [];
  8. $studentsChannel = CourseMember::where('course_id',$courseId)
  9. ->whereNotNull('channel_id')
  10. ->where('role','student')
  11. ->whereIn('status',['joined','accepted','agreed'])
  12. ->select('channel_id')
  13. ->orderBy('created_at')
  14. ->get();
  15. foreach ($studentsChannel as $key => $channel) {
  16. $channels[] = $channel->channel_id;
  17. }
  18. return $channels;
  19. }
  20. public static function role($courseId,$userUid){
  21. $role = CourseMember::where('course_id',$courseId)
  22. ->where('user_id',$userUid)
  23. ->where('is_current',true)
  24. ->value('role');
  25. return $role;
  26. }
  27. }