Topic: Jobs

Laravel 6 concatenate Multiple Columns with Example 0

Laravel 6 concatenate Multiple Columns with Example

Today, We want to share with you Laravel 6 concatenate Multiple Columns with Example.In this post we will show you CONCAT columns with Laravel 6 eloquent, hear for How to concatenate columns with Laravel 6 Eloquent we will give you demo and example for implement.In this post, we will learn about How to select concat columns with Laravel 6 Query Builder? with an example.

Laravel 6 concatenate Multiple Columns with Example

There are the Following The simple About Laravel 6 concate nate Multiple Columns with Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel concat two columns with example, so the laravel 6 query builder concat in where clause for this example is following below.

Example 1: Laravel concat two columns with example

Display the application dashboard.

public function index()
{
    $products = Product::select("*", DB::raw("CONCAT(products.full_title,' ',products.title) as full_title"))
        ->get();
  
    return view('home', compact('products'));
}

Example 2: set scope in your Laravel 6 model

<?php
  
namespace App;
  
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\Product as Authenticatable;
  
class Product extends Authenticatable
{
    use Notifiable;
   
    protected $fillable = [
        'full_title', 'title', 'details', 'secure','type','is_active',
    ];

    protected $hidden = [
        'secure', 'remember_token',
    ];
   
    protected $casts = [
        'product_verified_at' => 'datetime',
    ];
   
    public function getFullNameAttribute()
    {
        return "{$this->full_title} {$this->title}";
    }
  
}

Use:

@foreach ($products as $product)

    {{ $product->full_name }}

@endforeach

Use Pluck Concat Two Columns:


$products = Product::select("id", DB::raw("CONCAT(products.full_title,' ',products.title) as full_name"))
        ->pluck('full_name', 'id');
  
dd($products);    

Web Programming Tutorials Example with Demo

Read :

Summary

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

I hope you get an idea about PHPLaravel 6 concatenate Multiple Columns with Example.
I would like to have feedback on my infinityknow.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 6 Guzzle HTTP Client Request Example 0

Laravel 6 Guzzle HTTP Client Request Example

Today, We want to share with you Laravel 6 Guzzle Client Request Example.In this post we will show you Guzzle http client request tutorial with Laravel 6, hear for Make a GET and POST Request from Laravel 6 With Guzzle we will give you demo and example for implement.In this post, we will learn about Guzzle http client GET and POST request example in Laravel 6 with an example.

Laravel 6 Guzzle HTTP Client Request Example

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

As I will cover this Post with live Working example to develop laravel 6 guzzle service provider, so the laravel 6 guzzle post form data for this example is following below.

Laravel 6 Install Package:

Install Package:

Fisrt of all we shall simple step to install PHP “guzzlehttp/guzzle package” as well as we can simply use their some Http GET, POST, PUT and DELETE Curl method Therefor let’s step by step execute bellow command.

composer require guzzlehttp/guzzle

Example of Requests Using Guzzle: : And then here i shall step by step Explaing you how to execute all above listed methods request you can use Laravel 6 to following controller method:

Laravel 6 Http Client “GET” Request Example

GET Request:

public function getProductsRequest()
{
    $app_client = new \GuzzleHttp\Client();
    $api_request = $app_client->get('http://your_api_domain_name.com');
    $results_data = $api_request->getBody();
   
    dd($results_data);
}

Laravel 6 Http Client “POST” Request Example

POST Request:

public function postProductsRequest()
{
    $app_client = new \GuzzleHttp\Client();
    $url = "http://your_api_domain_name.com/api/products";
   
    $products_data['p_details'] = "details of the products";
    $api_request = $app_client->post($url,  ['body'=>$products_data]);
    $results_data = $api_request->send();
  
    dd($results_data);
}

Laravel 6 Http Client “PUT” Request Example

PUT Request:

public function putProductsRequest()
{
    $app_client = new \GuzzleHttp\Client();
    $url = "http://your_api_domain_name.com/api/products/1";
    $products_data['p_details'] = "details of the products";
    $api_request = $app_client->put($url,  ['body'=>$products_data]);
    $results_data = $api_request->send();
   
    dd($results_data);
}

Laravel 6 Http Client “DELETE” Request Example

DELETE Request:

public function deleteProductsRequest()
{
    $app_client = new \GuzzleHttp\Client();
    $url = "http://your_api_domain_name.com/api/products/1";
    $api_request = $app_client->delete($url);
    $results_data = $api_request->send();
  
    dd($results_data);
}

