Amanda1990 Amanda1990 - 3 months ago 26
PHP Question

Laravel POST data from view to ROUTE without using a form

I'm not sure what's the best way to implement this but here is what I have going

On my

register.blade.php
view I have a button that links to an external api link,once clicked the api will redirect the response back to
register.blade.php
or [
localhost:8000/register
] as a
GET
request (I have no control over that matter, only the redirect link)

how would I pass the
GET
data to my custom authentication controller.

Or is there a better way to implement this?

The API returns the following data and will be used to store the data in a db and authenticate the user


  • Account ID

  • Nickname

  • Access_Token
    (will be used to make more api calls)


Answer

IF the API is redirecting back as get, but has post data for example: http://localhost:8000/register?someval=something -- you'd simply use request('someval') to get that data, or you could in your control add Request $request in the attribute of the function i.e.

    public function myfunc(Request $request){
      dd($request->somevar) // will die and dump: showing "something" as a string.    
    }

Whether you're sending data via get, post, patch, and use normal static post, or ajax -it'll still work. You can even pass ajax to the call. I recommend using Postman to test out get/posts it's a Chrome plugin.