samedi 23 septembre 2017

How to call static function from routes.php in Laravel

I am trying to call a static function from the controller which is already written and I just want to reuse that function.

Controller:

public static function getProjectName($project_id){
     $project_obj = new Project();
     $project = $project_obj->find($project_id); 
     return $project->project_name;
}

This code is working fine if I call this static function in the same or another controller. But I'm trying to call it from routes.php something like below:

routes.php

Route::get('/get-project-name/{project_id}', 'ProjectController@getProjectName');

I am calling the same function using above code in routes.php but every time I'm getting 405 error that is method not allowed.
How can I call this static function from route in Laravel



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2fhccdH
via IFTTT

Aucun commentaire:

Enregistrer un commentaire