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.

Laravel ajax get Request Example From Scratch 0

Laravel ajax get Request Example From Scratch

Today, We want to share with you Laravel ajax get Request Example From Scratch.In this post we will show you Create Live Search In Laravel Using AJAX, hear for Laravel 5.7 Jquery Ajax Request Example From Scratch we will give you demo and example for implement.In this post, we will learn about AJAX call to a Laravel controller function / method with an example.

Laravel ajax get Request Example From Scratch

There are the Following The simple About Laravel ajax get Request Example From Scratch Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel 5.7 Ajax GET and POST examples, so the Laravel 5.7 AJAX GET and show new data for this example is following below.

Step 1 : Define a Laravel Routes

Add Routes for Ajax Request:routes/web.php

Route::get('productGetReq', '[email protected]');
Route::post('productGetReq', '[email protected]');

Step 2: Create a Laravel Controller methods:

app/Http/Controllers/ProductController.php

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProductController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function productGetReq()
    {
        return view('productGetReq');
    }
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function productGetReqPost()
    {
        $input = request()->all();
        return response()->json(['success'=>'Get All the Product Simple jQuery Ajax Request.']);
    }
}

Step 3 : Create Laravel Blade File:

resources/views/productGetReq.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>pakainfo.com - Laravel 5.7 Ajax Request example</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
    <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <meta name="csrf-token" content="{{ csrf_token() }}" />
</head>
<body>
    <div class="container">
        <h1>Create Live Search In Laravel Using AJAX - Pakainfo.com</h1>
        <form >
            <div class="form-group pakainfo">
                <label>Name:</label>
                <input type="text" name="name" class="form-control" placeholder="Name" required="">
            </div>
            <div class="form-group pakainfo">
                <label>company:</label>
                <input type="company" name="company" class="form-control" placeholder="company" required="">
            </div>
            <div class="form-group pakainfo">
                <strong>Qty:</strong>
                <input type="text" name="qty" class="form-control" placeholder="Qty" required="">
            </div>
            <div class="form-group pakainfo">
                <button class="btn btn-success save-product btn-submit">Submit</button>
            </div>
        </form>
    </div>
</body>
<script type="text/javascript">
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    $(".save-product").click(function(e){
        e.preventDefault();
        var name = $("input[name=name]").val();
        var company = $("input[name=company]").val();
        var qty = $("input[name=qty]").val();
        $.ajax({
           type:'POST',
           url:'/productGetReq',
           data:{name:name, company:company, qty:qty},
           success:function(data){
              alert(data.success);
           }
        });
	});
</script>
</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 Laravel ajax get Request Example From Scratch.
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 Autocomplete Live Search from database 0

Laravel Autocomplete Live Search from database using jQuery

Today, We want to share with you Laravel Autocomplete Live Search from database using jQuery.In this post we will show you Manual Laravel Autocomplete search from Database, hear for Laravel 5.7 Autocomplete Search from Database using Typeahead JS we will give you demo and example for implement.In this post, we will learn about Laravel Bootstrap Typeahead Autocomplete Search from Database with an example.

Laravel Autocomplete Live Search from database using jQuery

There are the Following The simple About Laravel Autocomplete Live Search from database using jQuery Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel 5.7 autocomplete search with typeahead.js, so the laravel 5.7 autocomplete from database for this example is following below.

Step 1:- Create Laravel the migration

command line and type

php artisan make:model tbl_data -m

structure of my migration

public function up()
{
	Schema::create('products', function (Blueprint $table) {
		$table->increments('id');
		$table->string('title');
		$table->string('slug');
		$table->timestamps();
	});
}

Step 2 : create a view resources/views

resources/views/autocomplete.blade.php

<html>
<head>
    <title>
       Laravel 5.7 jQUery Auto Complete - Pakainfo.com</title>
   <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">
   <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
   <style>

       * {
        margin: 0px auto; !important /* Aligning all the data to center */
    }
</style>

</head>
<body>
<h3>Laravel 5.7 Autocomplete Search from Database using Typeahead JS Example</h3>
    <div class="container" style="margin-top: 10px;">
        <div align="center">
            <div class="row">
                <div class="col-md-6">
                    <div class="row">
                        <div class="col-md-12">
                            <form action="">
                                <div class="form-group">
                                    <div class="ui-widget">
                                        <label for="">Search for Anything</label>
                                        <input id="searchString" type="text" name="search_string" placeholder="Enter Search String" class="form-control" />
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </center>
    </div>

    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
</body>
</html>

