本文整理匯總了PHP中app\Category::with方法的典型用法代碼示例。如果您正苦於以下問題:PHP Category::with方法的具體用法?PHP Category::with怎麽用?PHP Category::with使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Category
的用法示例。
在下文中一共展示了Category::with方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: viewCategories
public static function viewCategories($request)
{
$categories = Category::with(['devices'])->latest('updated_at');
$categories = $categories->where('name', 'LIKE', '%' . $request->get('filter') . '%')->paginate(25);
$categories->setPath('/');
return view('home', compact('categories'));
}
示例2: index
/**
* Retrieve all categories with their products
* Products can have a category_id_sub : if it is not null, a category with sub_ids can be shown on screen
*
* @return mixed
*/
public function index()
{
return Category::with(['products' => function ($q) {
$q->select(['products.id', 'category_id', 'name', 'price', 'visible', 'sort', 'category_id_sub']);
$q->orderBy('sort');
}])->orderBy('sort')->get();
}
示例3: getAll
/**
* Get all categories with childs ordered by priority
*
* @return collection
*/
public static function getAll()
{
$categories = Category::with(['childs' => function ($query) {
$query->orderBy('priority', 'desc');
}])->where('parent_id', null)->orderBy('priority')->get();
return $categories;
}
示例4: showSingleCategory
/**
* @param $slug
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function showSingleCategory($slug)
{
$categories = Category::with('products')->where('is_active', true)->has('products')->get();
$category = Category::findBySlug($slug);
$products = $category->products;
return view('frontend.categories.showCategory', compact('categories', 'category', 'products'));
}
示例5: destroy
public function destroy(Request $request)
{
$model = Category::with('articles', 'announcements')->find($request->id);
if (empty($model)) {
Flash::error('Impossible de supprimer cette catégorie.');
return Redirect::back();
}
$announcements = $model->announcements();
$articles = $model->articles();
if (!empty($announcements)) {
foreach ($announcements as $a) {
$a->update(['category_id' => 1]);
}
}
if (!empty($articles)) {
foreach ($articles as $a) {
$a->update(['category_id' => 1]);
}
}
$name = $model->name;
$model->delete();
makeModification('categories', 'The category « ' . $name . ' » has been removed.');
Flash::success('La catégorie a bien été supprimé.');
return Redirect::back();
}
示例6: updatePostCount
private static function updatePostCount()
{
foreach (Category::with('posts')->get() as $category) {
$category->post_count = $category->posts()->count();
$category->save();
}
}
示例7: viewMenus
public function viewMenus($id = '')
{
$categories = Category::with('product')->lightSelection()->store()->full()->orderBy('name')->get()->toArray();
$actualCategory = [];
findfather($actualCategory, $categories, $id);
$panel = ['left' => ['width' => '3', 'class' => 'categories-panel'], 'center' => ['width' => '9']];
return view('categories.menus', ['panel' => $panel, 'categories' => orderByParents($categories), 'actualCategory' => $actualCategory]);
}
示例8: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$record = Category::with('user')->get();
if (!$record) {
return View::make('errors.404');
}
//return View::make('company_category.index')->with('data', $record);
return View::make('company_category.index', ['data' => $record, 'categories' => $this->getCategoryListAsJson()]);
}
示例9: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$categories = Category::with(['threads' => function ($query) {
$query->orderBy('updated_at', 'desc');
}, 'threads.posts' => function ($query) {
$query->orderBy('created_at', 'asc');
}, 'threads.posts.user'])->get();
return view('categories.index', compact('categories'));
}
示例10: index
/**
* Display a listing of the resource.
*
* @param $categoryId
* @return Response
*/
public function index($categoryId)
{
$category = Category::with(['threads' => function ($query) {
$query->orderBy('updated_at', 'desc');
}, 'threads.posts' => function ($query) {
$query->orderBy('created_at', 'asc');
}, 'threads.posts.user'])->findOrFail($categoryId);
return view('threads.index', compact('category'));
}
示例11: getIndex
/**
* Отображает список категорий.
*
* @return Response
*/
public function getIndex()
{
// Ищем фирму по короткому названию
$data['company'] = Company::whereShortTitle($this->companyName)->first();
// Получаем список групп категорий
$data['categories'] = Category::with('group_category')->with('parent_category')->whereHas('group_category', function ($query) use($data) {
$query->where('company_id', '=', $data['company']->id);
})->get();
return view('admin.companies.catalog.categories.index', $data);
}
示例12: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$category = Category::with(['threads', 'threads.posts'])->findOrFail($id);
foreach ($category->threads as $thread) {
$thread->posts()->delete();
}
$category->threads()->delete();
$category->delete();
return redirect()->route('admin.categories.index');
}
示例13: getCategoriesAdmin
public function getCategoriesAdmin($departmentId = null)
{
if ($departmentId) {
$categories = Category::with('langs')->where('department_id', $departmentId)->sort()->get();
} else {
$categories = Category::with('langs')->sort()->get();
}
$categories = $this->loadLangs($categories);
return $categories;
}
示例14: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$user = new Users();
$user->fill($request->all());
$user->password = Hash::make($request->input('password'));
$user->save();
$data['partner'] = Partner::orderBy('created_at', 'asc')->get();
$data['category'] = Category::with('SubCategory')->orderBy('created_at', 'asc')->get();
return view('site.success', $data);
}
示例15: getRooms
public static function getRooms($q)
{
$json = array();
$categories = Category::with(['rooms' => function ($query) use($q) {
$query->where('name', 'LIKE', '%' . $q . '%');
}])->get();
foreach ($categories as $category) {
foreach ($category->rooms as $room) {
$json[] = ['category_id' => $category->id, 'room_id' => $room->id, 'category_name' => $category->name, 'room_name' => $room->name, 'category_min' => $category->min_capacity, 'category_max' => $category->max_capacity, 'category_price' => $category->price];
}
}
return $json;
}