Last active
July 17, 2017 03:10
Example of non-database bound model binding in Laravel routes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Controller | |
{ | |
function getData(Period $period) | |
{ | |
return Model::where('created_at', '>', Carbon::create($period->year, $period->month, 1)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Period | |
{ | |
public $year; | |
public $month; | |
function Period(string param) { | |
// TODO: Handle input like '2017-06', '2017' or '' | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Route::get('/data/{period}', 'Controller@getData'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment