本文整理汇总了PHP中RainLab\User\Models\User::creating方法的典型用法代码示例。如果您正苦于以下问题:PHP User::creating方法的具体用法?PHP User::creating怎么用?PHP User::creating使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RainLab\User\Models\User
的用法示例。
在下文中一共展示了User::creating方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* {@inheritDoc}
*/
public function boot()
{
// Handle locations upon login
$this->registerLocation();
// Register timezone settings
date_default_timezone_set(Settings::get('timezone', Config::get('app.timezone')));
// Register ServiceProviders
App::register('DMA\\Friends\\FriendsServiceProvider');
App::register('Maatwebsite\\Excel\\ExcelServiceProvider');
// Register aliases
$alias = AliasLoader::getInstance();
$alias->alias('Excel', 'Maatwebsite\\Excel\\Facades\\Excel');
// Register Event Subscribers
$subscriber = new FriendsEventHandler();
Event::subscribe($subscriber);
// Bind user and point events to trigger user synchronization with MailChimp
MailChimpIntegration::bindEvents();
// Generate barcode_id when a user object is created
// TODO: Migrate when user plugin is forked
User::creating(function ($user) {
if (empty($user->barcode_id)) {
$user->barcode_id = substr(md5($user->email), 0, 9);
}
});
// Extend the user model to support our custom metadata
User::extend(function ($model) {
$model->hasOne['metadata'] = ['DMA\\Friends\\Models\\Usermeta', 'key' => 'user_id'];
$model->hasMany['activityLogs'] = ['DMA\\Friends\\Models\\ActivityLog'];
$model->hasMany['bookmarks'] = ['DMA\\Friends\\Models\\Bookmark'];
$model->hasMany['notifications'] = ['DMA\\Friends\\Models\\Notification'];
$model->hasMany['rates'] = ['DMA\\Friends\\Models\\UserRate'];
$model->belongsToMany['activities'] = ['DMA\\Friends\\Models\\Activity', 'table' => 'dma_friends_activity_user', 'user_id', 'activity_id', 'timestamps' => true, 'order' => 'dma_friends_activity_user.created_at desc'];
$model->belongsToMany['steps'] = ['DMA\\Friends\\Models\\Step', 'table' => 'dma_friends_step_user', 'user_id', 'step_id', 'timestamps' => true, 'order' => 'dma_friends_step_user.created_at desc'];
$model->belongsToMany['badges'] = ['DMA\\Friends\\Models\\Badge', 'table' => 'dma_friends_badge_user', 'user_id', 'badge_id', 'timestamps' => true, 'order' => 'dma_friends_badge_user.created_at desc'];
$model->belongsToMany['rewards'] = ['DMA\\Friends\\Models\\Reward', 'table' => 'dma_friends_reward_user', 'user_id', 'reward_id', 'timestamps' => true, 'order' => 'dma_friends_reward_user.created_at desc'];
$model->belongsToMany['groups'] = ['DMA\\Friends\\Models\\UserGroup', 'table' => 'dma_friends_users_groups', 'key' => 'user_id', 'foreignKey' => 'group_id', 'pivot' => ['membership_status']];
});
// Extend User fields
$context = $this;
Event::listen('backend.form.extendFields', function ($widget) use($context) {
$context->extendedUserFields($widget);
$context->extendedSettingFields($widget);
});
Event::listen('backend.list.extendColumns', function ($widget) {
if (!$widget->getController() instanceof \RainLab\User\Controllers\Users) {
return;
}
$widget->addColumns(['barcode_id' => ['label' => 'Barcode ID'], 'full_name' => ['label' => 'Full Name', 'relation' => 'metadata', 'sortable' => false, 'select' => "concat(first_name, ' ', last_name)", 'searchable' => true], 'first_name' => ['label' => 'First Name', 'relation' => 'metadata', 'select' => '@first_name', 'searchable' => true], 'last_name' => ['label' => 'Last Name', 'relation' => 'metadata', 'select' => '@last_name', 'searchable' => true], 'points' => ['label' => 'Points'], 'zip' => ['label' => 'Zip'], 'current_member_number' => ['label' => 'Membership ID', 'relation' => 'metadata', 'select' => '@current_member_number']]);
});
}