Skip to content

Instantly share code, notes, and snippets.

@jameshulse
Last active July 17, 2017 03:10
Show Gist options
  • Save jameshulse/21cdcd5912686282edf958a07a0d0078 to your computer and use it in GitHub Desktop.
Save jameshulse/21cdcd5912686282edf958a07a0d0078 to your computer and use it in GitHub Desktop.
Example of non-database bound model binding in Laravel routes
<?php
class Controller
{
function getData(Period $period)
{
return Model::where('created_at', '>', Carbon::create($period->year, $period->month, 1));
}
}
<?php
class Period
{
public $year;
public $month;
function Period(string param) {
// TODO: Handle input like '2017-06', '2017' or ''
}
}
Route::get('/data/{period}', 'Controller@getData');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment