Topic: Laravel

Laravel cURL Send HTTP Request Example 0

Laravel cURL Send HTTP Request Example

Today, We want to share with you Laravel cURL Send HTTP Request Example.In this post we will show you cURL request in Laravel, hear for Laravel 5.7 curl request example using ixudra/curl package we will give you demo and example for implement.In this post, we will learn about Laravel PHP guzzle http client GET and POST request example with an example.

Laravel cURL Send HTTP Request Example

There are the Following The simple About Laravel cURL Send HTTP Request Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel 5.7 curl request, so the some php laravel curl for this example is following below.

Make GET Request

Laravel PHP http client GET request Example

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://your_website_name.com",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_TIMEOUT => 30000,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => array(
        // Set Here Your Requesred Headers
        'Content-Type: application/json',
    ),
));
$results = curl_exec($curl);
$resErrors = curl_error($curl);
curl_close($curl);

if ($resErrors) {
    echo "Your cURL Error #:" . $resErrors;
} else {
    print_r(json_decode($results));
}

Crate a Laravel POST Request

Laravel PHP http client POST request Example

// Call a Post Fields Array
$message = [
    'message1' => 'Value_of_the_data',
    'message2' => 'Your_data_string',
];

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://your_website_name.com",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30000,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => json_encode($message),
    CURLOPT_HTTPHEADER => array(
        // Set here Laravel Post required headers
        "accept: */*",
        "accept-language: en-US,en;q=0.8",
        "content-type: application/json",
    ),
));

$results = curl_exec($curl);
$resErrors = curl_error($curl);

curl_close($curl);

if ($resErrors) {
    echo "Your cURL Error #:" . $resErrors;
} else {
    print_r(json_decode($results));
}

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel cURL Send HTTP Request Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Laravel Create Custom Helper Class Example 0

Laravel Create Custom Helper Class Example

Today, We want to share with you Laravel Create Custom Helper Class Example.In this post we will show you Creating a Helpers file in a Laravel App, hear for Creating your own PHP helper functions in Laravel we will give you demo and example for implement.In this post, we will learn about How To Create A Custom Helper Class In Laravel MVC with an example.

Laravel Create Custom Helper Class Example

There are the Following The simple About Laravel Create Custom Helper Class Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel 5.7 custom helper functions, so the create custom helper in laravel 5.7 for this example is following below.

Step : 1 Create Laravel helpers.php file

app/helpers.php

<?php

function getMemberProfile($id) {
    $data = \DB::table('users')
        ->select(\DB::raw('CONCAT(firstname, " ", lastname) as username'))
        ->where('id', $id)
        ->first();

    return $data->username;
}

Step : 2 Add app/helpers.php file in composer.json file

app/helpers.php

"autoload": {
    "classmap": [
        ...
    ],

    "psr-4": {
        "App\": "app/"
    },

    "files": [
        "app/helpers.php" //Add This Line
    ]
},

After done this then once we are run following command.

composer dump-autoload

Step : 3 Use Custom Laravel Helper In Controller

Create a Laravel Controller

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Auth;

class HomeController extends Controller
{   
    
    public function index()
    {
        $fullprofiledetails = getMemberProfile(Auth::user()->id);
        dd($fullprofiledetails);
    }

}

Step : 4 Use Custom Laravel Helper In Blade File

Laravel Blade View Files

@extends('layouts.app')

@section('content')

<?php
    $fullprofiledetails = getMemberProfile(Auth::user()->id);
    dd($fullprofiledetails);
?>

@endsection

Angular 6 CRUD Operations Application Tutorials

Read :

Create A Custom Helper Class In Laravel MVC

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel Create Custom Helper Class Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Create Custom 404 Error page in laravel Example 0

Create Custom 404 Error page in laravel Example

Today, We want to share with you Create Custom 404 Error page in laravel Example.In this post we will show you How to create custom 404 error page in Laravel, hear for Creating A Laravel 404 Page Using Custom Exception Handlers we will give you demo and example for implement.In this post, we will learn about laravel redirect if route not found with an example.

Create Custom 404 Error page in laravel Example

There are the Following The simple About Create Custom 404 Error page in laravel Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to create custom 404 page in laravel, so the laravel 5 custom 404 for this example is following below.

step : 1 Install laravel 5.6 project

create new laravel project

composer create-project --prefer-dist laravel/laravel simplelaravelblog

step : 2 change in Handler File

app/Exceptions/Handler.php file

<?php
public function render($request, Exception $exception)
{
    if($this->isHttpException($exception))
    {
        switch ($exception->getStatusCode()) 
            {
            //here call not found
            case 404:
            return redirect()->route('notfound');
            break;

            //Laravel internal error
            case '500':
            return redirect()->route('notfound');
            break;

            default:
                return $this->renderHttpException($e);
            break;
        }
    }
    else
    {
            return parent::render($request, $exception);
    }
}

