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


PHP Category::findOrFail方法代码示例

本文整理汇总了PHP中app\models\Category::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::findOrFail方法的具体用法?PHP Category::findOrFail怎么用?PHP Category::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Category的用法示例。


在下文中一共展示了Category::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: update

 /**
  * Update the specified resource in storage.
  *
  * @param  Requests\Backend\StoreCategoryRequest $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Requests\Backend\StoreCategoryRequest $request, $id)
 {
     $category = Category::findOrFail($id);
     $this->authorize($category);
     $category->update($request->all());
     return redirect()->action('Backend\\CategoryController@show', [$category]);
 }
开发者ID:niefufeng,项目名称:drip,代码行数:14,代码来源:CategoryController.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $user = auth()->check() ? auth()->user() : null;
     if (is_null($user)) {
         return redirect('/')->with('error', 'You need to be logged in');
     }
     if (!$user->can('break_upload_limit') && $user->videos()->newlyups()->count() >= 20) {
         return redirect()->back()->with('error', 'Uploadlimit reached')->withInput();
     }
     if (!$request->hasFile('file')) {
         return redirect()->back()->with('error', 'No file')->withInput();
     }
     $file = $request->file('file');
     if (!$file->isValid() || $file->getClientOriginalExtension() != 'webm' || $file->getMimeType() != 'video/webm') {
         return redirect()->back()->with('error', 'Invalid file');
     }
     if (!$user->can('break_max_filesize') && $file->getSize() > 30000000.0) {
         return redirect()->back()->with('error', 'File to big. Max 30MB')->withInput();
     }
     if (($v = Video::withTrashed()->where('hash', '=', sha1_file($file->getRealPath()))->first()) !== null) {
         return redirect($v->id)->with('error', 'Video already exists');
     }
     $file = $file->move(public_path() . '/b/', time() . '.webm');
     $hash = sha1_file($file->getRealPath());
     $video = new Video();
     $video->file = basename($file->getRealPath());
     $video->interpret = $request->get('interpret', null);
     $video->songtitle = $request->get('songtitle', null);
     $video->imgsource = $request->get('imgsource', null);
     $video->user()->associate($user);
     $video->category()->associate(Category::findOrFail($request->get('category')));
     $video->hash = $hash;
     $video->save();
     return redirect($video->id)->with('success', 'Upload successful');
 }
开发者ID:holzmaster,项目名称:w0bm.com,代码行数:41,代码来源:VideoController.php

示例3: addCategory

 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function addCategory($category_id = null)
 {
     if ($category_id) {
         return view('admin.partials.add_category', ['category' => Category::findOrFail($category_id)]);
     } else {
         return view('admin.partials.add_category');
     }
 }
开发者ID:nandha007,项目名称:tnbooks.in,代码行数:13,代码来源:AdminController.php

示例4: show

 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $category = Category::findOrFail($id);
     $paginator = $category->posts()->paginate(9);
     $posts = $paginator->getCollection();
     $data = fractal()->collection($posts)->transformWith(new PostTransformer())->includeUser()->includeCategories()->paginateWith(new IlluminatePaginatorAdapter($paginator))->toArray();
     return $this->respond($data);
 }
开发者ID:elieandraos,项目名称:project-evey,代码行数:14,代码来源:CategoriesController.php

示例5: destroy

 public function destroy(Request $request, $id)
 {
     try {
         $category = Category::findOrFail($id)->delete();
         session()->flash('flash_success', 'Delete successful!');
     } catch (ModelNotFoundException $e) {
         session()->flash('flash_error', 'Delete failed. The category you are trying to delete cannot be found.');
     }
     return redirect('/categories');
 }
开发者ID:jsnulla,项目名称:fels_rush,代码行数:10,代码来源:CategoryController.php

示例6: start

 /**
  * Displays category selection for a new request.
  *
  * @param null|int|string $categoryId
  *
  * @return \Illuminate\View\View
  */
 public function start($categoryId = null)
 {
     if (is_null($categoryId)) {
         $category = $this->category;
     } else {
         $category = $this->category->findOrFail($categoryId);
     }
     $categories = $this->presenter->tableCategories($this->inquiry, $category);
     return view('pages.inquiries.start', compact('categories'));
 }
开发者ID:stevebauman,项目名称:ithub,代码行数:17,代码来源:InquiryController.php

示例7: delete

 public function delete($id)
 {
     $id = intval($id);
     $category = Category::findOrFail($id);
     if ($category->delete()) {
         return Redirect::back()->withResult('delete succeed');
     } else {
         return Redirect::back()->withResult('delete failed');
     }
 }
开发者ID:Albertao,项目名称:myblog,代码行数:10,代码来源:CategoryAdminController.php

示例8: category

 /**
  * Display category videos
  *
  * @param  integer $id Category ID
  * @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse
  */
 public function category($id = false)
 {
     if ($id) {
         //we got an id, display the videos
         $selected_category = \App\Models\Category::findOrFail($id);
         $videos = $selected_category->videos;
         return view('partials.videos', compact('selected_category', 'videos'));
     }
     //don't display error message yet
     return redirect('/');
 }
