當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Category::whereSlug方法代碼示例

本文整理匯總了PHP中app\Category::whereSlug方法的典型用法代碼示例。如果您正苦於以下問題:PHP Category::whereSlug方法的具體用法?PHP Category::whereSlug怎麽用?PHP Category::whereSlug使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\Category的用法示例。


在下文中一共展示了Category::whereSlug方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: index

 /**
  * Display a listing of categories and the category members (parent-children) and their social media.
  *
  * @return Response
  */
 public function index($slug)
 {
     // get links in footer
     $linksArr = \App\Links::orderBy('rank', 'ASC')->lists('link', 'name');
     if ($slug != 'all') {
         $catObj = Category::whereSlug($slug)->first();
         if (is_null($catObj)) {
             \Session::flash('message', 'Invalid category');
             return redirect('/socialmedia/all');
         }
         $catPathArr = $catObj->getCategoryPath($slug);
         $catArr = $catObj->getChildren($catObj->id);
     } else {
         $catPathArr = array();
         $catObj = new Category();
         $catArr = $catObj->getParents();
     }
     $getChildren = $this->getChildrenBool($catPathArr, $slug, $catObj);
     // eg. get the teammates on the Lakers, don't get teams in the Pacific Coast division
     if ($getChildren) {
         $memberArr = $this->memberObj->getMembersWithinSingleCategory($catObj->id);
         list($memberArr, $contentArr) = $this->memberSocialObj->getSocialMediaWithMemberIds($memberArr);
         return view('socialmedia.child', compact('memberArr', 'contentArr', 'catPathArr', 'linksArr'));
     } else {
         $parentArr['contentArr'] = [];
         foreach ($catArr as $catId => $catName) {
             $memberArr = $this->memberObj->getMembersWithinSingleCategory($catId);
             $tmpMemberArr = array($memberArr[0]);
             list(, $contentArr) = $this->memberSocialObj->getSocialMediaWithMemberIds($tmpMemberArr);
             $parentArr['memberArr'][$catId] = $memberArr;
             $parentArr['contentArr'] = $parentArr['contentArr'] + $contentArr;
         }
         return view('socialmedia.parent', compact('parentArr', 'catArr', 'catPathArr', 'linksArr'));
     }
 }
開發者ID:nowarena,項目名稱:homestead,代碼行數:40,代碼來源:SocialMediaController.php

示例2: findByCategory

 /**
  * Find all tricks for the category that matches the given slug.
  *
  * @param string $slug
  * @param int    $perPage
  *
  * @return array
  */
 public function findByCategory($slug, $perPage = self::PAGE_SIZE)
 {
     $category = $this->category->whereSlug($slug)->first();
     if (is_null($category)) {
         throw new CategoryNotFoundException('The category "' . $slug . '" does not exist!');
     }
     $tricks = $category->tricks()->orderBy('created_at', 'DESC')->paginate($perPage);
     return [$category, $tricks];
 }
開發者ID:wmk223,項目名稱:site,代碼行數:17,代碼來源:TrickRepository.php

示例3: fetch_status_history

 public static function fetch_status_history($category_slug)
 {
     $json = [];
     $category = Category::whereSlug($category_slug)->first();
     $device_statuses = DeviceStatus::all();
     foreach ($device_statuses as $device_status) {
         if ($device_status->device->category_id == $category->id) {
             $json[] = ['device_slug' => $device_status->device->slug, 'device_name' => $device_status->device->name, 'user_slug' => $device_status->user->id, 'user_name' => $device_status->user->name, 'status_label' => $device_status->status->status, 'status_descrip' => $device_status->status->description, 'created_at' => date('m/d/Y h:i A', strtotime($device_status->created_at))];
         }
     }
     return json_encode($json);
 }
開發者ID:encry2024,項目名稱:inv_5_2,代碼行數:12,代碼來源:Category.php

示例4: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     // Route Bindings
     $router->bind('categories', function ($value) {
         return Category::whereSlug($value)->first();
     });
     $router->bind('posts', function ($value) {
         return Post::whereSlug($value)->first();
     });
     $router->bind('author', function ($value) {
         return User::whereName($value)->first();
     });
     parent::boot($router);
 }