step : 3 create route

Make a Laravel Route page not found

Route::get('notpagefound', ['as' => 'notfound', 'uses' => '[email protected]']);

step : 4 create notpagefound()

app/http/ProductController.php

public function notpagefound()
{
    return view('errors.notpagefound');
}

step : 5 Laravel create 404 page

resources/views/errors folder

<!DOCTYPE html>
<html>
<head>
    <title>Page Not Found - Creating A Laravel 404 Page Using Custom Exception Handlers</title>
</head>
<body>
    <h1>Sorry, Page Not Found</h1>
    <h6>Page not found - YourWebsite.com</h6>
</body>
</html>

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Create Custom 404 Error page in laravel Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Laravel JSON Encode Decode Handling 0

Laravel JSON Encode Decode Handling

Today, We want to share with you Laravel JSON Encode Decode Handling.In this post we will show you Convert and Loop through JSON with Laravel, hear for get data from json array in Laravel 5.7 we will give you demo and example for implement.In this post, we will learn about get the data from an array of JSONarray from Laravel 5.7 with an example.

Laravel JSON Encode Decode Handling

There are the Following The simple About Laravel JSON Encode Decode Handling Full Information With Example and source code.

As I will cover this Post with live Working example to develop Handling JSON Data in Laravel 5.7, so the laravel 5.7 return view with json data for this example is following below.

JSON encoded database column

[{
    "title": "Vuejs",
    "points": 0,
    "tags": [{
        "type": "Core",
        "uid": 45
    }]
}, {
    "title": "Angularjs",
    "points": 2,
    "tags": [{
        "type": "MVC",
        "uid": 1
    }]
}]

Laravel 5.7 – Get specific array in JSON encoded database column

$postData = json_decode($post->data, true);
dd($postData);

json decode laravel controller

Laravel Decode JSON

foreach (json_decode($response) as $area)
{
	print_r($area);
}

Encoding JSON Data

<?php
// An associative array
$marks = array("Vuejs"=>65, "Laravel"=>80, "PHP"=>78, "Angularjs"=>90);
 
echo json_encode($marks);
?>

Decoding JSON Data

<?php
$json = '{"Vuejs":65,"Laravel":80,"PHP":78,"Angularjs":90}';
 
var_dump(json_decode($json));
?>

Laravel Controller and Route Setup

create a new controller in Laravel 5.7

php artisan make:controller HomeController

# app/Http/Controllers/HomeController.php
...
use App\Product;

class HomeController extends Controller
{
    public function getProducts() {
        $products = Product::all();
        return $products;
    }
}

Formatting JSON data in Laravel

json_encode() to simple way to encode arrays into JSON string format.

$array = array('JavaScript','Magento','Vuejs');
return json_encode($array);

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel JSON Encode Decode Handling.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Dynamic QR codes Generator in Laravel 5.7 0

Dynamic QR codes Generator in Laravel 5.7

Today, We want to share with you Dynamic QR codes Generator in Laravel 5.7.In this post we will show you laravel 5.7 qr code generator example, hear for simple qr code generator laravel we will give you demo and example for implement.In this post, we will learn about qr code generator in laravel 5.7 with an example.

Dynamic QR codes Generator in Laravel 5.7

There are the Following The simple About Dynamic QR codes Generator in Laravel 5.7 Full Information With Example and source code.

As I will cover this Post with live Working example to develop simple-qrcode laravel example, so the Design QR Code generator for this example is following below.

Step 1: Install Laravel 5.7

Simple Laravel 5.7 Latest version Install step by step in CMD(werneckbh/laravel-qr-code)

composer create-project --prefer-dist laravel/laravel atmiya25

Step 2: Install Laravel qrcode Package

simple-qrcode plugin use in Laravel 5.7

composer require simplesoftwareio/simple-qrcode

config/app.php

'providers' => [
	....
	SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class
],
'aliases' => [
	....
	'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class
],

Step 3: Create a Laravel Route

routes/web.php

<?php
Route::get('qr-code-g', function () {
  \QrCode::size(500)
            ->format('png')
            ->generate('pakainfo.com', public_path('images/qrcode.png'));
    
  return view('qrCode');
    
});

Step 4: Create Laravel 5.7 Blade file

resources/views/qrCode.blade.php

<!DOCTYPE html>
<html>
<head>
	<title>Simple Laravel 5.7 - QR Code Generator Example : Pakainfo.com</title>
</head>
<body>
    
<div class="visible-print text-center">
	<h1>Laravel 5.7 - QR Code Generator Demo - Pakainfo.com</h1>
    {!! QrCode::size(250)->generate('pakainfo.com'); !!}
     
    <p>example by www.pakainfo.com.</p>
</div>
    
</body>
</html>

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Dynamic QR codes Generator in Laravel 5.7.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.