开发者ID:poci-hu,项目名称:testtask,代码行数:17,代码来源:WelcomeController.php

示例9: destroy

 /**
  * Deletes the specified category.
  *
  * @param int|string $id
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($id)
 {
     $this->authorize('categories.destroy');
     $category = $this->category->findOrFail($id);
     if ($category->delete()) {
         flash()->success('Success!', 'Successfully deleted category.');
         return redirect()->route('inquiries.categories.index');
     }
     flash()->error('Error!', 'There was an issue deleting this category. Please try again.');
     return redirect()->route('inquiries.categories.index');
 }
开发者ID:stevebauman,项目名称:ithub,代码行数:18,代码来源:InquiryCategoryController.php

示例10: update

 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(StoreCategory $request, $id)
 {
     try {
         $category = Category::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         abort(404);
     }
     $category->update($request->all());
     $category->save();
     return redirect('categories')->with('alert-success', 'Название группы товаров обновлено');
 }
开发者ID:kostik34,项目名称:trains.shop,代码行数:17,代码来源:CategoryController.php

示例11: create

 public function create($category = 0)
 {
     $category = intval($category);
     if ($category > 0) {
         $category = Category::findOrFail($category);
     }
     $categories = Category::roots()->get();
     $user = Auth::user();
     $states = Location::states()->first();
     $regions = $states->children()->first();
     $locations = $regions->children;
     return view('pages.task.create', compact('category', 'categories', 'user', 'locations'));
 }
开发者ID:blozixdextr,项目名称:tuasist2,代码行数:13,代码来源:TaskController.php

示例12: trendingNews

 public function trendingNews($category_id = -1)
 {
     /*
      * the news most visited
      */
     if ($category_id < 0) {
         $query = News::with('category');
     } else {
         $category = Category::findOrFail($category_id);
         $query = $category->news()->with('category');
     }
     $trendingNews = $query->where('status', 'active')->orderBy('visit', 'desc')->take(2)->get();
     return $this->parseNewsList($trendingNews);
 }
开发者ID:cntjmj,项目名称:Laralog,代码行数:14,代码来源:NewsRepository.php

示例13: generateLessonWords

 public function generateLessonWords($request, $user)
 {
     // Fetch the ids of learned words to be used in querying the words that have not been learned yet
     $lessonWords = Category::findOrFail($request->category_id)->words()->userUnlearnedWords($user)->orderBy(\DB::raw('RAND()'))->take(20)->get();
     $lessonWordsToInsert = [];
     foreach ($lessonWords as $lessonWord) {
         $lessonWordsToInsert[] = ['lesson_id' => $request->lesson_id, 'word_id' => $lessonWord->id, 'created_at' => date('Y-m-d H:i:s')];
     }
     try {
         Eloquent::insert($lessonWordsToInsert);
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }
开发者ID:jsnulla,项目名称:fels_rush,代码行数:15,代码来源:LessonWord.php

示例14: store

 public function store(Request $request)
 {
     $availableQuestions = Category::findOrFail($request->category_id)->words()->userUnlearnedWords(auth()->user())->count();
     if ($availableQuestions < 20) {
         session()->flash('flash_error', 'There are not enough words left for your exam. Please try again later.');
         return redirect()->back();
     } else {
         try {
             $lesson = auth()->user()->lessons()->create(['category_id' => $request->category_id]);
         } catch (Exception $e) {
             session()->flash('flash_error', 'Your lesson could not be generated. Please try again later.');
             return redirect()->back();
         }
         // Route to LessonWordController to generate questions
         return redirect()->action('LessonWordController@create', ['lesson_id' => $lesson->id, 'category_id' => $lesson->category_id]);
     }
 }
开发者ID:jsnulla,项目名称:fels_rush,代码行数:17,代码来源:LessonController.php

示例15: game

 public function game()
 {
     //game already running
     if (!empty(session('word'))) {
         $data = session()->all();
         return view('game')->with(['alphabet' => $this->alphabet, 'blank' => implode('', $data['blank']), 'category' => $data['category'], 'mistakes' => $data['mistakes'], 'points' => $data['points']]);
     } else {
         if (empty(session('cat_id'))) {
             return redirect('/');
         }
         $category = Category::findOrFail(session('cat_id'));
         $category->load('words');
         $word = $category->words->random()->name;
         $word = preg_split('//u', $word, -1, PREG_SPLIT_NO_EMPTY);
         $answer = implode('', $word);
         $blank = array_fill(0, count($word), '_');
         $points = session('points') == 0 ? 0 : session('points');
         session(['word' => $word, 'blank' => $blank, 'mistakes' => 0, 'category' => $category->name, 'points' => $points, 'answer' => $answer]);
         return view('game')->with(['alphabet' => $this->alphabet, 'blank' => implode('', $blank), 'category' => $category->name, 'mistakes' => 0, 'points' => $points]);
     }
 }
开发者ID:Vuidaa,项目名称:kartuves,代码行数:21,代码来源:GameController.php


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