LavaLite / cms

Multilingual PHP CMS built with Laravel and bootstrap
https://lavalite.org
2.85k stars 968 forks source link

Litecms error on blog pages #376

Open melaniecarr23 opened 2 years ago

melaniecarr23 commented 2 years ago

When I go to 127.0.0.1:8000/blog I get the following error after following the documentation on install: Too few arguments to function Litecms\Blog\Http\Controllers\BlogPublicController::show(), 1 passed in /Users/melaniecarr/WebDevelopment/thehigheryougo/vendor/laravel/framework/src/Illuminate/Routing/Controller.php on line 54 and exactly 2 expected

When I go to 127.0.0.1:8000/blog/index, I get the following error: Attempt to read property "name" on null

Just getting my feet wet here, so maybe I'm missing something.

melaniecarr23 commented 2 years ago

Updating this: when I go to /blogs, I get the following error: 'Call to undefined method Illuminate\Database\Eloquent\Builder::withQueryString()' Looks like packages/litecms/blog/src/Http/Controllers/BlogPublicController.php:51 doesn't like that. What am I missing? What can I do to make this work?

mepsd commented 2 years ago

could you please drop the controller code of packages/litecms/blog/src/Http/Controllers/BlogPublicController.php

wmomesso commented 2 years ago

error on new installation

Too few arguments to function Litecms\Blog\Http\Controllers\BlogPublicController::show(), 1 passed in /var/www/cmstisfe/vendor/laravel/framework/src/Illuminate/Routing/Controller.php on line 54 and exactly 2 expected

BlogPublicController `namespace Litecms\Blog\Http\Controllers;

use App\Http\Controllers\PublicController as BaseController; use App\Http\Requests\PublicRequest; use Litecms\Blog\Interfaces\BlogRepositoryInterface; use Litecms\Blog\Interfaces\CategoryRepositoryInterface; use Litecms\Blog\Interfaces\TagRepositoryInterface; use Litecms\Blog\Repositories\Eloquent\Filters\BlogPublicFilter; use Litecms\Blog\Repositories\Eloquent\Presenters\BlogListPresenter; use Litepie\Repository\Filter\RequestFilter;

class BlogPublicController extends BaseController {

/**
 * Constructor.
 *
 * @return void
 */
public function __construct(
    BlogRepositoryInterface $blog,
    CategoryRepositoryInterface $category,
    TagRepositoryInterface $tag
) {
    parent::__construct();
    $this->modules = $this->modules(config('litecms.blog.modules'), 'blog', guard_url('blog'));
    $this->repository = $blog;
    $this->category = $category;
    $this->tag = $tag;

}

/**
 * Show blog's list.
 *
 * @return response
 */
protected function index(PublicRequest $request)
{

    $search = $request->search;
    $pageLimit = $request->input('pageLimit', config('database.pagination.limit'));
    $data = $this->repository
        ->pushFilter(RequestFilter::class)
        ->pushFilter(BlogPublicFilter::class)
        ->setPresenter(BlogListPresenter::class)
        ->select('blogs.*')
        ->paginate($pageLimit)
        ->withQueryString()
        ->appends([
            'dd' => 'dd',
        ])
        ->toArray();

    extract($data);

    $categories = $this->category->categories()->toArray();
    $tags = $this->tag->tags()->toArray();
    $recent = $this->repository->recent(2)->toArray();

    return $this->response->setMetaTitle(trans('blog::blog.names'))
        ->view('blog::public.blog.index')
        ->data(compact('data', 'meta', 'categories', 'tags', 'recent'))
        ->output();
}

/**
 * Show blog.
 *
 * @param string $slug
 *
 * @return response
 */
protected function show(PublicRequest $request, $slug)
{
    $data = $this->repository
        ->findBySlug($slug)
        ->toArray();

    $categories = $this->category->categories()->toArray();
    $tags = $this->tag->tags()->toArray();
    $recent = $this->repository->recent(2)->toArray();

    return $this->response->setMetaTitle($data['title'] . trans('blog::blog.name'))
        ->view('blog::public.blog.show')
        ->data(compact('data', 'categories', 'tags', 'recent'))
        ->output();
}

} `

huynhhuynh02 commented 1 year ago

I have change /litecms/blog/src/Repositories/Eloquent/Presenters/BlogItemPresenter.php line 38 'author' => @$this->author->name It working for me . @melaniecarr23