Answer the question
In order to leave comments, you need to log in
How to pull the work of the desired category?
Such situation. There is a table - works, all works are stored in it. There is a column - categories , which indicates the categories to which the work belongs, in the form: category, category,
category I need to pull out all works related to a given category. How can I do it? Heard about realtionships, but did not understand. Could you show a working example? Thank you!
Answer the question
In order to leave comments, you need to log in
You have selected the wrong category structure.
Read about connections. For categories, belongsToMany is ideal, but it can be wiser - through a polymorphic relationship.
Then, to select by category, something like
Work::whereHas('categories', function($q) use($category){
$q->where('slug', $category);
})->get();
It's hard to judge such an informative question.
Try thisWork::where('categories', $category)->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question