開發者ID:shempignon,項目名稱:laravel-5-blog-mvc,代碼行數:20,代碼來源:RouteServiceProvider.php

示例5: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $this->bind('package', function ($slug) {
         return Package::with('photos')->whereSlug($slug)->firstOrFail();
     });
     $this->bind('category', function ($slug) {
         return Category::whereSlug($slug)->firstOrFail();
     });
     $this->bind('packages', function ($id) {
         return Package::findOrFail($id);
     });
     $this->bind('categories', function ($id) {
         return Category::findOrFail($id);
     });
     parent::boot($router);
 }
開發者ID:marktimbol,項目名稱:eclipse,代碼行數:22,代碼來源:RouteServiceProvider.php

示例6: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param \Illuminate\Routing\Router $router
  *
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('user', function ($value) {
         return \App\User::whereSlug($value)->firstOrFail();
     });
     $router->bind('category', function ($value) {
         return \App\Category::whereSlug($value)->firstOrFail();
     });
     $router->bind('event', function ($value) {
         return \App\Event::whereSlug($value)->firstOrFail();
     });
     $router->bind('city', function ($value) {
         return \App\City::where('iata', $value)->firstOrFail();
     });
     $router->bind('subscriber', function ($value) {
         return \App\Subscriber::where('token', $value)->firstOrFail();
     });
     parent::boot($router);
 }
開發者ID:EMT,項目名稱:see-do,代碼行數:26,代碼來源:RouteServiceProvider.php

示例7: postCreate

 /**
  * 創建分類 
  *
  * @param string $value 
  *
  * @return Response
  */
 public function postCreate()
 {
     $rules = array('name' => 'required', 'slug' => 'regex:/^[a-zA-Z 0-9_-]+$/', 'parent_id' => 'integer');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     // 檢測分類名
     if (Category::whereName(Input::get('name'))->count()) {
         return Redirect::back()->withMessage("分類 '" . Input::get('name') . "' 已經存在!")->withColor('danger')->withInput(Input::all());
     }
     //檢測別名
     if (Input::get('slug') && Category::whereSlug(Input::get('slug'))->count()) {
         return Redirect::back()->withMessage("分類別名 '" . Input::get('slug') . "' 已經存在!")->withColor('danger')->withInput(Input::all());
     }
     // 創建分類
     $category = new Category();
     $category->name = Input::get('name');
     $category->slug = str_replace(' ', '', snake_case(Input::get('slug')));
     $category->parent = Input::get('parent_id');
     $category->description = Input::get('description');
     $category->save();
     return Redirect::back()->withMessage("分類 '{$category->name}' 添加成功!");
 }
開發者ID:jacobcyl,項目名稱:writor,代碼行數:31,代碼來源:CategoryController.php

示例8: retrieveAvailableDevices

 public static function retrieveAvailableDevices($category_slug, $request)
 {
     $count = 0;
     $category = Category::whereSlug($category_slug)->first();
     $devices = Device::with(['category', 'information'])->where('category_id', $category->id)->where('owner_id', 0);
     $devices = $devices->where('name', 'LIKE', '%' . $request->get('filter') . '%')->paginate(25);
     $devices->setPath('available_devices');
     return view('devices.available_devices', compact('category', 'devices', 'count'));
 }
開發者ID:encry2024,項目名稱:inv_5_2,代碼行數:9,代碼來源:Device.php

示例9: getCategory

 public function getCategory($slug)
 {
     $category = Category::whereSlug($slug)->firstOrFail();
     $products = $category->product()->paginate(12);
     return view('front.home', compact('products'));
 }
開發者ID:fransiskusbenny,項目名稱:larashop,代碼行數:6,代碼來源:FrontController.php

示例10: array

