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.

Example 1: Laravel concat two columns with example

Display the application dashboard.

Read Also:  AngularJS Get Current Date Time Example

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 :

Read Also:  jQuery Fundamentals Tutorial with Examples

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.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *