当前位置: 首页>>代码示例>>PHP>>正文


PHP User::findOrFail方法代码示例

本文整理汇总了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'));
 }
开发者ID:Omniarate,项目名称:omniarate.dv,代码行数:7,代码来源:PagesController.php

示例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);
 }
开发者ID:abada,项目名称:laravel-5-simple-cms,代码行数:40,代码来源:RouteServiceProvider.php

示例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();
     });
 }
开发者ID:jubaedprince,项目名称:instaappAPI,代码行数:38,代码来源:AppServiceProvider.php

示例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);
 }
开发者ID:salvomulas,项目名称:angryproton,代码行数:7,代码来源:InstitutionController.php

示例5: store

 public function store($id)
 {
     $user = User::findOrFail($id);
     $input = Input::all();
     $this->message->storeMessage($user, $input);
     return redirect('messages');
 }
开发者ID:mathewsandi,项目名称:Practice,代码行数:7,代码来源:MessageController.php

示例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');
 }
开发者ID:KunwarSingh,项目名称:Summer-15-Intern-Work,代码行数:7,代码来源:UserMaintController.php

示例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;
 }
开发者ID:thaigialai1987,项目名称:qlcv,代码行数:7,代码来源:Mymail.php

示例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');
 }
开发者ID:thibaultvanc,项目名称:organit,代码行数:14,代码来源:UserController.php

示例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');
 }
开发者ID:RyOberfelder,项目名称:ccard,代码行数:12,代码来源:ConnectRequestsController.php

示例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);
     });
 }
开发者ID:nilstr,项目名称:stackoverflow-clone,代码行数:33,代码来源:RouteServiceProvider.php

示例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);
     }
 }
开发者ID:cntjmj,项目名称:Laralog,代码行数:25,代码来源:UserController.php

示例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'];
             }
         }
     }
 }
开发者ID:villar88,项目名称:salesperformanceindicator,代码行数:32,代码来源:UpdateAndSaveCompany.php

示例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);
     });
 }
开发者ID:jxjjdccj,项目名称:StuGradeWithLaravel5,代码行数:13,代码来源:RouteServiceProvider.php

示例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'));
 }
开发者ID:jg29,项目名称:bpmn_experiment,代码行数:30,代码来源:FreigabeController.php

示例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;
 }
开发者ID:urbanix,项目名称:contract-payments-demo,代码行数:13,代码来源:UserController.php


注:本文中的app\User::findOrFail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。