Its probably been asked a million times but I can't seem to get the right answer!
How would I make a request to a laravel application externally and process it?
This is what I have so far (built from other stack overflow questions),
My Website
//Send details to Laravel System
$url = 'http://mylaravelsystem.fake/processExternalData';
$data = array('firstname' => $name_first, 'lastname' => $name_last, 'email_address' => $email, 'method' => 4);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
)
);
$context = stream_context_create($options);
My Laravel application
Routes > api.php
Route::post('/processExternalData', 'OptController@insertViaRequest');
OptController@insertViaRequest
//First create new candidate
$user = new Candidates;
$user->firstname = $request->firstname;
$user->lastname = $request->lastname;
$user->email_address = $request->email_address;
$user->created_by = 1;
if(!$user->save()){
Log::info((array) $user->save());
}
My task is to be able to send a POST Request to my laravel application and insert it into the database. Am I missing something with the CSRF Token?
Sorry if this is a stupid question, I just can't seem to figure it out!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire