0

I am trying to get the fullname from the database. but the data base doesn't have fullname but firstname lastname & middlename, I am new to laravel and i am trying to get the full name like this. but its giving me error

 'firstName' => $this->first_name,
 'middleName' => $this->middle_name,
 'lastName' => $this->last_name,
 'fullName' => $this->first_name + $this->middle_name + $this->last_name,
Kerry
  • 384
  • 3
  • 25
  • 2
    `$this->first_name . $this->middle_name . $this->last_name` use `.` to concat https://www.php.net/manual/en/language.operators.string.php#:~:text=The%20first%20is%20the%20concatenation,argument%20on%20the%20left%20side. – Kamlesh Paul Dec 22 '20 at 08:39
  • @Daan Today my first day in php. I don't know the terms use in php. I am searching how to merge data :D – Kerry Dec 22 '20 at 08:48

2 Answers2

2

easy to search but here you go:

$this->first_name .' '. $this->middle_name .' '. $this->last_name,
0

You can add it to your model. $user = User::find(1)

$user->fullName = $user->first_name.' '.$user->middle_name.' '.$user->lastName;