Created
August 6, 2014 21:19
-
-
Save adamgoose/d517eca6e011d84f99cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Course extends Eloquent implements Collectable { | |
use SoftDeletingTrait; | |
use EventGenerator; | |
use TaggableTrait; | |
use ImagableTrait; | |
/** | |
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | |
*/ | |
public function completedBy() | |
{ | |
return $this->belongsToMany('User', 'course_progress')->withTimestamps()->withPivot(['scope_type', 'scope_id']); | |
} | |
/** | |
* @param Model $parent | |
* @param array $attributes | |
* @param string $table | |
* @param bool $exists | |
* | |
* @return CourseProgress|Pivot | |
*/ | |
public function newPivot(Model $parent, array $attributes, $table, $exists) | |
{ | |
if($table == 'course_progress') | |
return new CourseProgress($parent, $attributes, $table, $exists); | |
return new Pivot($parent, $attributes, $table, $exists); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class CourseProgress extends Pivot { | |
use EventGenerator; | |
/** | |
* @var string | |
*/ | |
protected $table = 'course_progress'; // The pivot table between users and courses | |
/** | |
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | |
*/ | |
public function user() | |
{ | |
return $this->belongsTo('User'); | |
} | |
/** | |
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | |
*/ | |
public function course() | |
{ | |
return $this->belongsTo('Course'); | |
} | |
/** | |
* @return \Illuminate\Database\Eloquent\Relations\MorphTo | |
*/ | |
public function scope() | |
{ | |
return $this->morphTo(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class User extends Eloquent implements UserInterface, RemindableInterface, CourseProgressScope { | |
use UserTrait, RemindableTrait, EventGenerator; | |
/** | |
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | |
*/ | |
public function courseProgress() | |
{ | |
return $this->belongsToMany('Course', 'course_progress')->withTimestamps()->withPivot(['scope_type', 'scope_id']); | |
} | |
/** | |
* @param Model $parent | |
* @param array $attributes | |
* @param string $table | |
* @param bool $exists | |
* | |
* @return CourseProgress|Pivot | |
*/ | |
public function newPivot(Model $parent, array $attributes, $table, $exists) | |
{ | |
if($table == 'course_progress') | |
return new CourseProgress($parent, $attributes, $table, $exists); | |
return new Pivot($parent, $attributes, $table, $exists); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment