【发布时间】:2018-05-05 21:39:37
【问题描述】:
我想获取一些数据,但它说它不知道变量:
我得到的错误:
ErrorException in dbda158712a631f22ffd888cd244c74e60f3a433.php line 51:
Undefined variable: albums (View: /var/www/clients/client2/web2/web/resources/views/album.blade.php)
这是我的代码:
Album.blade.php
@foreach($albums as $others)
<option value="{{$others->id}}">{{$others->name}}</option>
@endforeach
我的相册控制器功能
public function getAlbum($id)
{
$album = Album::with('Photos')->find($id);
return View::make('album')
->with('album',$album);
}
public function getList()
{
$albums = Album::with('Photos')->get();
return View::make('index')
->with('albums',$albums);
}
【问题讨论】:
-
使用
@foreach($album as $others) -
@CharlotteDunois 这给了我以下错误:尝试获取非对象的属性
-
发布完整错误信息
-
返回视图怎么样('album', ['album' => $album]):
-
ErrorException in dbda158712a631f22ffd888cd244c74e60f3a433.php line 52: Trying to get property of non-object (View: /var/www/clients/client2/web2/web/resources/views/album.blade.php)