diff --git a/GamePedia/src/controleurs/ControleurScript.php b/GamePedia/src/controleurs/ControleurScript.php index 71e6d151348adc955fd2b2ccae678acce27c819f..748e662dc3c0f30ea2899a0d5a2a1993600799b7 100644 --- a/GamePedia/src/controleurs/ControleurScript.php +++ b/GamePedia/src/controleurs/ControleurScript.php @@ -2,6 +2,8 @@ namespace gp\controleurs; +use gp\modeles\Comment; +use gp\modeles\User; use Illuminate\Database\Capsule\Manager as DB; use gp\modeles\Game_rating; use gp\modeles\Genre; @@ -376,11 +378,11 @@ class ControleurScript //random game $game = Game::all()->random(1)->first(); //fake data - $title = $user->email; + $title = $faker->text(50); $content = $faker->text(200); $date = $faker->date('Y-m-d', '2015-02-01'); //insert comment - Comment::create($title, $content, $date); + Comment::create($game->id, $user->email, $title, $content, $date); } } } diff --git a/GamePedia/src/modeles/Comment.php b/GamePedia/src/modeles/Comment.php new file mode 100644 index 0000000000000000000000000000000000000000..8e50f9261be7d69b778982cf7023e69e05b952bc --- /dev/null +++ b/GamePedia/src/modeles/Comment.php @@ -0,0 +1,24 @@ +<?php +namespace gp\modeles; +use Illuminate\Database\Eloquent\Builder; +class Comment extends \Illuminate\Database\Eloquent\Model +{ + protected $table = 'comment'; + protected $primaryKey = 'id'; + public $timestamps = false ; + + public static function create($id_game, $email, $title, $content, $createdAt){ + $obj = new Comment(); + $obj->email = $email; + $obj->title = $title; + $obj->content = $content; + $obj->createdAt = $createdAt; + $obj->save(); + Game::where('id', '=', $id_game)->first()->comments()->attach([$id_game]); + return $obj; + } + + function games(){ + return $this->BelongsToMany('gp\modeles\Game', 'game2comment','comment_id'); + } +} \ No newline at end of file diff --git a/GamePedia/src/modeles/Game.php b/GamePedia/src/modeles/Game.php index 11f8781d33e2cc9039eae521176a9f74aca4ee02..ddc463d433506f971fb705e75be5f3e2f2267aeb 100644 --- a/GamePedia/src/modeles/Game.php +++ b/GamePedia/src/modeles/Game.php @@ -31,4 +31,7 @@ class Game extends \Illuminate\Database\Eloquent\Model public function similarGames(){ return $this->belongsToMany('gp\modeles\Games', 'similar_games','game1'); } + public function comments(){ + return $this->belongsToMany('gp\modeles\comment', 'game2comment','game_id'); + } } \ No newline at end of file diff --git a/GamePedia/src/modeles/User.php b/GamePedia/src/modeles/User.php new file mode 100644 index 0000000000000000000000000000000000000000..7410dee196094834eaf483d8fec1f80694c0eb8c --- /dev/null +++ b/GamePedia/src/modeles/User.php @@ -0,0 +1,25 @@ +<?php +namespace gp\modeles; +use Illuminate\Database\Eloquent\Builder; +class User extends \Illuminate\Database\Eloquent\Model +{ + protected $table = 'user'; + protected $primaryKey = 'id'; + public $timestamps = false ; + + public static function create($fname, $name, $email, $adress, $numtel, $date){ + $obj = new User(); + $obj->name = $name; + $obj->fname = $fname; + $obj->email = $email; + $obj->adress = $adress; + $obj->numtel = $numtel; + $obj->date = $date; + $obj->save(); + return $obj; + } + + function games(){ + return $this->BelongsToMany('gp\modeles\Game', 'game2genre','genre_id'); + } +} \ No newline at end of file