Answer the question
In order to leave comments, you need to log in
How to display category name by id value of another table?
There are tables
Cars - containing id, make_id, model_id
Makes - id, name
public function index() {
$cars = Car::select(['id', 'make_id', 'model_id', 'year', 'start_bid', 'odometer'])->get();
$makes = Make::all();
return view('main', compact('cars', 'makes'));
}
<div class="row">
@foreach ($cars as $article)
<div class="col-3 car">
<a href="{{ route('carsShow', ['id'=>$article->id]) }}">
<div class="box ratio4_3">
<div class="box-content grey">
<img src="">
</div>
</div>
<div class="box-text">
<div class="box-title">{{$article->make_id}} {{$article->model_id}}</div>
</div>
<div class="box-descr w100 flex">
<div><span>{{ number_format($article->start_bid,0,'',' ') }} ₽</span>, </div>
<div >{{$article->year}}, </div>
<div>{{ number_format($article->odometer,0,'',' ') }} км</div>
</div>
</a>
</div>
@endforeach
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question