【问题标题】:Getting specific category posts with appserviceprovider in laravel在 laravel 中使用 appserviceprovider 获取特定类别的帖子
【发布时间】:2017-10-27 11:34:51
【问题描述】:

我尝试在 Laravel 5.5 的 main page 中获取我的类别最新帖子,但我不知道该怎么做。

这是我的代码:

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

这是我得到的错误:

Class 'App\Providers\Cateory' not found

这是我的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:除了我上面的问题,我需要知道无论如何我 可以在管理面板中选择我的类别,并在其中显示的帖子 homepage 而不是我从静态加载每个类别 AppServiceProvider 还是没有?

说明

如果您使用 WP 主题/插件,您可以从某种下拉框中选择要在首页显示的类别帖子。

例子:

【问题讨论】:

  • Cateory !== Category 正如@haidang 指出的那样。

标签: php laravel


【解决方案1】:

我认为你输入错误

使用Category 而不是Cateory

【讨论】:

  • 我明白了,谢谢,但是如何获得特定类别的帖子?
猜你喜欢
  • 2020-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-22
  • 1970-01-01
相关资源
最近更新 更多