How to pass query string params to routes in Laravel4

后端 未结 1 823
长发绾君心
长发绾君心 2021-01-07 05:30

I\'m writing an api in Laravel 4. I\'d like to pass query string parameters to my controllers. Specifically, I want to allow something like this:

api/v1/ac         


        
相关标签:
1条回答
  • 2021-01-07 06:24

    You might want to implement this in your BaseController. This is one of the possible solutions:

    class BaseController extends Controller {
    
        protected $fields;
    
        public function __construct(){
    
            if (Input::has('fields')) {
                $this->fields = Input::get('fields');
            }
        }
    }
    

    After that $fields could be accessed in every route which is BaseController child:

    class AccountApiController extends \BaseController {
    
        public function index()
        {
            dd($this->fields);
        }
    } 
    
    0 讨论(0)
提交回复
热议问题