У меня есть данные о моих проектах в laravel с ...
$aProjects = Project::all();
Я хочу получить полное имя создателя проекта с ...
foreach ($aProjects as $key => $project) {
$sFullName = $project->user->getFullName();
$project->fullName = $sFullName;
}
, хотя все данные проектов одинаковы, только для первого $ проекта я получил fullName
. для других у меня есть null
это getFullName()
функция в пользовательской модели
public function getFullName()
{
return $this->firstName ." ".$this->lastName;
}
с этим foreach
$a = [] ;
foreach ($aProjects as $key => $project) {
$a[$key]= $project->user;
}
dd($a);
laravel return
array:9 [
0 => App\User {#330
#fillable: array:5 [
0 => "firstName"
1 => "lastName"
2 => "userName"
3 => "email"
4 => "password"
]
#hidden: array:2 [
0 => "password"
1 => "remember_token"
]
#casts: array:1 [
"users_email_verified_at" => "datetime"
]
#connection: "mysql"
#table: "users"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:10 [
"id" => 1
"firstName" => "komail"
"lastName" => "fayazbakhsh"
"role" => 1
"email" => "komail.f67@gmail.com"
"email_verified_at" => null
"password" => "$2y$10$M5mRU1QkZ84nSkkalAlyVOpcP2jIYUUDF9jMicFxqzw6Xc3V85FQS"
"remember_token" => null
"created_at" => "2019-12-30 19:41:11"
"updated_at" => "2019-12-30 19:41:11"
]
#original: array:10 [
"id" => 1
"firstName" => "komail"
"lastName" => "fayazbakhsh"
"role" => 1
"email" => "komail.f67@gmail.com"
"email_verified_at" => null
"password" => "$2y$10$M5mRU1QkZ84nSkkalAlyVOpcP2jIYUUDF9jMicFxqzw6Xc3V85FQS"
"remember_token" => null
"created_at" => "2019-12-30 19:41:11"
"updated_at" => "2019-12-30 19:41:11"
]
#changes: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#visible: []
#guarded: array:1 [
0 => "*"
]
#rememberTokenName: "remember_token"
}
1 => App\User {#339
#fillable: array:5 [
0 => "firstName"
1 => "lastName"
2 => "userName"
3 => "email"
4 => "password"
]
#hidden: array:2 [
0 => "password"
1 => "remember_token"
]
#casts: array:1 [
"users_email_verified_at" => "datetime"
]
#connection: "mysql"
#table: "users"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:10 [
"id" => 2
"firstName" => "kasra"
"lastName" => "karami"
"role" => 3
"email" => "kasra@gmail.com"
"email_verified_at" => null
"password" => "$2y$10$wSVxxFFF7uWztfP7ZPytaOT.PPUJObnddLdyMWRIKLgfVa7JjZEqu"
"remember_token" => null
"created_at" => "2019-12-30 19:42:20"
"updated_at" => "2019-12-30 19:42:20"
]
#original: array:10 [
"id" => 2
"firstName" => "kasra"
"lastName" => "karami"
"role" => 3
"email" => "kasra@gmail.com"
"email_verified_at" => null
"password" => "$2y$10$wSVxxFFF7uWztfP7ZPytaOT.PPUJObnddLdyMWRIKLgfVa7JjZEqu"
"remember_token" => null
"created_at" => "2019-12-30 19:42:20"
"updated_at" => "2019-12-30 19:42:20"
]
#changes: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#visible: []
#guarded: array:1 [
0 => "*"
]
#rememberTokenName: "remember_token"
}
2 => null
3 => null
4 => null
5 => null
6 => null
7 => null
8 => null
]
В чем причина этих нулевых значений?