Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Litecms error on blog pages #376

Open
melaniecarr23 opened this issue Jan 25, 2022 · 4 comments
Open

Litecms error on blog pages #376

melaniecarr23 opened this issue Jan 25, 2022 · 4 comments

Comments

@melaniecarr23
Copy link

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
Copy link
Author

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
Copy link

mepsd commented Jan 27, 2022

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

@wmomesso
Copy link

wmomesso commented Mar 20, 2022

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@melaniecarr23 @wmomesso @huynhhuynh02 @mepsd and others