Reputation: 1
How can I pass a parameter in URL, like type=Wedding
, then query DB accordingly and pass it to a view in laravel?
<div class="row row-bottom-padded-md">
<div align="center">
<button class="btn btn-default filter-button" data-filter="all">All</button>
<button class="btn btn-default filter-button" data-filter="pre_wedding">Pre-Wedding</button>
<button class="btn btn-default filter-button" data-filter="holud">Holud</button>
<button class="btn btn-default filter-button" data-filter="wedding">Wedding</button>
<button class="btn btn-default filter-button" data-filter="reception">Reception</button>
<button class="btn btn-default filter-button" data-filter="post_wedding">Post Wedding</button>
</div>
<br/>
@forelse($gallerypictures as $gallerypicture)
<div class="gallery_product col-lg-4 col-md-4 col-sm-4 col-xs-6 filter">
<div class="products">
<img src="{{url('images',$gallerypicture->image)}}">
<div class="overlays">
<div class="text_color">Hello World</div>
</div>
</div>
</div>
@empty
<h3>No Photos</h3>
@endforelse
</div>
The code works well when I search http://127.0.0.1:8000/gallery/wedding
. But I want to show products category when I click the button. How can I solve it?
Upvotes: 0
Views: 1354
Reputation: 723
From what I understood you wanted to show something on wedding page when the user click the wedding button . What you can do is instead of declaring the button declare the anchor tag in the blade file like this
<a href="/gallery/wedding" class="btn btn-default filter-button">Button </a>
Instead of doing it this way
<button class="btn btn-default filter-button" data-filter="wedding">Wedding</button>
Upvotes: 2
Reputation: 19
You can do like this <a>
tag to redirect to another page instead of button
<a href="/gallery?type=wedding" class="btn btn-default filter-button">Wedding</a>
You can get this type parameter value in your laravel view file by using this below code
@php
$queryParam = Request::query('type');
@endphp
{{$queryParam}}
Upvotes: 0
Reputation: 963
Hope you are looking something like this http://127.0.0.1:8000/gallery/wedding?a=1&b=2
Here ?a=1&b=2
is called query string. On your action method you can grab value of a by get method(eg: $_GET['a']
)
So in your case http://127.0.0.1:8000/gallery/wedding?type=Wedding
do something like this
and grab the value by $_GET['type']
.
Hope this will help.
Upvotes: 0