本文整理汇总了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'));
}
}
示例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];
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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}' 添加成功!");
}
示例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'));
}
示例9: getCategory
public function getCategory($slug)
{
$category = Category::whereSlug($slug)->firstOrFail();
$products = $category->product()->paginate(12);
return view('front.home', compact('products'));
}
示例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');
示例11: viewCategoryStatusesHistory
public function viewCategoryStatusesHistory($category_slug)
{
$category = Category::whereSlug($category_slug)->first();
return view('category.device_statuses', compact('category'));
}
示例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);
}
}
示例13: scopeOfCategory
/**
* All files by slug of category
*/
public function scopeOfCategory($query, $categorySlug)
{
$category = Category::whereSlug($categorySlug)->firstOrFail();
return $query->whereCategoryId($category->id);
}
示例14: showDefectDev
public function showDefectDev($category_slug)
{
$category = Category::whereSlug($category_slug)->first();
return view('devices.defective_devices', compact('category'));
}
示例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'));
}