Today, We want to share with you Laravel 6 CONCAT Multiple Columns with example.In this post we will show you CONCAT columns with Laravel 6 eloquent, hear for CONCAT Two Columns in Laravel with Example we will give you demo and example for implement.In this post, we will learn about laravel eloquent where concat with an example.
Laravel 6 CONCAT Multiple Columns with example
There are the Following The simple About laravel concatenate string in controller 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 concat two columns in laravel 6.2 query is used for this example is following below.
Example 1 : Laravel Wrap Query in DB::raw
query in DB::raw.
public function members() { $members = DB::table('members')->select("*", DB::raw("CONCAT(members.first_name,' ',members.last_name) AS full_name")) ->get(); foreach ($members as $member) { echo $member->full_name . '<br>'; } }
Example 2 : Using Pluck Method
use the pluck() method to concat two columns
public function members() { $members = DB::table('members')->select('id', DB::raw("CONCAT(members.first_name,' ',members.last_name) AS full_name"))->get()->pluck('full_name', 'id'); dd($members); }
Example 3 : Define Custom Method in Model
app/Member.php
protected $fillable = [ 'first_name', 'last_name', 'email', 'password', ]; public function getFullNameAttribute() { return "{$this->first_name} {$this->last_name}"; }
run the query and get full name
public function members() { $members = Member::get(); foreach ($members as $member) { echo $member->full_name . '<br>'; } }
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 concat in laravel 6.2 blade.
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.