Web Programming Tutorials Example with Demo

Read :

Summary

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

I hope you get an idea about Laravel 6 Guzzle HTTP REQUEST Client Request Example.
I would like to have feedback on my infinityknow.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.

PHP access global variable in function 0

PHP access global variable in function

Today, We want to share with you PHP access global variable in function.In this post we will show you PHP $GLOBALS (super global) variable, hear for Accessing a Global Variable Inside a Function we will give you demo and example for implement.In this post, we will learn about How to assign global variable value in a function in php? with an example.

PHP access global variable in function

There are the Following The simple About PHP access global variable in function Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to use global variable inside function in php, so the php global variable in function for this example is following below.

Way : 1 php access variable outside function

// global scope
$product_data = "Old Product Data Value";

function product_function($data) {
   global $product_data;
   $product_data = "New Data value";
}

function category_function(){
    global $product_data;
    product_function("test test test");
}

Way : 2 php set global variable in function

function foo(){
  $GLOBALS['product_id'] = 'product_id';
}
function bar(){
  echo $GLOBALS['product_id'];
}
foo();
bar();

Way : 3 php global variable across files

<?php

//this is old value
$product_data = "Old Product Data Value";

//need to change the value of global variable
product_function($product_data);
echo $product_data;

function product_function(&$data) {
    $data = "New value";
}
?>

Way : 4 Declaring a global variable inside a function

// global scope
$product_id = 1;

product_function($rid){
   global $product_id;
   $product_id = $rid;
}

category_function(){
    global $product_id;
    sendValue($product_id);
}

Way : 5 PHP Global Variable Example: Playing with Scope in PHP

$global = "I am a global variable because I wasn't defined inside a function.";

product_function();
category_function($global);
function product_function() { 
     global $global; 
     echo $global;
}

function category_function($global) {
     echo $global;
}

function category_else_global() {
    global $category_global;
    $category_global = "I'm global becuase the word global was used inside a function.";
}
category_else_global();
echo $category_global;

Web Programming Tutorials Example with Demo

Read :

Summary

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

I hope you get an idea about PHP access global variable in function.
I would like to have feedback on my infinityknow.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.

PHP Array Tutorial With Examples – filter array 0

PHP Array Tutorial With Examples

Today, We want to share with you PHP Array Tutorial With Examples.In this post we will show you PHP Arrays Cheatsheet – everything you need to know, hear for Top Most Frequently Used And Useful PHP Array Operations we will give you demo and example for implement.In this post, we will learn about PHP Indexed, Associative, and Multidimensional Arrays with an example.

PHP Array Tutorial With Examples – filter array

There are the Following The simple About PHP Array Tutorial With Examples Full Information With Example and source code.

As I will cover this Post with live Working example to develop php filter multidimensional array by value, so the some remove blank value from array php for this example is following below.

How to Filter Array by Value in PHP

Simple PHP array_filter() methods filters all the data elements of an array using a simple userdefine callback function as well as returns the filtered data array. Here I shall provide a short scripts to filter data elements of an array that all the contain a specific data value. It will help you to filter an array based on specific if else or any condition with PHP Array Tutorial With Examples.

$players = array(
    'first' => 'Ajay',
    'second' => 'Rahul',
    'third' => 'Virat'
);

$filter_product_array = array_filter($players, function ($param) {
    return (strpos($param, 'Aja') === false);
});

// Output the filtered array
print_r($filter_product_array);

php filter multidimensional array by value

This Example show to you Filtering Multi-Dimensional Arrays in PHP

Input Array

Array
(
    [0] => Array
        (
            [name] => Jasurya
            [email] => [email protected]
            [dept] => Manager
        )

    [1] => Array
        (
            [name] => Binny
            [email] => [email protected]
            [dept] => ERP
        )

    [2] => Array
        (
            [name] => Austin
            [email] => [email protected]
            [dept] => HR
        )

    [3] => Array
        (
            [name] => Vishal
            [email] => [email protected]
            [dept] => Manager
        )

    [4] => Array
        (
            [name] => Mayur
            [email] => [email protected]
            [dept] => ERP
        )

)

Example 2

