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

Partie 1 models test

parent c90e81d5
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
}
}
......
<?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
......@@ -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
<?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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment