[英]Laravel 4 model controller view
how can i use this in the model 我如何在模型中使用它
now example 1 this work just fine... on the controller 现在示例1这项工作就很好...在控制器上
$songs = DB::table('songlist')
->join('historylist', 'songlist.id', '=', 'historylist.songID')
->select('songlist.*', 'historylist.*')
->orderBy('historylist.date_played', 'DESC')
->first();
return View::make('currentsong')
->with('songs', $songs);
but i want to get that from the model my model is 但我想从模型中得到我的模型
class Radio extends Eloquent
{
public static $timestamps = true;
}
i want my model to look like 我希望我的模特看起来像
class Radio extends Eloquent { 广播电台扩展口才{
public static function getSonginfo()
{
$songs = DB::table('songlist')
->join('historylist', 'songlist.id', '=', 'historylist.songID')
->select('songlist.*', 'historylist.*')
->orderBy('historylist.date_played', 'DESC')
->first();
}
}
now how can i pass this model into my controller and view and call the varible as i do right now $songs->title on my view 现在如何将这个模型传递到我的控制器中并像现在一样在我的视图中调用并调用变量$ songs-> title
the part i dont really get is how can i call the model function on the controller and parse it into the view something like this maybe 我没有真正得到的部分是如何在控制器上调用模型函数并将其解析为类似这样的视图
$songs = Radio::getSonginfo();
return View::make('currentsong')->with('songs', $songs);
now when i call this on my view {{ $songs->title}} i get undefined variable $songs. 现在,当我在视图{{$ songs-> title}}上调用它时,我得到了未定义的变量$ songs。
any help Thanks. 任何帮助谢谢。
sorry for my rusty english. 对不起,我的英语不好。
you need to return the variable in your model. 您需要在模型中返回变量。
public static function getSonginfo()
{
$songs = DB::table('songlist')
->join('historylist', 'songlist.id', '=', 'historylist.songID')
->select('songlist.*', 'historylist.*')
->orderBy('historylist.date_played', 'DESC')
->first();
return $songs;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.