I am using Laravel 5.2 on PHP 5.5.9
Instead of hard coding methods in the following controller, I used PHP __callStatic method to dynamically add functionality. It works fine while I tried from Console But while calling methods route, I am getting the following error
Method App\Http\Controllers\showCategory::latest() does not exist
Here is my Route
Route::get('Category/{id}', 'showCategory@latest');
Here is my 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 help to point where I messed up ?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire