Php Laravel 4.2雄辩的检查ID
我有两张桌子 “hostgame”->游戏的托管地 “游戏”->这里有每一个游戏的主人都可以得到他们各自的信息 我们将在“hostgame”表中获得“game_id”,到目前为止,所有游戏都发布在网站上,我希望根据“hostgame”表中的“game_id”筛选这些游戏,并仅显示已托管的游戏 我该怎么做 GameController.phpPhp Laravel 4.2雄辩的检查ID,php,laravel,eloquent,Php,Laravel,Eloquent,我有两张桌子 “hostgame”->游戏的托管地 “游戏”->这里有每一个游戏的主人都可以得到他们各自的信息 我们将在“hostgame”表中获得“game_id”,到目前为止,所有游戏都发布在网站上,我希望根据“hostgame”表中的“game_id”筛选这些游戏,并仅显示已托管的游戏 我该怎么做 GameController.php public function select() { // TODO: Pls revise this. This is not the r
public function select()
{
// TODO: Pls revise this. This is not the right way to do
$weekly_dates = $this->get_days( Config::get('game.year'), 9 );
$this->params['weekly_dates'] = $weekly_dates;
$this->params['weekly_games'] = array();
foreach($weekly_dates as $date ) {
$from = date('Y-m-d 00:00:00', strtotime($date));
$to = date('Y-m-d 23:59:59', strtotime($date));
//foreach($hostgames as $hostgame){
$this->params['hostgame'] = Hostgame::all();
dd($this->params['hostgame']);
$this->params['weekly_games'][$date] = Game::whereRaw('schedule >= ? and schedule <= ?', array($from, $to) )->get();
//}
//$this->params['weekly_games'][$date] = Game::has()('schedule >= ? and schedule <= ?', array($from, $to) )->hostgames();
//$this->params['weekly_games'][$date] = Hostgame::whereHas('game', function($q) {
//$q->whereRaw('schedule >= ? and schedule <= ?', array('34365', '2435') )->get();
//});
}
公共功能选择()
{
//TODO:请修改这个。这不是正确的方法
$weekly_dates=$this->get_days(配置::get('game.year'),9);
$this->params['weekly_dates']=$weekly_dates;
$this->params['weekly_games']=array();
foreach($date作为$date的每周日){
$from=日期('Y-m-d 00:00:00',标准时间($date));
$to=日期('Y-m-D23:59:59',标准时间($date));
//foreach($hostgames作为$hostgame){
$this->params['hostgame']=hostgame::all();
dd($this->params['hostgame']);
$this->params['weekly_games'][$date]=Game::whereRaw('schedule>=?和schedule=?和schedule=?和schedule有多种方法可以实现您的目标。由于您的游戏id已经在主机列表中,请尝试以下操作:
将单个游戏的函数添加到GameController.php公共函数getSingleGame($id){//logic here}
接下来,将以下(控制器)路由添加到routes.php以在路由、控制器和模板之间建立链接:route::get('game/draft/{id}',['as'=>'show_single_game','uses'=>'GameController@getSingleGame“]);
您现在可以通过特定名称访问路线(show_single_game)
现在,您可以这样编写URL路由:{{link\u to\u route('show\u single\u game',$game->home\u name.”Vs.“$game->away\u name,array($game->id))}
Laravel将为您创建链接,因此不必担心URL,这现在是由路由设置的
GameController getSingleGame的逻辑:
public function getSingleGame($id) {
// find the game by id
$game = Game::findOrFail($id);
// assuming your template is located in views/games/show.blade.php
return View::make('games/show')
->with('game', $game);
}
我建议你读这本书,为laravel 4.X->和第5版,看看这个很棒的系列:你使用雄辩的模型吗?->是的,我用了。但我想问的是,如果有人知道我要做什么,我会不顾一切地提出一个问题。但是如果它能用雄辩的模型来做,那就是我问的原因。好的,如果我理解的话正确吗?你有两个表,一个用于托管的游戏,另一个用于游戏本身,对吗?那么,每个主机都属于一个游戏?是的,它们分别属于各自的游戏,所以“hostgame”表是创建游戏的地方,“games”表是获取信息的地方,所以具体来说,我试图找到“hostgame.game\u id”->“game.id”,如果id相同,那么它将提取“schedule”数据,“home\u team”和“away\u team”并在前面显示游戏信息。我明白了。因此,请将您的game.php和hostgame.php模型添加到gist()中或者在你的帖子中,我会帮助你建立正确的关系谢谢你尽可能清晰的解释…谢谢你,我还没有测试过这个,但它应该能工作(希望如此),所以只要问一下,我就会编辑帖子!
public function getSingleGame($id) {
// find the game by id
$game = Game::findOrFail($id);
// assuming your template is located in views/games/show.blade.php
return View::make('games/show')
->with('game', $game);
}