How to bring clients relevant objectified. categories?

There are two tables. client-сategories (id,title) and сlients(id,title,link,category). In Clients -> lies category id from the category you want. I have on the page displays a list of categories. Need to get clients that match the category.

How to do it? How to take these clients? I was like hasMany() but does not work not a Fig(

class Model extends ClientCategories 
{ 
 public $timestamps = false;
 protected $table = 'client categories';
 protected $fillable = ['title'];

 public function client()
{
 return $this->hasMany('App/Clients');
}
}


Deduce this:

<div class="clients">
 @foreach($categories as $category)
 <div class="slider-title clients-row">{{ $category['title'] }} <span class="plus">+</span></div>
 <div class="slider-content">
the <ul>
 the <li><span>{{ $category->client->title }}</span></li>
</ul>
</div>
@endforeach
 </div>


And instead of the title from the customers, I displayed {"id":1,"title":"\u0418\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u043e"}
July 9th 19 at 10:24
4 answers
July 9th 19 at 10:26
Has decided as follows:

<div class="clients">
 @foreach($categories as $category)
 <? $client = App\Clients::find($category['id'])?> 
 <div class="slider-title clients-row">{{ $category['title'] }} <span class="plus">+</span></div>
 <div class="slider-content">
the <ul>
 the <li><span>{{ $client['title'] }}</span></li>
</ul>
</div>
@endforeach
 </div>
More so never do.
You will have to query on each iteration. - Angelica.Schamberger commented on July 9th 19 at 10:29
July 9th 19 at 10:28
Read about the relationship in Eloquent in the official documentation. This is too trivial question
July 9th 19 at 10:30
You decide whether you want to obrashatsa as an object or as an array.
Otherwise you have to code then {{ $category->client->title }} then {{ $category['title'] }}.
View in config/database.php the method of data collection. And it and use.
But to use both - just not the best option.
how can I in the controller to create the array with customers to define. ctaegory and return as $categories, $client? - Angelica.Schamberger commented on July 9th 19 at 10:33
July 9th 19 at 10:32
Suggest more sleep or to be distracted from work, and a blunt out of the blue.
You have in each category a few customers, hasMany relationship, but in the view you work with him like a client one and a hasOne relationship, even though you have a collection and need to be cycle
@foreach($category->client as $client) {{ $client->title }}
FatalErrorException in Model.php line 931:
Class 'App/Clients' not found - Angelica.Schamberger commented on July 9th 19 at 10:35
Where you need to add use App\Clients;? - Salma_Jones commented on July 9th 19 at 10:38

Find more questions by tags Laravel