Route::get('/article/detail/{id}', array('uses' => 'ArticleController@showPublic'));
Route::get('/index', function () {
    $coupons = Coupon::all();
    return View::make('index')->with('coupons', $coupons);
});
Route::get('/admin', 'UserController@getAdminLogin');
Route::post('/admin', 'UserController@postAdminLogin');
Route::get('/logout', 'UserController@getLogout');
Route::get('/admin/dashboard', function () {
    return view('admin.content');
});
Route::model('articles', 'Article');
Route::model('merchants', 'Merchant');
Route::model('coupons', 'Coupon');
Route::model('categories', 'Category');
Route::bind('articles', function ($value, $route) {
    return App\Article::whereSlug($value)->first();
});
Route::bind('merchants', function ($value, $route) {
    return App\Merchant::whereSlug($value)->first();
});
Route::bind('coupons', function ($value, $route) {
    return App\Coupon::whereSlug($value)->first();
});
Route::bind('categories', function ($value, $route) {
    return App\Category::whereSlug($value)->first();
});
Route::resource('admin/article', 'ArticleController');
Route::resource('admin/merchant', 'MerchantController');
Route::resource('admin/coupon', 'CouponController');
Route::resource('admin/category', 'CategoryController');
開發者ID:sientong,項目名稱:tagin,代碼行數:31,代碼來源:routes.php

示例11: viewCategoryStatusesHistory

 public function viewCategoryStatusesHistory($category_slug)
 {
     $category = Category::whereSlug($category_slug)->first();
     return view('category.device_statuses', compact('category'));
 }
開發者ID:encry2024,項目名稱:inv_5_2,代碼行數:5,代碼來源:CategoryController.php

示例12: setCategories

 public static function setCategories($post, $category_ids = null, $new_category = null)
 {
     $post->categories()->detach();
     if (isset($new_category) && !empty($new_category)) {
         $current_category = Category::whereSlug(str_slug($new_category))->first();
         if (!$current_category) {
             $new_category = Category::create(['name' => $new_category, 'slug' => str_slug($new_category)]);
             $add_cat_id = $new_category->id;
         } else {
             $add_cat_id = $current_category->id;
         }
         if (is_null($category_ids)) {
             $category_ids = [];
         }
         array_push($category_ids, $add_cat_id);
     }
     if (isset($category_ids)) {
         $post->categories()->attach($category_ids);
     }
 }
開發者ID:ambarsetyawan,項目名稱:brewski,代碼行數:20,代碼來源:Post.php

示例13: scopeOfCategory

 /**
  * All files by slug of category
  */
 public function scopeOfCategory($query, $categorySlug)
 {
     $category = Category::whereSlug($categorySlug)->firstOrFail();
     return $query->whereCategoryId($category->id);
 }
開發者ID:quantbm,項目名稱:RimDrive,代碼行數:8,代碼來源:File.php

示例14: showDefectDev

 public function showDefectDev($category_slug)
 {
     $category = Category::whereSlug($category_slug)->first();
     return view('devices.defective_devices', compact('category'));
 }
開發者ID:encry2024,項目名稱:inv_5_2,代碼行數:5,代碼來源:DeviceController.php

示例15: show

 /**
  * Display the specified resource.
  *
  * @param  int $id
  * @return Response
  */
 public function show($slug)
 {
     $page_size = env('num_per_page');
     //        //method I.               num of queries:  17.
     //        $articles = Category::findBySlug($slug)->articles()->latest()->paginate($page_size);
     //method II: eager loading. num of queries 5
     //http://php.net/manual/en/functions.anonymous.php   "use" to inherit variables from its parent scope
     //whereSlug($slug) equals to where('slug', '=', $slug).
     $articles = \App\Article::with('tags', 'category')->published()->whereHas('category', function ($query) use($slug) {
         $query->whereSlug($slug);
     })->latest()->paginate($page_size);
     $Catname = Category::whereSlug($slug)->firstOrFail()->name;
     return view('blog.cats.show', compact('articles', 'Catname'));
 }
開發者ID:ambarsetyawan,項目名稱:laravel5-blog-1,代碼行數:20,代碼來源:CategoriesController.php


注:本文中的app\Category::whereSlug方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。