Skip to content

Instantly share code, notes, and snippets.

@abdullahseba
Last active November 6, 2017 22:11
Show Gist options
  • Save abdullahseba/81a9b69ed82ce7e2fbe9568e3ebd915b to your computer and use it in GitHub Desktop.
Save abdullahseba/81a9b69ed82ce7e2fbe9568e3ebd915b to your computer and use it in GitHub Desktop.
<?php
namespace UserFrosting\Sprinkle\UfWidget\Database\Models;
use UserFrosting\Sprinkle\Account\Database\Models\User as BaseUser;
class User extends BaseUser
{
protected $fillable = [
'user_name',
'first_name',
'last_name',
'email',
'locale',
'theme',
'group_id',
'flag_verified',
'flag_enabled',
'last_activity_id',
'password',
'deleted_at',
'widget_id'
];
public function scopeJoinWidgets($query)
{
/** @var UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
$classMapper = static::$ci->classMapper;
$userWidgetsTable = $classMapper->createInstance('user_widget')->getTable();
$widgetsTable = $classMapper->createInstance('widget')->getTable();
$query = $query->select("$widgetsTable.*");
$query = $query->leftJoin($widgetsTable, "$userWidgetsTable.content_template_id", '=', "$widgetsTable.id");
return $query;
}
public function widgets()
{
/** @var UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
$classMapper = static::$ci->classMapper;
return $this->belongsTo($classMapper->getClassMapping('widgets'), 'widget_id');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment