Where are you getting taginDate, seems you are bypassing it via:
<form action="{{route('venue.venuetaginstats', [Auth::user()->venue_id, date('Y-m-d')])}}">
Get your request in a controller.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
So my URL is currently set to show todays date:
http://moveme.test/venue/1152522/2020-09-23/tagin/stats
I want the URL to change to the selected date from the form below:
<form action="{{route('venue.venuetaginstats', [Auth::user()->venue_id, date('Y-m-d')])}}">
<select name="taginDate" id="taginDate">
@foreach($data as $date)
<option value="{{$date->taginDate}}">
{{ Carbon\Carbon::parse($date->taginDate)->format('l jS \of F Y') }}
</option>
@endforeach
</select>
<input type="submit" value="search">
</form>
but when I submit the form, I get:
http://moveme.test/venue/1152522/2020-09-23/tagin/stats?taginDate=2020-09-04
Where are you getting taginDate, seems you are bypassing it via:
<form action="{{route('venue.venuetaginstats', [Auth::user()->venue_id, date('Y-m-d')])}}">
Get your request in a controller.
taginDate is the name of the select
In value save whole url and with javascript change action attribute. This is in pure js.
<form id="date-form" action="{{ route('venue.venuetaginstats', [Auth::user()->venue_id, today()->toDateString()]) }}">
<select name="taginDate" id="taginDate">
@foreach($data as $date)
<option value="{{ route('venue.venuetaginstats', [Auth::user()->venue_id, $date->taginDate]) }}">
{{ Carbon\Carbon::parse($date->taginDate)->format('l jS \of F Y') }}
</option>
@endforeach
</select>
<input type="submit" value="search">
</form>
<script>
document.getElementById('date-form').taginDate.onchange = function() {
document.getElementById('date-form').action = this.value;
};
</script>
Thanks but that didn't work?!
I got
http://moveme.test/venue/1152522/2020-09-23/tagin/stats?taginDate=http%3A%2F%2Fmoveme.test%2Fvenue%2F1152522%2F2020-09-17%2Ftagin%2Fstats
You are getting what you pass
date('Y-m-d')
Somewhere you have to request taginDate.
I just need the URL to change:
from this:
http://moveme.test/venue/1152522/2020-09-23/tagin/stats
and if someone selects the 17th
http://moveme.test/venue/1152522/2020-09-17/tagin/stats
Ok I changed it little bit. This should work
<form id="date-form" action="{{ route('venue.venuetaginstats', [Auth::user()->venue_id, today()->toDateString()]) }}">
<select id="taginDate">
@foreach($data as $date)
<option value="{{ route('venue.venuetaginstats', [Auth::user()->venue_id, $date->taginDate]) }}">
{{ Carbon\Carbon::parse($date->taginDate)->format('l jS \of F Y') }}
</option>
@endforeach
</select>
<input type="submit" value="search">
</form>
<script>
document.getElementById('taginDate').onchange = function() {
document.getElementById('date-form').action = this.value;
};
</script>
Thanks, that doesn't work, it just adds a '?' to the end of the URL
Ok last try
<form id="date-form" action="{{ route('venue.venuetaginstats', [Auth::user()->venue_id, today()->toDateString()]) }}">
<select id="taginDate">
@foreach($data as $date)
<option value="{{ route('venue.venuetaginstats', [Auth::user()->venue_id, $date->taginDate]) }}">
{{ Carbon\Carbon::parse($date->taginDate)->format('l jS \of F Y') }}
</option>
@endforeach
</select>
<input type="submit" value="search">
</form>
<script>
document.getElementById('taginDate').onchange = function() {
document.getElementById('date-form').action = this.value;
};
document.getElementById('date-form').onsubmit = function() {
window.location = this.action;
return false;
};
</script>
Working example you can see here http://jsfiddle.net/43vhk6Lu/3/
Open devtools and under network tab you can see that it works.
no, but thanks anyways.... anyone else?
Other people just give you similar answer and they maybe use jquery, vue.js and so on. What means that you have to use javascript for that.
don't have to use jquery or javascript, would just like it to work, thanks so much for your help so far
not sure why it doesn't work MichaelOravec?!
Route to a controller and get the request there. Or use a button and set up a click event that gets the data change in the JavaScript. The way you are doing it now you never get the data from the select option.
by default I arrive at the page with todays date, when I select a different date, it just adds a '?' to the end of the URL...
here is my code so far (well MichaelOravec's code):
<form id="date-form" action="{{ route('venue.venuetaginstats', [Auth::user()->venue_id, today()->toDateString()]) }}">
<select id="taginDate" onchange="this.form.submit()">
@foreach($data as $date)
<option value="{{ route('venue.venuetaginstats', [Auth::user()->venue_id, $date->taginDate]) }}">
{{ Carbon\Carbon::parse($date->taginDate)->format('l jS \of F Y') }}
</option>
@endforeach
</select>
</form>
<script>
document.getElementById('taginDate').onchange = function() {
document.getElementById('date-form').action = this.value;
};
document.getElementById('date-form').onsubmit = function() {
window.location = this.action;
return false;
};
</script>
jlrdw are you suggesting I change my route
Route::get('venue/{id}/{now}/tagin/stats', 'VenueController@venueTaginstats')->name('venue.venuetaginstats');
and my controller?
public function venueTaginstats($id, $date) {
$tagins = Tagin::latest()->where('venue_id',$id)->where('created_at', 'like', '%' . $date . '%')->paginate(1000);
$data = Tagin::select(DB::raw('DATE_FORMAT(created_at, "%Y-%m-%d") as taginDate'))->distinct()->where('venue_id',$id)->get();
$thevenue = Venue::findOrFail($id);
return view('venues.tagins', compact(
'tagins','thevenue', 'data'));
}
In the controller request taginDate if selected, now you have a default or taginDate to deal with choose which one and use in the query. If no selection was made I'm guessing you want to use your default date.
Also for a date, you shouldn't need like, wouldn't "=" work.
I didn't post code with
onchange="this.form.submit()"
I got it working:
controller:
public function venueTaginstats($id, Request $request) {
$date = $request->get('taginDate');
if($date == ''){
$date = date('Y-m-d');
}
$tagins = Tagin::latest()->where('venue_id',$id)->where('created_at', 'like', '%' . $date . '%')->paginate(1000);
$data = Tagin::select(DB::raw('DATE_FORMAT(created_at, "%Y-%m-%d") as taginDate'))->distinct()->where('venue_id',$id)->get();
$thevenue = Venue::findOrFail($id);
return view('venues.tagins', compact(
'tagins','thevenue', 'data'));
}
route:
Route::get('venue/{id}/tagin/stats', 'VenueController@venueTaginstats')->name('venue.venuetaginstats');
I added that in instead of the button, I tried with the button as in your code first... Thanks so much for your help
Why use a form with select if you just need to switch an url? Create a dropdown with links...
@boyjarv that's what I meant in my first reply, when I said get the request in the controller. That way you choose what date is needed.
What did you end up doing,
Please or to participate in this conversation.