Laravel Concatenation: Combining Two Columns with Examples

In this article, we will explore different ways to concatenate two columns in Laravel applications, specifically in versions 6, 7, 8, 9, and 10.

Concatenating columns is useful when you want to display the combined result of two or more columns in a single query.

We will cover two methods to achieve this: using Laravel Query Builder with DB raw and using Laravel Eloquent Model Scope. Both methods have their advantages and limitations, so choose the one that suits your needs best.

Before we dive into the examples, let’s ensure that you have the necessary prerequisites in place. You should have a working Laravel application with a User model and a database connection.

Make sure you have the required columns in the database schema for this example, such as ‘first_name’ and ‘last_name’. Now, let’s get started with the two methods.

Read more