Astrotomic / laravel-translatable

A Laravel package for multilingual models
https://docs.astrotomic.info/laravel-translatable/
MIT License
1.23k stars 156 forks source link

How can I hide empty translated posts in my blog? #227

Closed vahidtakro closed 3 years ago

vahidtakro commented 3 years ago

Hello, I am using this package on my multilingual blog, where I translate some posts and some not, for now when user opens my blog, he can see all posts, no matter if they are translated or not. if he is using the locale that the post is not translated in, it's still showing the post, but without title and content. how can I hide them? so in this case I can post in different languages, so if I want to publish a post in all languages, I just translate it.

my controller:

  public function blog()
  {
    $blogs = Blogs::where('status', 'published')->orderBy('id','desc')->paginate(10);

    $page = request()->get('page');

    if ($page > $blogs->lastPage()) {
            abort('404');
        }
    return view('index.blog', ['blogs' => $blogs]);
  }

I also used Scopes, but I don't know if I did it right or not.

Thanks.

Gummibeer commented 3 years ago

https://docs.astrotomic.info/laravel-translatable/package/scopes#translatedin-string-usdlocale-null

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days