jQuery Code

Laravel Autocomplete Search from database using jQuery Source code

$( function() {
          $( "#searchString" ).autocomplete({
            //html : html,
            source: "display-search-queries",
            minLength: 1,
            select:function(e,ui) { 
                location.href = ui.item.link;
            }
        } );
      } );

Define a Laravel Route

Route::get('/','[email protected]');

Route::get('display-search-queries','[email protected]');

Step 3: Create Laravel Controller

ProductController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Response;
use DB;

class ProductController extends Controller
{
    public function index() {
        return view('autocomplete');
    }

    public function autoCompleteSearch(Request $request) {
        $querystr = $request->get('querystr');
    	$data = DB::table('products')->where("title","LIKE","%$querystr%")->select('title as value','slug as link')->get();
        return response()->json($data);
    }
}

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 Autocomplete Live Search from database using jQuery.
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 Dynamic active menu Example Tutorial 0

Laravel Dynamic active menu Example Tutorial

Today, We want to share with you Laravel Dynamic active menu Example Tutorial.In this post we will show you laravel active menu item, hear for laravel request is and laravel request::is we will give you demo and example for implement.In this post, we will learn about laravel 5.7 navigation menu with an example.

Laravel Dynamic active menu Example Tutorial

There are the Following The simple About Laravel Dynamic active menu Example Tutorial Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel 5.7 active class with active states laravel, so the some major files and Directory structures for this example is following below.

LARAVEL ADDING CLASS .ACTIVE TO CURRENT LINK

step 1: Create a helpers.php

function isActive($path)
{
    return Request::is($path . '*') ? ' active' :  '';
}

step 2: Add in composer.json files

"autoload": {
        "classmap": [
            "database"
        ],
        "files": [
            "app/helpers.php"
        ],
        "psr-4": {
            "App\": "app/"
        }
    },

step 3: How to use it:

<ul class="nav navbar-nav">
     
    <li class="{{ isActive('products') }}">
       <a href="{{ url('products') }}"><i class="fa fa-fw fa-user"></i> Products</a>
    </li>
 
 </ul>

Laravel 5.7 active menu item using request

<li class="{{ Request::is('status*') ? 'active' : '' }}">
    <a href="{!! route('status.index') !!}"><span>Status</span></a>
</li>
<li class="{{ Request::is('users*') ? 'active' : '' }}">
    <a href="{!! route('users.index') !!}"><span>Users</span></a>
</li>
<li class="{{ Request::is('roles*') ? 'active' : '' }}">
    <a href="{!! route('roles.index') !!}"><span>Roles</span></a>
</li>

Highlight Active Nav Links using Laravel

We can use ternary operator with 3 Examples. For example, We can check dynamic URI for the current ul > li route:

using ternary operator

<li{{ request()->is('product-types') ? ' class="active"' : '' }}>

using * as wildcard:

<li{{ request()->is('product-type-number-*') ? ' class="active"' : '' }}>

using check route name

<li{{ request()->route()->getName() === 'ProductType.index' ? ' class="active"' : '' }}>

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 Dynamic active menu Example Tutorial.
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 Custom Namespaces Example Tutorial 0

Laravel Custom Namespaces Example Tutorial

Today, We want to share with you Laravel Custom Namespaces Example Tutorial.In this post we will show you Namespaces in Laravel Applications, hear for Laravel – Namespaces Example we will give you demo and example for implement.In this post, we will learn about Laravel 5.7 CRUD Example Tutorial For Beginners with an example.

Laravel Custom Namespaces Example Tutorial

There are the Following The simple About Laravel Custom Namespaces Example Tutorial Full Information With Example and source code.

As I will cover this Post with live Working example to develop Custom namespaces, so the Laravel – Namespaces with Custom namespaces for this example is following below.

Declaration of namespace

The use keyword allows the developers to shorten the namespace.

use <Your-namespace-name>;

Example

Laravel Create a simple user defined namespace

php artisan app:name InfoProduct

Namespaces

Simple common use-case for Lravel route groups is assigning the Like PHP namespace to a group of controllers using the namespace method:

Route::namespace('User')->group(function () {
    // Laravel 5.7 Controllers Within The "App\Http\Controllers\User" Namespace
});

Custom namespaces in Laravel Example

Calling Lang:

Lang::get('web::group.name');

@trans('web::group.name');

Calling Blade View:

view('web::index')

view('web::partials.sidebar')

Laravel Calling Config:

Config::get('web.name')

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 Custom Namespaces Example Tutorial.
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.