Skip to content
Snippets Groups Projects
Commit 11ffccbc authored by SASSU Thomas's avatar SASSU Thomas
Browse files

association game

parent 7dc38823
No related branches found
No related tags found
No related merge requests found
<?php
require_once dirname (__DIR__) . '/vendor/autoload.php';
session_start();
use \Slim\Slim as Slim;
use Illuminate\Database\Capsule\Manager as DB;
use \gp\controleurs\ControleurPrincipal as ControleurPrincipal;
use \gp\controleurs\ControleurScript as ControleurScript;
$db = new DB();
$db->addConnection(parse_ini_file('../conf/conf.ini'));
$db->setAsGlobal();
$db->bootEloquent();
$c = new ControleurScript();
$c->td2();
......@@ -8,6 +8,7 @@ use gp\modeles\Platform;
use gp\modeles\Game;
use gp\modeles\Company;
use gp\modeles\Deck;
use gp\modeles\Character;
class ControleurScript
{
......@@ -72,4 +73,12 @@ class ControleurScript
private function platformByBase($base){
return Platform::where("install_base", ">=", "{$base}");
}
/**
* TD_2
*/
public function td2(){
echo (Game::where('id','=',1)->first()->characters()->get());
}
}
\ No newline at end of file
......@@ -6,4 +6,8 @@ class Character extends \Illuminate\Database\Eloquent\Model
protected $table = 'character';
protected $primaryKey = 'id';
public $timestamps = false ;
function games(){
return $this->BelongsToMany('gp\modeles\Game', 'game2character','character_id');
}
}
\ No newline at end of file
<?php
namespace gp\modeles;
use Illuminate\Database\Eloquent\Builder;
class Contient extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'contient';
protected $primaryKey = ['idRecette', 'idIngre'];
public $timestamps = false ;
public $incrementing = false;
public function recette() {
return $this->belongsTo('fridgie\modeles\Recette', 'idRecette');
}
public function ingredient() {
return $this->hasOne('fridgie\modeles\Ingredient', 'idIngre');
}
/**
* Set the keys for a save update query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function setKeysForSaveQuery(Builder $query)
{
$keys = $this->getKeyName();
if(!is_array($keys)){
return parent::setKeysForSaveQuery($query);
}
foreach($keys as $keyName){
$query->where($keyName, '=', $this->getKeyForSaveQuery($keyName));
}
return $query;
}
/**
* Get the primary key value for a save query.
*
* @param mixed $keyName
* @return mixed
*/
protected function getKeyForSaveQuery($keyName = null)
{
if(is_null($keyName)){
$keyName = $this->getKeyName();
}
if (isset($this->original[$keyName])) {
return $this->original[$keyName];
}
return $this->getAttribute($keyName);
}
}
\ No newline at end of file
......@@ -6,4 +6,29 @@ class Game extends \Illuminate\Database\Eloquent\Model
protected $table = 'game';
protected $primaryKey = 'id';
public $timestamps = false ;
public function characters(){
return $this->belongsToMany('gp\modeles\Character', 'game2character','game_id');
}
public function platform(){
return $this->belongsToMany('gp\modeles\Platform', 'game2platform','game_id');
}
public function theme(){
return $this->belongsToMany('gp\modeles\Theme', 'game2theme','game_id');
}
public function genre(){
return $this->belongsToMany('gp\modeles\Genre', 'game2genre','game_id');
}
public function rating(){
return $this->belongsToMany('gp\modeles\Rating', 'game2rating','game_id');
}
public function publishers(){
return $this->belongsToMany('gp\modeles\Company', 'game_publishers','game_id');
}
public function developers(){
return $this->belongsToMany('gp\modeles\Company', 'game_developers','game_id');
}
public function similarGames(){
return $this->belongsToMany('gp\modeles\Games', 'similar_games','game1');
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment