本文整理汇总了PHP中app\User::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findOrFail方法的具体用法?PHP User::findOrFail怎么用?PHP User::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\User
的用法示例。
在下文中一共展示了User::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: profile
public function profile($id)
{
$images = Auth::User()->uploaded_pictures;
$categories = Category::lists('category_name', 'category_id');
$user = User::findOrFail($id);
return view('templates/singleProfile')->with(compact('user', 'images', 'categories'));
}
示例2: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
// bind article
$router->model('article', 'App\\Article');
$router->bind('admin.article', function ($id) {
return \App\Article::findOrFail($id);
});
// bind category
$router->model('category', 'App\\Category');
$router->bind('admin.category', function ($id) {
return \App\Category::findOrFail($id);
});
// bind language
$router->model('language', 'App\\Language');
$router->bind('admin.language', function ($id) {
return \App\Language::findOrFail($id);
});
// bind language
$router->model('page', 'App\\Page');
$router->bind('admin.page', function ($id) {
return \App\Page::findOrFail($id);
});
// bind setting
$router->model('setting', 'App\\Setting');
$router->bind('admin.setting', function ($id) {
return \App\Setting::findOrFail($id);
});
// bind user
$router->model('user', 'App\\User');
$router->bind('admin.user', function ($id) {
return \App\User::findOrFail($id);
});
parent::boot($router);
}
示例3: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Like::creating(function ($attribute) {
// -1 like_left for media
$media = Media::findOrFail($attribute->media_id);
$media->likes_left = $media->likes_left - 1;
$media->save();
// +1 credit for liker of media
$user = User::findOrFail($attribute->user_id);
if ($user->pro_user) {
$user->credit = $user->credit + 3;
//for pro user
} else {
$user->credit = $user->credit + 1;
}
$user->save();
});
Follow::creating(function ($attribute) {
// -1 like_left for media
$user = User::findOrFail($attribute->follow_id);
$user->followers_left = $user->followers_left - 1;
$user->save();
// +1 credit for liker of media
$user = User::findOrFail($attribute->user_id);
if ($user->pro_user) {
$user->credit = $user->credit + 3;
//for pro user
} else {
$user->credit = $user->credit + 1;
}
$user->save();
});
}
示例4: myInstitutions
public function myInstitutions($id)
{
$user = User::findOrFail($id);
$teacher = $user->institutions(1)->get();
$manager = $user->institutions(2)->get();
return view('public.myInstitutions')->with('username', $user->fullName)->with('teacher', $teacher)->with('manager', $manager);
}
示例5: store
public function store($id)
{
$user = User::findOrFail($id);
$input = Input::all();
$this->message->storeMessage($user, $input);
return redirect('messages');
}
示例6: updateUser
public function updateUser($id, Request $request)
{
$user = User::findOrFail($id);
// return $request->all();
$user->update(['username' => $request->username, 'email' => $request->email, 'usertype' => $request->usertype]);
return redirect('/adminPanel/userMaintenance');
}
示例7: getNguoiGuiAttribute
public static function getNguoiGuiAttribute($id)
{
$user = User::findOrFail($id);
$phong = Danhmucphong::where('id', $user->phong_id)->value('name');
$nguoigui = $user->name . ' - ' . $phong;
return $nguoigui;
}
示例8: update
/**
* Update the specified resource in storage.
*
* @param int $id
*
* @return Response
*/
public function update($id, Request $request)
{
$user = User::findOrFail($id);
$user->update($request->all());
Session::flash('flash_message', 'User updated!');
return redirect('admin/user');
}
示例9: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store($id, Request $request)
{
$this->validate($request, ['authuser_id' => 'required']);
$connectRequest = new ConnectRequest($request->all());
User::findOrFail($id)->connectRequests()->save($connectRequest);
return redirect('/users');
}
示例10: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
//
parent::boot($router);
$router->bind('articles', function ($id) {
$article = Article::findOrFail($id);
// If the owner return all articles else return only published.
if (Auth::user() && $article->user_id === Auth::user()->id) {
$articles = Article::findOrFail($id);
} else {
$articles = Article::published()->findOrFail($id);
}
return $articles;
});
$router->bind('questions', function ($id) {
return Question::findOrFail($id);
});
$router->bind('answers', function ($id) {
return Answer::findOrFail($id);
});
$router->bind('tags', function ($name) {
return Tag::where('name', $name)->firstOrFail();
});
$router->bind('users', function ($id) {
return User::findOrFail($id);
});
}
示例11: updateProfile
public function updateProfile(Request $request, $user_id)
{
try {
$validator = Validator::make($request->all(), ['name' => 'required|between:4,100', 'uploadAvatar' => 'max:1024000|mimes:jpeg,jpg,png,image/jpeg']);
if ($validator->fails()) {
//$message = ['error' => true, 'body' => implode('<br>', $validator->errors()->all())];
$message = implode('<br>', $validator->errors()->all());
throw new Exception($message);
//return redirect()->route('userViewProfile', ['user_id' => $user_id])
// ->with('scopeMessage', $message);
}
$profile = User::findOrFail($user_id);
$this->authorize('update', $profile);
$profile->name = $request->input('name');
if ($request->hasFile('uploadAvatar')) {
$this->processAvatar($request, $profile);
}
$profile->save();
$scopeMessage = ['success' => true, 'body' => 'User profile has been successfully updated.'];
return redirect()->route('userViewProfile', ['user_id' => $user_id])->with('scopeMessage', $scopeMessage);
} catch (Exception $e) {
$scopeMessage = ['error' => true, 'body' => $e->getMessage()];
return redirect()->route('userViewProfile', ['user_id' => $user_id])->with('scopeMessage', $scopeMessage);
}
}
示例12: rules
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$type = $this->input('type_request');
if ($type == 0) {
return ['name' => 'required|max:255|unique:companies', 'email' => 'required|email|unique:users', 'first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'password' => 'required|min:5|max:20|same:confirm_password', 'confirm_password' => 'required|min:5'];
} else {
$email = $this->input('email');
$name = $this->input('name');
$user_id = $this->input('user_id');
$company_id = $this->input('company_id');
$company = Company::findOrFail($company_id);
$user = User::findOrFail($user_id);
if ($user->email == $email) {
if ($company->name == $name) {
return ['first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'password' => 'min:5|max:20', 'new_password' => 'min:5|same:confirm_password'];
} else {
return ['name' => 'required|max:255|unique:companies', 'first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'password' => 'min:5|max:20', 'new_password' => 'min:5|same:confirm_password'];
}
} else {
if ($company->name == $name) {
return ['email' => 'required|email|unique:users', 'first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'password' => 'min:5|max:20', 'new_password' => 'min:5|same:confirm_password'];
} else {
return ['name' => 'required|max:255|unique:companies', 'email' => 'required|email|unique:users', 'first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'password' => 'min:5|max:20', 'new_password' => 'min:5|same:confirm_password'];
}
}
}
}
示例13: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
parent::boot($router);
$router->bind('admin', function ($id) {
return \App\User::findOrFail($id);
});
}
示例14: freigabe
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function freigabe($experiment)
{
$experiment = Experiment::findOrFail($experiment);
$rechte = json_decode($experiment->group, true);
$editUser = array();
$viewUser = array();
$users = array();
if (is_array($rechte)) {
$keys = array("edit", "view");
foreach ($keys as $key) {
if (array_key_exists($key, $rechte)) {
foreach ($rechte[$key] as $recht) {
$users[$recht] = User::findOrFail($recht);
if ($key == "edit") {
$editUser[] = $recht;
}
if ($key == "view") {
$viewUser[] = $recht;
}
}
}
}
}
return view("freigabe.index", compact('experiment', 'editUser', 'viewUser', 'users'));
}
示例15: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
$user = User::findOrFail($id);
$user->delete();
return 1;
}