Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

app/Models/Module.php

Open in GitHub
use 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 GitHub
use 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 GitHub
use 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());
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.