Laravel 6 concatenate Multiple Columns with Example

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.

  Angularjs ng-keypress Event Handling Directive

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 :

  Merger of vodafone and Idea News

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.

Leave a Reply

avatar
  Subscribe  
Notify of