mardi 17 janvier 2017

Accessing dates in query string using Laravel

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 http://ift.tt/2jGJVyh. Then, if a user hit a back button, they could return the week previous (e.g. http://ift.tt/2iKUrWW), 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.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2jtiU4f
via IFTTT

Aucun commentaire:

Enregistrer un commentaire