我正在创建一个用户配置文件, 我正在尝试 TITRE_ANNONCE
在选择 div 中显示, 但我收到错误:
试图获取非对象的属性
这是我的表格:
@foreach($user as $annonce)
{{$annonce->TITRE_ANNONCE}}
@endforeach
与我的控制器:
public function voirprofile($id) {
$user = DB::table('users')->
join('article', 'article.id', '=', 'users.id')->
join('annonce', 'annonce.ID_ARTICLE', '=', 'article.ID_ARTICLE')->
where('users.id', $id)->
get();
return view('voirprofile') - > with('user', $user);
}
$user 有用户信息与所有的 ' 年文 ' 的, 他发布。这就是 $user 返回的内容:
[
{
"id":1,
"name":"Othmane Messaoud",
"email":"othmane.messaoud@gmail.com",
"password":"$2y$10$at2J0teHoorwI7Y396Ckh.l1EvRojWJzomx4Ccqsf9LYA0j0oRxl.",
"ville":"Rabat",
"region":"Irfan",
"ID_Ville":1,
"tele_user":642213124,
"type_user":0,
"adresse":"Maroc, Rabat Al Irfan ENSIAS",
"presentation":"je m'appelle othmane",
"remember_token":"RPoRKcupcaBujbYoUj0e7QlmYaq0ybrhiKg3bHDwtQNK02DxLa7DPAi1QwsX",
"created_at":"2019-03-30 13:56:06",
"updated_at":"2019-03-30 13:56:06",
"ID_ARTICLE":1,
"TYPE_ARTICLE":"1",
"NOM_ARTICLE":"Le maitre des illusions",
"DESCRIPTION_ARTICLE":"ici la description de mon livre 'Le maitre des illusions' !!",
"ID_ANNONCE":1,
"TITRE_ANNONCE":"Annonce 1",
"DATE_DEPOT":null,
"TYPE_ANNONCE":"1",
"PRIX":200,
"ETAT_ANNONCE":1,
"MOTIF_REFUS":null
},
{
"id":1,
"name":"Othmane Messaoud",
"email":"othmane.messaoud@gmail.com",
"password":"$2y$10$at2J0teHoorwI7Y396Ckh.l1EvRojWJzomx4Ccqsf9LYA0j0oRxl.",
"ville":"Rabat",
"region":"Irfan",
"ID_Ville":1,
"tele_user":642213124,
"type_user":0,
"adresse":"Maroc, Rabat Al Irfan ENSIAS",
"presentation":"je m'appelle othmane",
"remember_token":"RPoRKcupcaBujbYoUj0e7QlmYaq0ybrhiKg3bHDwtQNK02DxLa7DPAi1QwsX",
"created_at":"2019-04-09 15:39:30",
"updated_at":"2019-04-09 15:39:30",
"ID_ARTICLE":84,
"TYPE_ARTICLE":"livre",
"NOM_ARTICLE":"zednumber5",
"DESCRIPTION_ARTICLE":"fsd",
"ID_ANNONCE":26,
"TITRE_ANNONCE":"voilae",
"DATE_DEPOT":"2019-04-09 17:40:43",
"TYPE_ANNONCE":"1",
"PRIX":100,
"ETAT_ANNONCE":1,
"MOTIF_REFUS":null
},
{
"id":1,
"name":"Othmane Messaoud",
"email":"othmane.messaoud@gmail.com",
"password":"$2y$10$at2J0teHoorwI7Y396Ckh.l1EvRojWJzomx4Ccqsf9LYA0j0oRxl.",
"ville":"Rabat",
"region":"Irfan",
"ID_Ville":1,
"tele_user":642213124,
"type_user":0,
&
尝试
@foreach($user as $annonce)
{{$annonce['TITRE_ANNONCE']}}
@endforeach
使用可选的帮助程序
@foreach($user as $annonce)
{{optional($annonce)->TITRE_ANNONCE}}
@endforeach
改变
{{{$annonce > TIRE _ ANNACE}}
自
{{可选 ($annonce)-> TITRE _ ANONCE}}