Answer the question
In order to leave comments, you need to log in
How to get records from database in Laravel?
There is a table post in which there is a cell "category".
This cell contains post categories. They look like "Architecture;Construction;Installation"
How can I make a selection of all posts that have the "Construction" category?
Answer the question
In order to leave comments, you need to log in
There is a table post in which there is a cell "category".
This cell contains post categories. Have the form "Architecture;Construction;Installation"
class Post extends Eloquent
{
public $table = 'posts';
public function category()
{
return $this->belongsTo(Category::class);
}
}
class Category extends Eloquent
{
public $table = 'categories';
public function posts()
{
return $this->hasMany(Post::class);
}
}
Will it fit?:PostModel::whereCategory('Строительство')->get();
With such a database architecture, there are three questions:
1. How to correctly query the database?
2. How to make this request through Laravel?
3. How to do it using Laravel models, here Models\Post?
1. If there is no way to change the database architecture, then I would use a regular expression in the database, something like:
2/3. Smoke docs:
laravel.com/docs/5.1/database
laravel.com/docs/5.1/eloquent
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question