简体   繁体   中英

How can I get the api_token in the controller?

I have this Vuejs Code:

axios.get('/api/electronic_collection?page='+this.currentPage+'&api_token='+App.apiToken)
                .then(response => {
                    this.posts = response.data.data.data;
                    this.total = response.data.data.last_page;
                    this.currentPage = response.data.data.current_page;
                    this.rowsQuantity = response.data.data.total;
                });

How you can see I am seding the api_token because it connects to an API Restful but what I want to do it's that I need to get this api_token in the controller.

My controller is like this:

public function index(Request $request)
{
     but I'd like to get the api_token here, how can I do that I mean $_GET['api_token'] is it like this?
}

The query string is an input source. You can ask the Request for this input:

$request->input('api_token')

Laravel 8.x Docs - Requests - Retrieving Input - Retrieving and Input value input

You can get it off the $request object

public function index(Request $request)
{
     $apiToken = $request->api_token;

    //OR

    $apiToken = $request->query('api_token');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM