-
app/Models/Module.php
Open in GitHubuse App\Completable; use Illuminate\Database\Eloquent\Model; class Module extends Model implements Completable { // public function completions() { return $this->morphMany(Completion::class, 'completable'); } // }
-
app/Models/User.php
Open in GitHubuse Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { // public function complete(Completable $completable) { return $this->completions()->create([ 'completable_id' => $completable->getKey(), 'completable_type' => $completable->getMorphClass(), ]); } // }
-
app/Models/Completion.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; class Completion extends Model { // public function completable() { return $this->morphTo(); } public function scopeModules($query) { return $query->where('completable_type', (new Module)->getMorphClass()); } public function scopeResources($query) { return $query->where('completable_type', (new Resource)->getMorphClass()); } public function scopeSkills($query) { return $query->where('completable_type', (new Skill)->getMorphClass()); } }