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

Get post category name #612

Open
falahidev opened this issue Jul 12, 2022 · 1 comment
Open

Get post category name #612

falahidev opened this issue Jul 12, 2022 · 1 comment

Comments

@falahidev
Copy link

Hi guys. How I can get post category name? I tried to find a way but I failed.

@alexmanase
Copy link

Hi there!

From a collection of categories

Well you can return a collection with all categories with the Taxonomy model.

Taxonomy::where('taxonomy', 'category')->get()

The collection contains all categories as models. You can call name in order to get the name of the category.

Taxonomy::where('taxonomy', 'category')->get()->first()->name

From a post

If you have a post and you need the category name then you will need to call category_name.

Post::published()->type('post')->slug($slug)->with('attachment')->firstOrFail()->category_name

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

2 participants