本文整理汇总了PHP中app\models\User::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findOrFail方法的具体用法?PHP User::findOrFail怎么用?PHP User::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\User
的用法示例。
在下文中一共展示了User::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: destroy
/**
* Removes the specified permission from the specified user.
*
* @param int|string $userId
* @param int|string $permissionId
*
* @return int
*/
public function destroy($userId, $permissionId)
{
$this->authorize('admin.users.permissions.destroy');
$user = $this->user->findOrFail($userId);
$permission = $user->permissions()->findOrFail($permissionId);
return $user->permissions()->detach($permission);
}
示例2: destroy
/**
* Removes the specified permission from the specified user.
*
* @param int|string $userId
* @param int|string $permissionId
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy($userId, $permissionId)
{
$this->authorize('admin.users.permissions.destroy');
$user = $this->user->findOrFail($userId);
$permission = $user->permissions()->findOrFail($permissionId);
if ($user->permissions()->detach($permission)) {
flash()->success('Success!', 'Successfully removed permission.');
return redirect()->route('admin.users.show', [$userId]);
}
flash()->error('Error!', 'There was an issue removing this permission. Please try again.');
return redirect()->route('admin.users.show', [$userId]);
}
示例3: postUpdate
/**
* 更新密码.
*
* @param Request $request
* @param int $id
*
* @return Response
*/
public function postUpdate(Request $request, $id)
{
$rules = ['password' => 'required|min:6|confirmed'];
$this->validate($request, $rules);
$user = User::findOrFail($id)->update(['password' => Hash::make($request->password)]);
return redirect()->back()->withMessage('更新成功!');
}
示例4: handle
/**
* Execute the job.
*
*/
public function handle()
{
$user = User::findOrFail(1);
$status = 1;
$mail = event(new LoginEvent($user, $status));
return $mail;
}
示例5: send
public static function send($from, $to, $subject, $content)
{
if (empty($subject)) {
return 'Subject must not be empty';
}
if (empty($content)) {
return 'Content must not be empty';
}
try {
if (!is_object($from)) {
$from = User::findOrFail($from);
}
if (!is_object($to)) {
$to = User::findOrFail($to);
}
} catch (ModelNotFoundException $e) {
return false;
}
$message = new static();
$message->from = $from->id;
$message->to = $to->id;
$message->subject = $subject;
$message->content = $content;
$message->save();
return $message;
}
示例6: update
public function update($userId, Request $request)
{
$user = User::findOrFail($userId);
$user->fill($request->all());
$user->save();
return Redirect::back()->with(['success' => 'User ' . $user->name . ' was changed']);
}
示例7: postEdit
/**
* Update user details
*
* @param Request $request
* @return Response
*/
public function postEdit(Request $request)
{
$data = $request->all();
$user = User::findOrFail(Auth::user()->id);
$user->fill($data)->save();
$user->touch();
return redirect()->action('UserController@getEdit')->with('message', array('info', 'Profile information updated.'));
}
示例8: putUseractive
public function putUseractive($periodo_id)
{
$user = User::fromToken();
$usuario = User::findOrFail($user->user_id);
$usuario->periodo_id = $periodo_id;
$usuario->save();
return $usuario;
}
示例9: update
/**
* Update a user.
*
* @param UserUpdateRequest $request
* @param int $id
*
* @return \Illuminate\Http\JsonResponse
*/
public function update(UserUpdateRequest $request, $id)
{
$data = $request->only('name', 'email');
if ($password = $request->input('password')) {
$data['password'] = Hash::make($password);
}
return response()->json(User::findOrFail($id)->update($data));
}
示例10: show
public function show($id){
try{
$user = User::findOrFail($id);
return view('home',['user' => $user]);
}catch(ModelNotFoundException $e){
return view('errors.404');
}
}
示例11: show
public function show($id)
{
$user = User::findOrFail($id);
echo "{$user->name}" . "<br>";
echo "{$user->open_id}" . "<br>";
echo "{$user->introduction}" . "<br>";
echo $user->favorites;
}
示例12: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
#find user
$user = User::findOrFail($id);
#skin to call
$view = 'skins.skin_b.user.show';
#call the view with the user
return view($view, ['user' => $user]);
}
示例13: get
public function get($id)
{
try {
$user = User::findOrFail($id);
} catch (\Exception $e) {
return parent::response(['success' => false, 'error' => "User not found"]);
}
return $user;
}
示例14: update
/**
* Approves startup membership for the specified user
* Get /startups/{startupUrl}/membership/{userId}/approve
*
* @param $startup
* @param $user
* @param $action
* @return Response
*/
public function update($startup, $user, $action)
{
$startup = Startup::where('url', '=', $startup)->firstOrFail();
if ($this->currentUserIsOwner($startup->owner)) {
$user = User::findOrFail($user);
$this->dispatch(new UpdateMembership($user, $startup, $action));
}
return Redirect::route('startups.show', ['url' => $startup->url]);
}
示例15: destroyUser
public function destroyUser($id)
{
$authUser = Auth::user();
$user = User::findOrFail($id);
if ($user->id == $authUser->id) {
return -1;
}
$result = User::destroy($id);
return $result;
}