Skip to content
Snippets Groups Projects
Commit 9b9cf516 authored by BARBI HUGO's avatar BARBI HUGO
Browse files

AncienTPNotéFin

parent b6abeaad
No related merge requests found
......@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Models\UserEloquent;
use App\Models\VideoGame;
class UserController extends Controller
{
......@@ -70,6 +71,13 @@ class UserController extends Controller
->with('message',$request->session()->get('message'));
}
/**
* Get the game for the user session.
*/
public function comments()
{
return $this->hasMany(VideoGame::class);
}
/**
* Signout
......
......@@ -52,6 +52,9 @@ class VideoGameController extends Controller
$game->name = $request->newgame;
$game->url = $request->newurl;
$game->description = $request->newdesc;
$user = $request->session()->get('user');
$game->user_id = $user->user_id;
try
{
......@@ -59,7 +62,7 @@ class VideoGameController extends Controller
}
catch (\Illuminate\Database\QueryException $e){
return redirect()->route('formgame')
->with('message','QueryException :'+ $e);
->with('message','QueryException :'.$e->getMessage());
}
return redirect()->route('account')->with('message','Game created ! Check in GamemList.');
......
......@@ -12,4 +12,9 @@ class UserEloquent extends Model
protected $table = 'UserEloquent';
protected $primaryKey = 'user_id';
public $timestamps = false;
public function games()
{
$this->hasMany(VideoGame::class,'user_id');
}
}
......@@ -19,7 +19,10 @@ class CreateVideoGamesTable extends Migration
$table->string('name')->unique();
$table->string('url');
$table->string('description');
$table->string('proprietaire')->nullable();
$table->string('user_id');
$table->foreign('user_id')
->references('user_id')->on('UserEloquent')
->onDelete('cascade');
});
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment