DeveloperBreeze

Laravel Programming Tutorials, Guides & Best Practices

Explore 51+ expertly crafted laravel tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.

Handling HTTP Requests and Raw Responses in Laravel

Tutorial October 24, 2024
php

use Illuminate\Support\Facades.Http;

$response = Http::post('https://api.example.com/endpoint', [
    'key1' => 'value1',
    'key2' => 'value2',
]);

$data = $response->json(); // Automatically parses JSON response into an associative array
dd($data);
  • $response->json(): Decodes the JSON response to an associative array automatically, allowing you to work with it directly in PHP.

Building a Custom E-commerce Platform with Laravel and Vue.js

Tutorial August 27, 2024
javascript php

This command sets up authentication routes, controllers, and views. It also installs Vue.js and integrates the necessary frontend components.

Run the migrations to create the users table:

Integrating and Using NMI Payment Gateway in Laravel

Tutorial August 14, 2024
php

   public function addCustomerVault($creditCard)
   {
       $data = [
           'ccnumber' => $creditCard['cc_number'],
           'ccexp' => $creditCard['exp_date'],
           'cvv' => $creditCard['cvv'],
           'customer_vault' => 'add_customer',
           'security_key' => $this->securityKey,
       ];

       if ($this->production === false) {
           $data['test_mode'] = 'enabled';
       }

       $createVaultCurl = curl_init();
       curl_setopt_array($createVaultCurl, [
           CURLOPT_URL => $this->url,
           CURLOPT_RETURNTRANSFER => true,
           CURLOPT_POST => true,
           CURLOPT_POSTFIELDS => http_build_query($data),
           CURLOPT_SSL_VERIFYHOST => false,
           CURLOPT_SSL_VERIFYPEER => false,
       ]);
       $createVaultResponse = curl_exec($createVaultCurl);
       curl_close($createVaultCurl);

       \Log::info('NMI Vault Response: ' . $createVaultResponse);

       if ($createVaultResponse === false) {
           return [
               'responsetext' => 'error',
               'error' => 'Customer vault creation failed',
           ];
       }

       parse_str($createVaultResponse, $vaultResponseArray);
       return isset($vaultResponseArray['customer_vault_id']) ? $vaultResponseArray['customer_vault_id'] : null;
   }

This method takes in credit card details, formats them, and sends a CURL request to the NMI API to add the customer to the vault. If the application is in test mode, it returns a mock response. The method logs the response using Laravel's standard logging mechanism.