简体   繁体   English

在Laravel中使用appserviceprovider获取特定类别的帖子

[英]Getting specific category posts with appserviceprovider in laravel

I try to get my category latest posts in main page in Laravel 5.5 and I'm not sure how to do that. 我尝试在Laravel 5.5的main page上获取类别的最新帖子,但我不确定该怎么做。

Here is the code that I have: 这是我的代码:

View::composer('frontend.index', function ($view) {
$categoryone = Cateory::with('products')->where('category_id', $category)
  ->offset(1)
  ->limit(9)
  ->get();
$view->with('categoryone', $categoryone);
});

This is the error i get: 这是我得到的错误:

Class 'App\Providers\Cateory' not found

This is my AppServiceProvider head: 这是我的AppServiceProvider负责人:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\View;
use App\Category;
use DB;

class AppServiceProvider extends ServiceProvider
{
....

PS: except my question above, I need to know is there anyway that I can select my categories in admin panel and posts of that be shown in homepage instead of I statically load each category from AppServiceProvider or no? PS:除了上面的问题外,我仍然需要知道是否可以在管理面板中选择类别,而该类别的帖子显示在homepage而不是我从AppServiceProvider静态加载每个类别,还是没有?

Explanation 说明

If you worked with WP themes/plugins you can choose what category posts to be shown in front page from some sort of dropdown boxes. 如果您使用WP主题/插件,则可以从某种下拉框中选择要显示在首页上的类别帖子。

Example: 例:

样本图片

I think you has a error typing 我认为您输入错误

Use Category instead of Cateory 使用Category ,而不是Cateory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM