我是laravel的新手。 我正在尝试路由到控制器,从模型中获取一些数据并将其传递给视图,如下所示:
class PlayerController extends Controller{
public function index(){
$data['start'] = Player::allPlayer()->get();
return View::make('pages.player')->with($data);
}
}
现在当我尝试在视图中读取$ data时。它说这是未定义的..
@if (isset($data))
{{'its there'}}
@else
{{'its not there'}}
@endif
我在做错了什么?我试图在控制器中print_r数组。它看起来不错......
答案 0 :(得分:0)
您必须通过密钥访问变量:
getData(FullName: string): Promise<PropertyNode[]> {
let body = JSON.stringify({ FullName });
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.dataUrl, body, options)
.toPromise()
.then(this.extractData)
.catch(this.handleError);
}
查看:
class PlayerController extends Controller{
public function index(){
$data['start'] = Player::allPlayer()->get();
return View::make('pages.player')->with($data);
}
}
答案 1 :(得分:0)
即使这应该有效
$post['hello'] = \App\Post::where('id','=',1)->get();
return view('test',compact('post'));
并在视野中
@if($post)
{{$post['hello']}}
@else
<p>Oops!</p>
@endif