Answer the question
In order to leave comments, you need to log in
How to pass data to popup in Laravel?
I have a list of objects and a "details" button for each.
When the user clicks "details", a window with more detailed information about this particular object should pop up. So, how to transfer information about this particular object to this window?
<div class="row">
@foreach ($objects->sortby(-'id') as $object)
<div class="col-xs-6 col-md-4">
<div class="text-center object">
<div class="object__img">
<img src="{{ $object->object_image }}" alt="Фото объекта">
</div>
<div class="object__info">
<div class="text-left object__price">Цена: {{ $object->object_price }}</div>
<div class="text-left object__space">Площадь: {{ $object->object_space }}</div>
<p class="text-left object__description">{{ $object->object_description }}</p>
</div>
<button class="button object__btn description-open">Подробнее</button>
</div>
</div>
@endforeach
</div>
public function index() {
$objects = ObjectsModel::All();
$data = [
'objects' => $objects
];
return view('pages.landing', $data);
}
<div class="col-md-12">
<h5 class="popup_obj__subtitle">
Описание:
</h5>
</div>
<div class="col-md-12">
<p class="popup_obj__desc">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sequi inventore iste nesciunt modi non culpa voluptate explicabo, ipsum dolorem suscipit natus quidem ex vel eum asperiores ipsam facilis recusandae. Ut?
</p>
</div>
<div class="col-md-12">
<div class="text-left popup_obj__price">Цена: 45454 54 54 54</div>
<div class="text-left popup_obj__space">Площадь: 46/46/46/46</div>
</div>
Answer the question
In order to leave comments, you need to log in
There are several options:
1) Create a lot of divs with popups (for each object) and show only the one you need.
2) Display $objects in json on the page, and take information using JS from there.
3) Make an ajax request when you click on "Details" and collect information about the object from the server.
4) If there is not much data in the object that needs to be displayed, then you can write them to the "data-*" attributes, and read from there.
Depending on the number of objects, each of the items can be used.
1 - few objects (up to 10)
2 - up to 100 objects
3 - when there are more than 100 objects
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question