Getting cURL error 3: <url> malformed (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) error after saving models in laravel 5.4

Viewed 60838

I am having this error cURL error 3: <url> malformed (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) after saving/creating multiple models to database.

I have this in my controller:

public function storeTruck(Request $request){
    //Save Company Detail
    $company = Company::Create($request->only(['company']));
    // Save Trucker Info
    $request->request->add(['password'=>bcrypt('trucker')]);
    $request->request->add(['company_id'=>$company->id]);
    $trucker = Trucker::create( $request->only([
        'first_name','last_name','company',
        'email','contact', 'password', 'company_id'
    ]));
    return view('admin.truck.list'); 
}

Those models are saved successfully in database but it will then proceed to a cURL error 3 problem. What causes this error based on the codes? Please advice. Thanks.

4 Answers

I made a mistake when instantiating the the Guzzle Client Object:

Rather than assigning my baseUrl to th 'base_uri' key as below,

$client = new Client([
        'base_uri' => $this->baseUrl
    ]);

I assigned the $baseUrl to the 'base_uri' key, which does not exist.

$client = new Client([
        'base_url' => $this->baseUrl
    ]);

Be careful when doing this. make sure you use 'base_uri' instead of 'base_url.

  1. Download download cacert.pem.
  2. Save the file "cacert.pem" to your computer. For example C:\PHP\cacert.pem
  3. Add the location of the "cacert.pem" file to your php.ini file.
    Search for [curl.cainfo] in your php.ini file and update the following line:
    curl.cainfo = "C:\PHP\cacert.pem"
  4. Restart your web server.
php artisan config:cache
php artisan cache:clear

I received the same error on Guzzle with WPEngine. I solved it by changing the protocol on the base_uri, from 'https' to 'http'

Related