input('start')) { $start = $request->input('start'); $start = DateTime::createFromFormat('dmY', $start); } else { $start = now()->modify('-1 year'); } // Set end date with request or now. if ($request->input('end')) { $end = $request->input('end'); $end = DateTime::createFromFormat('dmY', $end)->modify('+1 day'); } else { $end = now(); } // Check if the difference bewteen end and start is < than 1 year. if ($start->diff($end)->days > 366) { return response('Date interval too long', 403); }; $history = $url->history() ->where('start_date', '>', $start) ->where('end_date', '<', $end) ->get(); return new UrlHistoryCollection($history); } /** * Returns the stats for the given url. * * @param Url $url * @return \Illuminate\Http\Response */ public function getstats(Url $url) { return new UrlStatsCollection($url->stats); } }