本文整理汇总了PHP中app\User::findorFail方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findorFail方法的具体用法?PHP User::findorFail怎么用?PHP User::findorFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\User
的用法示例。
在下文中一共展示了User::findorFail方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update($id, Requests\UserRequest $request)
{
$user = User::findorFail($id);
$user->update($request->all());
session()->flash('flash_message', 'User Successfully Updated!');
return redirect('users/' . $id . '');
}
示例2: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(PostCreate $request)
{
$user = User::findorFail(Auth::user()->id);
$post = new Post();
$post->title = $request->input('title');
$post->body = $request->input('body');
$user->Post()->save($post);
$imageName = $post->id . '.' . $request->file('image')->getClientOriginalExtension();
$request->file('image')->move(base_path() . '/public/Images', $imageName);
return redirect('posts');
}
示例3: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$user = User::findorFail(1);
$trans = new Transaction();
foreach ($request->all() as $key => $value) {
$trans->{$key} = $value;
}
//$transaction = $user->transaction()->create($request->all());
$newtransaction = $user->transaction()->save($trans);
return response()->success(compact('newtransaction'));
}
示例4: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$user = User::findorFail(1);
$name = $user->first_name;
return $user->getFirstName($name);
}
示例5: stores
public function stores($id)
{
$user = User::findorFail($id);
return view('user.stores', compact('user'));
}
示例6: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$user = User::findorFail($id);
$user->delete();
return redirect()->route('users.index');
}
示例7: userprofilephoto
public function userprofilephoto(Request $request, $id)
{
//$file= $request->file('file');
//$name= time(). $file->getClientOriginalName();
//$file->move('biz/profile/photos', $name);
//$biz= \App\Biz::findOrFail($id);
//$biz->photos()->create(['path'=>"/biz/photos/{$name}"]);
//return 'Done';
$picture = ['image' => $request->file('image')];
$rules = ['image' => 'required|image|mimes:jpeg,jpg,bmp,png,gif'];
$validator = \Validator::make($picture, $rules);
if ($validator->passes()) {
$user_id = $request->get('id');
$user = \App\User::findorFail($user_id);
$profilePhoto = $user->profilePhoto;
$image = $request->file('image');
$name = time() . $image->getClientOriginalName();
$image->move('user/profile', $name);
if (!isset($profilePhoto->image)) {
$pic = new \App\ProfilePhoto();
$pic->image = 'user/profile/' . $name;
$user->profilePhoto()->save($pic);
return \Redirect::back()->with('message', 'profile photo added!!!');
}
if (isset($profilePhoto->image)) {
$profilePhoto->image = 'user/profile/' . $name;
$user->profilePhoto()->save($profilePhoto);
return \Redirect::back()->with('message', ' profile photo updated!');
}
}
return \Redirect::back()->with('errors', $validator->messages());
}
示例8: show
/**
* Show the application dashboard to the user.
*
* @return Response
*/
public function show($id)
{
$user = User::findorFail($id);
$tasks = Task::where('assignedTo', $id)->get();
return view('users.show', compact('user', 'tasks'));
}
示例9: update
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update($id, EditUserRequest $request)
{
$role = Auth::user()->role_id;
$user_id = Auth::user()->id;
if ($role == 3 && $user_id != $id) {
\Session::flash('message', 'Not Authorized to edit other users profile');
\Session::flash('message-type', 'danger');
return redirect('/user/' . $user_id);
}
$input = $request->all();
$users = User::findorFail($id);
if (isset($input['password'])) {
$input['password'] = bcrypt($input['password']);
$users->update($input);
} else {
unset($input['password']);
$users->update($input);
}
\Session::flash('message', 'User has been updated!');
\Session::flash('message-type', 'success');
return redirect('/user/' . $id);
}