-1

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?
}
  • Does this answer your question? [Access query string values from Laravel](https://stackoverflow.com/questions/24744825/access-query-string-values-from-laravel) – miken32 Dec 14 '20 at 22:31
  • Why do you think you need to get the query string value anyway? You should just be using `Auth::user()` to get the authenticated user. – miken32 Dec 14 '20 at 22:38

2 Answers2

0

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

lagbox
  • 48,571
  • 8
  • 72
  • 83
0

You can get it off the $request object

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

    //OR

    $apiToken = $request->query('api_token');
}
Donkarnash
  • 12,433
  • 5
  • 26
  • 37