samedi 21 avril 2018

Laravel guzzle post request for create function not working

Hi all,

I am developing web application with Laravel 5.6 with the latest PHP and Composer version. I learnt about the Guzzle and installed in my application.

I used Guzzle to make the CRUD function in my application which my data is on another remote application. I able to display the record with the get request.

Here is my code to display records using Guzzle:

$guzzle = new Client;[enter image description here][1]
$response = $guzzle->get('http://192.168.1.6/oauth/client/view', [
  'query' => [
    'user_id' => Auth::user()->id,
  ],
])->getBody();
$clients = json_decode($response);

return view('pages.settings.clients', compact('clients'));

The problem that I face now is when I do the create function in get the error 419 status when I use the Guzzle function to create new record.

The snippet below is the code for create function:

$guzzle = new Client;
$response = $guzzle->post('http://192.168.1.6/oauth/client/create', [
    'form_params' => [
        'user_id' => Auth::user()->id,
        'name' => $request->input('name'),
        'desc' => $request->input('desc'),
        'company' => $request->input('company'),
        'website' => $request->input('website'),
        'redirect' => $request->input('redirect'),
    ],
]);

This is my route to go to my remote application and the local application:

Route::post('/oauth/client/create', ['uses' => 'ClientsController@create']);

Route::get('/oauth/client/view', 'ClientsController@view');
    Route::get('/settings/oauth/clients', 'SettingsController@clients')->name('settings.clients');
    
    Route::get('/settings/oauth/clients/create', 'SettingsController@createView')->name('settings.clients.create');

Appreciate if you can help me to find out the problem and tell me the way to fix it.



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

Aucun commentaire:

Enregistrer un commentaire