本文整理匯總了PHP中RainLab\User\Models\User::withTrashed方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::withTrashed方法的具體用法?PHP User::withTrashed怎麽用?PHP User::withTrashed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類RainLab\User\Models\User
的用法示例。
在下文中一共展示了User::withTrashed方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: up
public function up()
{
Schema::table('users', function ($table) {
$table->string('login')->nullable()->index();
});
/*
* Set login for existing users
*/
$users = User::withTrashed()->get();
foreach ($users as $user) {
$user->login = $user->email;
$user->save();
}
Schema::table('users', function ($table) {
$table->unique('login');
});
}
示例2: index_onBulkAction
/**
* Perform bulk action on selected users
*/
public function index_onBulkAction()
{
if (($bulkAction = post('action')) && ($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
foreach ($checkedIds as $userId) {
if (!($user = User::withTrashed()->find($userId))) {
continue;
}
switch ($bulkAction) {
case 'delete':
$user->forceDelete();
break;
case 'deactivate':
$user->delete();
break;
case 'restore':
$user->restore();
break;
case 'ban':
$user->ban();
break;
case 'unban':
$user->unban();
break;
}
}
Flash::success(Lang::get('rainlab.user::lang.users.' . $bulkAction . '_selected_success'));
} else {
Flash::error(Lang::get('rainlab.user::lang.users.' . $bulkAction . '_selected_empty'));
}
return $this->listRefresh();
}