<?php
$students = array(
    array("name"=>"Jasurya", "email"=>"[email protected]", "dept"=>"Manager"),
    array("name"=>"Binny", "email"=>"[email protected]", "dept"=>"ERP"),
    array("name"=>"Austin", "email"=>"[email protected]", "dept"=>"HR"),
    array("name"=>"Vishal", "email"=>"[email protected]", "dept"=>"Manager"),
    array("name"=>"Mayur", "email"=>"[email protected]", "dept"=>"ERP")
);

$filter = "ERP";

$new_array = array_filter($students, function($var) use ($filter){
    return ($var['dept'] == $filter);
});

echo "<pre>";
print_r($new_array);
?>

Output:

Array
(
    [1] => Array
        (
            [name] => Binny
            [email] => [email protected]
            [dept] => ERP
        )

    [4] => Array
        (
            [name] => Mayur
            [email] => [email protected]
            [dept] => ERP
        )

)

PHP array_merge Function

<?php
$product_color=array(3=>"red",4=>"green");
print_r(array_merge($product_color));
echo "<br/>";

$product_color1=array("a"=>"red","b"=>"green");
$product_color2=array("c"=>"blue","b"=>"yellow");
print_r(array_merge($product_color1,$product_color2));
echo "<br/>";

$product_color1=array("red","green");
$product_color2=array("blue","yellow");
print_r(array_merge($product_color1,$product_color2));
?>

Filtering Array by Mutiple Key Values:

Consider the following example

<?php
$students = array(
    array("name"=>"Jasurya", "email"=>"[email protected]", "dept"=>"Manager"),
    array("name"=>"Binny", "email"=>"[email protected]", "dept"=>"ERP"),
    array("name"=>"Austin", "email"=>"[email protected]", "dept"=>"HR"),
    array("name"=>"Vishal", "email"=>"[email protected]", "dept"=>"Manager"),
    array("name"=>"Mayur", "email"=>"[email protected]", "dept"=>"ERP")
);

$filter = array("Binny", "Vishal");

$new_array = array_filter($students, function($var) use ($filter){
    return in_array($var['name'], $filter);
});
echo "<pre>";
print_r($new_array);
?>

Output:

Array
(
    [1] => Array
        (
            [name] => Binny
            [email] => [email protected]
            [dept] => ERP
        )

    [3] => Array
        (
            [name] => Vishal
            [email] => [email protected]
            [dept] => Manager
        )

)

php filter array of objects

$new_array = array_filter($array, function($obj){
    if (isset($obj->products)) {
        foreach ($obj->products as $product) {
            if ($product->id == 11) return false;
        }
    }
    return true;
});

array filter php

<?php
function even($value)
{
  return $value % 2 == 0;
}

$pids = [1, 2, 3, 4, 5];
print_r(array_filter($pids,"even"));

PHP ARRAY_FILTER_USE_KEY

<?php
$pids = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4];
$data = array_filter($pids, function($k) {
  return $k == 'b';
}, ARRAY_FILTER_USE_KEY);
print_r($data);

php array map

<?php
function playerFilter($v)
{
if ($v==="Virat")
  {
  	return "Anushnka";
  }
return $v;
}

$players=array("Yuvraj","Virat","Pant");
print_r(array_map("playerFilter",$players));
?>

php array filter by list of keys

array_filter_key.php

function array_filter_key(array $array, $callback)
{
	$same_keys = array_filter(array_keys($array), $callback);
	return array_intersect_key($array, array_flip($same_keys));
}

remove blank value from array php

Remove Empty Array Elements In PHP

array_filter() example

<?php
$movies = array("Tamilrokers", "Tamil", "South", "", "Bollywood", null, 0);
print_r(array_filter($movies)); // removing blank, null, false, 0 (zero) values
?>

array_filter() example with reindex array elements

<?php
$movies = array("Tamilrokers", "Tamil", "South", "", "Bollywood", null, 0);
print_r(array_values(array_filter($movies)));
?>

php get array value by key

Find array value using key

<?
$arr=array('us'=>'United', 'ca'=>'canada');
$key='ca';
echo $arr[$key];
?>

It’s as simple as this :

$array[$key];

php filter dictionary

filter array values from a dictionary

function checkIsDictionary($array,$dictionary){
  foreach($array as $array_item){
    if(!in_array($array_item,$dictionary)){
      return false;
    }
  }
 return true;
}

Web Programming Tutorials Example with Demo

Read :

Summary

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

I hope you get an idea about PHP Array Tutorial With Examples.
I would like to have feedback on my infinityknow.com web 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.