Php 如何在Laravel模型类中编写此语句
如何在Laravel模型类中编写这样的语句Php 如何在Laravel模型类中编写此语句,php,laravel,codeigniter-2,Php,Laravel,Codeigniter 2,如何在Laravel模型类中编写这样的语句 SELECT * from video where view=(select max(view) from video) $query = DB::table('video')->select('*'); $alldetails = $query->addSelect('max(view)')->get(); 我打算选择具有最大视图量的视频的所有属性 我的型号 class Video extends Eloquent imple
SELECT * from video where view=(select max(view) from video)
$query = DB::table('video')->select('*');
$alldetails = $query->addSelect('max(view)')->get();
我打算选择具有最大视图量的视频的所有属性
我的型号
class Video extends Eloquent implements UserInterface, RemindableInterface {
protected $table = 'video';
public static function feature(){
$query = DB::table('video')->select('*');
$alldetails = $query->addSelect('max(view)')->get();
return $alldetails;
}
}
我的控制器
class HomeController extends BaseController {
public function home(){
$feature=View::feature();
return View::make('frontend/index')
->with("title","Kromatik Multimedia")
->with('feature'.$feature);
}
}
我的观点
@foreach($feature as $fet)
$fet->title;
@endforeach
创建一个如下所示的模型:
class Video extends Eloquent {
// Laravel expects the table name "videos"
// for Video model so need to specify here
// because you didn't follow that convention
protected $table = 'video';
}
class HomeController extends BaseController {
public function home()
{
// Get the Video model with maximum views; assumed that,
// view field contains numeric number, i.e. 2 (two views)
$featured = Video::orderBy('view', 'desc')->first();
// Load the "index.blade.php" view from "views/frontend" folder
return View::make('frontend.index')->with('video', $featured);
}
}
从控制器中调用如下内容:
class Video extends Eloquent {
// Laravel expects the table name "videos"
// for Video model so need to specify here
// because you didn't follow that convention
protected $table = 'video';
}
class HomeController extends BaseController {
public function home()
{
// Get the Video model with maximum views; assumed that,
// view field contains numeric number, i.e. 2 (two views)
$featured = Video::orderBy('view', 'desc')->first();
// Load the "index.blade.php" view from "views/frontend" folder
return View::make('frontend.index')->with('video', $featured);
}
}
在视图中(无需循环,因为只传递了一个模型):
我可以帮你,但是你能解释一下你的查询想要做什么吗?你是想让视频拥有最多的浏览量吗?是的,这正是我想做的。沃尔夫击败了我。他的回答可以做到这一点。