In my Laravel project, I have a dashboard that displays data on a weekly basis. Now, I need to provide a way for users to toggle between weeks, and to have the dashboard data update accordingly.
Ideally, I would use query parameters to achieve this—something like domain.dev/dashboard?start=2017-01-02&end=2017-01-08. Then, if a user hit a back button, they could return the week previous (e.g. domain.dev/dashboard?start=2016-12-26&end=2017-01-02), and so on.
Here's my current route:
Route::get('/dashboard/weekly', [
'as' => 'providerDashboardIndex', 'uses' => 'DashboardController@indexWeekly'
]);
Here's the corresponding controller:
public function index()
{
$user = Auth::user();
$endDate = Carbon::today();
$startDate = Carbon::today()->subDays(7);
return view('providers.dashboard.index', compact('user', 'startDate', 'endDate') );
}
When a user hits the route initially, how would I add those query parameters to my URL? I understand date creation, but unsure how to pass those dates through.