Laravel 5 method does not exist in Controller while used PHP __callStatic method -
i using laravel 5.2 on php 5.5.9
instead of hard coding methods in following controller, used php __callstatic method dynamically add functionality. works fine while tried console while calling methods route, getting following error
method app\http\controllers\showcategory::latest() not exist
here route
route::get('category/{id}', 'showcategory@latest');
here controller
class showcategory extends controller { public $methods = [ 'latest' => 'created_at', 'newarrival' => 'created_at', 'mostviewed' => 'views' ]; public function get( $link_or_id, $orderby = 'created_at' ) { } public static function __callstatic($func, $arg) { $category = new self(); if( array_key_exists( $func, $category->methods ) ) { return $category->get( $arg[0], $category->methods[ $func ] ); } } }
any point messed ?
__callstatic() triggered when invoking inaccessible methods in static context.
showcategory::latest(); works
and logically how put latest method in routes , know if found or not, if put in routes must found in controller
Comments
Post a Comment