它可能被问了一百万次,但我似乎无法得到正确的答案!
我如何在外部向laravel应用程序发出请求并进行处理?
这是我到目前为止(从其他堆栈溢出问题构建),
我的网站
//Send details to Laravel System
$url = 'http://mylaravelsystem.fake/processExternalData';
$data = array('firstname' => $name_first, 'lastname' => $name_last, 'email_address' => $email, 'method' => 4);
$ch = curl_init($url);
# Form data string
$postString = http_build_query($data, '', '&');
# Setting our options
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
# Get the response
$response = curl_exec($ch);
curl_close($ch);
我的Laravel应用程序
路线> 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());
}
我的任务是能够向我的laravel应用程序发送POST请求并将其插入数据库。我是否遗漏了CSRF令牌的内容?
很抱歉,如果这是一个愚蠢的问题,我似乎无法弄明白!