本文整理汇总了PHP中app\User::with方法的典型用法代码示例。如果您正苦于以下问题:PHP User::with方法的具体用法?PHP User::with怎么用?PHP User::with使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\User
的用法示例。
在下文中一共展示了User::with方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateLevel
public function updateLevel(Request $request)
{
$user = User::with(['level', 'courses' => function ($query) {
$query->where('level', '1')->where('validated', 1);
}])->where('id', $request->id)->first();
$oldLevel = ucfirst($user->level->name);
if (Auth::check()) {
if (Auth::user()->id != $user->id) {
if (Auth::user()->level_id == 5 || Auth::user()->level_id == 4 && $user->level_id < 4) {
if ($request->level < 3 && $user->courses->count() > 0) {
Flash::error('Impossible de rétrograder cet utilisateur à ce level car il est professeur de ' . $user->courses->count() . ' cours.');
return Redirect::back();
}
$newLevel = ucfirst(Level::find($request->level)->name);
$modif = $user->level_id > $request->level ? 'downgraded' : 'upgraded';
$user->level_id = $request->level;
$user->save();
Flash::success('Le changement a été effectué avec succès.');
makeModification('users', printUserLinkV2($user) . ' as been ' . $modif . ' from ' . $oldLevel . ' to ' . $newLevel . '.');
return Redirect::back();
}
}
}
Flash::error('Vous n\'avez pas les droits nécéssaires pour cela.');
return Redirect::back();
}
示例2: index
public function index(User $user, $type = null)
{
if (!Entrust::can('manage_user')) {
return redirect('/dashboard')->withErrors(config('constants.NA'));
}
$query = $user->with('roles');
if ($type != null) {
$query->whereHas('roles', function ($qry) use($type) {
$qry->where('name', '=', $type);
});
}
$users = $query->get();
$col_data = array();
$col_heads = array(trans('messages.Option'), trans('messages.Name'), trans('messages.Username'), trans('messages.Email'), trans('messages.Department'), trans('messages.Role'));
$col_heads = Helper::putCustomHeads($this->form, $col_heads);
$col_ids = Helper::getCustomColId($this->form);
$values = Helper::fetchCustomValues($this->form);
$token = csrf_token();
foreach ($users as $user) {
foreach ($user->roles as $role) {
$role_name = $role->display_name;
}
$cols = array('<div class="btn-group btn-group-xs">' . '<a href="/user/' . $user->id . '" class="btn btn-default btn-xs" data-toggle="tooltip" title="View"> <i class="fa fa-share"></i></a> ' . '<a href="/user/welcomeEmail/' . $user->id . '/' . $token . '" class="btn btn-default btn-xs" data-toggle="tooltip" title="Send Welcome Email"> <i class="fa fa-envelope"></i></a>' . '<a href="/user/' . $user->id . '/edit" class="btn btn-default btn-xs" data-toggle="tooltip" title="Edit"> <i class="fa fa-edit"></i></a> ' . delete_form(['user.destroy', $user->id]) . '</div>', $user->name, $user->username, $user->email, $user->Profile->department_id != null ? $user->Profile->Department->department_name : '', $role_name);
$id = $user->id;
foreach ($col_ids as $col_id) {
array_push($cols, isset($values[$id][$col_id]) ? $values[$id][$col_id] : '');
}
$col_data[] = $cols;
}
Helper::writeResult($col_data);
return view('user.index', compact('col_heads'));
}
示例3: showGroup
public function showGroup()
{
$customer_id = Auth::user()->customer->id;
$group = User::with('unpaidOrders')->where('customer_id', $customer_id)->get();
$spendings = Customer::find($customer_id)->unpaidOrders->sum('total_price');
return view('account.group', compact('group', 'spendings'));
}
示例4: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$this->authorize('users-edit');
$user = User::with('roles')->findOrFail($id);
$roles = Role::orderBy('display_name')->get();
return view('users.edit', compact('roles', 'user'));
}
示例5: show
public function show($id)
{
//show single
$record = User::with($this->related)->findOrFail($id);
$record['fullname'] = $record->fullname;
return $record;
}
示例6: show
/**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function show(Request $request)
{
$questions = ProfileQuestion::join('profiles_answers', 'profiles_questions.id', '=', 'profiles_answers.profile_question_id')->where('profiles_answers.user_id', $request->id)->get();
$user = User::with('achievements')->where('users.id', $request->id)->first();
//$users = User::where('category_id', 2)->where('id', '<>', Auth::user()->id)->get();
return view('members/show', ['user' => $user, 'questions' => $questions]);
}
示例7: getAll
public function getAll()
{
// return User::with('roles')->orderBy('first_name')->get();
return User::with('roles')->whereHas('roles', function ($q) {
$q->where('name', '!=', 'Medico')->where('name', '!=', 'Farmacista');
})->orderBy('first_name')->get();
}
示例8: getUserByIdWithRole
public function getUserByIdWithRole($id)
{
$users = User::with('userRole')->with(['projects' => function ($q) {
return $q->selectRaw('group_concat(projects.id) as project_ids');
}])->find($id);
return $users;
}
示例9: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
abort_unauthorized($id);
$user = User::with('sessions')->findOrFail($id);
$user->currentSessionHash = \App\ValidSession::generateFingerprint(request())['hash'];
return $user;
}
示例10: profile
public function profile()
{
$user_id = app('auth')->user()->getKey();
$user = User::with('wishlists', 'wishlists.givingCircle', 'wishlists.items')->where('id', '=', $user_id)->get()->first();
js(['user' => $user->getAttributes(), 'wishlists' => $user->wishlists->toArray()]);
return view('profile', ['user' => $user]);
}
示例11: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$all_user_details = User::with('uploadDetail')->get();
$users = array();
foreach ($all_user_details as $key => $value) {
$users[$key]['id'] = $value->id;
$users[$key]['name'] = $value->name;
$users[$key]['email'] = $value->email;
$users[$key]['username'] = $value->username;
$users[$key]['age'] = $value->age;
$users[$key]['allow_payment'] = $value->name;
$users[$key]['created_at'] = $value->created_at;
foreach ($all_user_details[$key]->uploadDetail as $key1 => $value1) {
$users[$key]['upload_detail'][$key1]['id'] = $value1->id;
$users[$key]['upload_detail'][$key1]['user_id'] = $value1->user_id;
$users[$key]['upload_detail'][$key1]['file_destination'] = $value1->file_destination;
$users[$key]['upload_detail'][$key1]['file_name'] = $value1->file_name;
$users[$key]['upload_detail'][$key1]['status'] = $value1->status;
$users[$key]['upload_detail'][$key1]['payment_status'] = $value1->payment_status;
$users[$key]['upload_detail'][$key1]['is_selected'] = $value1->is_selected;
$users[$key]['upload_detail'][$key1]['season_name'] = $value1->season_name;
$users[$key]['upload_detail'][$key1]['created_at'] = $value1->created_at->toDateTimeString();
$users[$key]['upload_detail'][$key1]['updated_at'] = $value1->updated_at->toDateTimeString();
}
}
// return $users;
$data = array("users" => $users);
// return $all_user_details;
return view('users', $data);
}
示例12: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$users = User::with('roles')->get();
$roles = Role::all();
return view('rbac.user')->with(['users' => $users, 'roles' => $roles]);
// return view('rbac.user');
}
示例13: getEmployee
public function getEmployee()
{
if (!empty($this->employee)) {
return $this->employee;
}
return $this->employee = User::with('Employee')->whereId($this->user->id)->first();
}
示例14: users
public function users()
{
$users = User::with('organization', 'roles')->get(['id', 'name', 'email', 'organization_id']);
$orgs = Organization::all();
$roles = Role::all();
return Datatables::of($users)->addColumn('organization', function ($user) use($orgs) {
$orgSelect = '<select name="organization" class="form-control organization" data-userid="' . $user->id . '">';
foreach ($orgs as $org) {
$select = "";
if ($org->id == $user->organization_id) {
$select = 'selected';
}
$orgSelect .= '<option value="' . $org->id . '" ' . $select . '>' . $org->name . '</option>';
}
$orgSelect .= '</select>';
//return '<a href="#edit-'.$user->id.'" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> '.$user->organization->name.'</a>';
return $orgSelect;
})->addColumn('role', function ($user) use($roles) {
$roleSelect = '<select name="organization" class="form-control role" data-userid="' . $user->id . '">';
foreach ($roles as $role) {
$select = "";
if ($user->hasRole($role->name)) {
$select = 'selected';
}
$roleSelect .= '<option value="' . $role->id . '" ' . $select . '>' . $role->display_name . '</option>';
}
$roleSelect .= '</select>';
//return '<a href="#edit-'.$user->id.'" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> '.$user->roles[0]->display_name.'</a>';
return $roleSelect;
})->removeColumn('id')->removeColumn('organization_id')->make(true);
}
示例15: getAll
public function getAll()
{
// Get All Users
$users = User::with('role')->get();
// Passing data to response service
return $this->responseService->returnMessage($users, 'No Users were Found.');
}