The SQL just like this:
select a,b,concat(a,b) from table
But we don't want to use raw sql(whereRaw() and so on), we want to use ORM and the Query Constructor.
You can do like this:
1. Attribute mode: In your model
Add
protected $appends = ['con_cat'];
public function getConCatAttribute()
{
return $this->attributes['A'].$this->attributes['B']
}
Now you can use
$yourModel->con_cat
2. Function mode: In your model
public function concatAB()
{
return $this->attributes['A'].$this->attributes['B']
}
Now you can use
$yourModel->concatAB()
You can use Raw Expression for concat in ORM and the Query Constructor. Like below :
Model::select('a','b',\DB::raw("concat(a,' ',b)"))
->get();