Commit 200c5b8b authored by quentin.vrel's avatar quentin.vrel

Fin du projet Laravel

parent 5e4bf219
...@@ -39,9 +39,9 @@ class migrationOrder extends Command ...@@ -39,9 +39,9 @@ class migrationOrder extends Command
{ {
$migrations = [ $migrations = [
'2014_10_12_000000_create_users_table.php', '2014_10_12_000000_create_users_table.php',
// '2014_10_12_100000_create_password_resets_table.php', '2014_10_12_100000_create_password_resets_table.php',
// '2014_10_12_200000_add_two_factor_columns_to_users_table.php', // '2014_10_12_200000_add_two_factor_columns_to_users_table.php',
// '2019_08_19_000000_create_failed_jobs_table.php', '2019_08_19_000000_create_failed_jobs_table.php',
// '2019_12_14_000001_create_personal_access_tokens_table.php', // '2019_12_14_000001_create_personal_access_tokens_table.php',
// '2020_11_12_102755_create_sessions_table.php', // '2020_11_12_102755_create_sessions_table.php',
'2020_11_24_144826_create_category_table.php', '2020_11_24_144826_create_category_table.php',
......
...@@ -6,9 +6,10 @@ use Illuminate\Database\Eloquent\Model; ...@@ -6,9 +6,10 @@ use Illuminate\Database\Eloquent\Model;
class Game extends Model class Game extends Model
{ {
protected $connection = 'mysql'; protected $connection = 'mysql';
protected $table = 'game'; protected $table = 'game';
protected $primaryKey = 'gamer_id'; protected $primaryKey = 'id_game';
public $incrementing = true; public $incrementing = true;
public $timestamps = false; public $timestamps = false;
......
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('home');
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class MonControleur extends Controller
{
public function index() {
return view('MaVue');
}
}
...@@ -4,16 +4,44 @@ namespace App\Http\Controllers; ...@@ -4,16 +4,44 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Game; use App\Game;
use App\Tournament;
class TournamentController extends Controller class TournamentController extends Controller
{ {
public function index() { public function index($args = []) {
$games = Game::all(); $games = Game::select('titre', 'id_game')->get();
$args['games']=$games;
return view('create-tournament', ['games' => $games]); return view('create-tournament', $args);
} }
public function createTournament(){ public function createTournament(Request $request){
$tournament = new Tournament();
$tournament->description=$request->input('description');
$year= $request->input('year-begin');
$month= $request->input('month-begin');
$day= $request->input('day-begin');
$tournament->tournament_date=$year . '-' . $month . '-' . $day;
$tournament->id_game=$request->input('select-game');
$tournament->created_at=date('Y-m-d');
try {
$tournament->save();
} catch (Exception $e) {
return $this->index(['post'=>false]);
}
return $this->index(['post'=>true]);
}
public function displayTournaments(){
$tournaments=Tournament::select('description','tournament_date','id_game')->get();
$games = Game::select('id_game','titre')->get();
$gamesTitles = [];
foreach ($games as $game) {
$gamesTitles[$game->id_game]=$game->titre;
}
foreach ($tournaments as $tournament) {
$tournament->titre=$gamesTitles[$tournament->id_game];
}
return view('home', ['tournaments'=>$tournaments]);
} }
} }
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Tournament extends Model
{
protected $connection = 'mysql';
protected $table = 'tournament';
protected $primaryKey = 'id_tournament';
public $incrementing = true;
public $timestamps = false;
}
This diff is collapsed.
...@@ -7,6 +7,10 @@ use Faker\Generator as Faker; ...@@ -7,6 +7,10 @@ use Faker\Generator as Faker;
$factory->define(Game::class, function (Faker $faker) { $factory->define(Game::class, function (Faker $faker) {
return [ return [
// 'titre' => $faker->name,
'version' => $faker->unique()->randomDigit,
'created_at' => now(),
'updated_at' => now(),
'id_category' => 0
]; ];
}); });
<?php <?php
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use App\Game;
class GameTableSeeder extends Seeder class GameTableSeeder extends Seeder
{ {
...@@ -9,11 +10,16 @@ class GameTableSeeder extends Seeder ...@@ -9,11 +10,16 @@ class GameTableSeeder extends Seeder
* *
* @return void * @return void
*/ */
/*
public function run() public function run()
{ {
DB::table('game')->insert([ DB::table('game')->insert([
'created_at' => date("Y-m-d H:i:s"), 'created_at' => date("Y-m-d H:i:s"),
'updated_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s"),
]); ]);
}*/
public function run()
{
factory(Game::class, 10)->create();
} }
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div class="container"> <div class="container">
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-md-8"> <div class="col-md-8">
<div class="card"> <div class="card text-white bg-dark">
<div class="card-header">{{ __('Login') }}</div> <div class="card-header">{{ __('Login') }}</div>
<div class="card-body"> <div class="card-body">
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div class="container"> <div class="container">
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-md-8"> <div class="col-md-8">
<div class="card"> <div class="card text-white bg-dark">
<div class="card-header">{{ __('Register') }}</div> <div class="card-header">{{ __('Register') }}</div>
<div class="card-body"> <div class="card-body">
......
@extends('layouts.app') @extends('layouts.app')
@section('content') @section('content')
@auth
<div class="container"> <div class="container">
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-md-8"> <div class="col-md-8">
@if (isset($post)) <div class="card text-white bg-dark">
@if($post) @if (isset($post))
<div class="alert alert-success" role="alert"> @if($post)
Le tournoi a été créé. <div class="alert alert-success" role="alert">
</div> Le tournoi a été créé.
$else </div>
<div class="alert alert-danger" role="alert"> @else
Un erreur est intervenue, merci de réessayer. <div class="alert alert-danger" role="alert">
</div> Un erreur est intervenue, merci de réessayer.
@endif </div>
@endif @endif
@endif
<div class="card-header">Créer un tournoi</div> <div class="card-header">Créer un tournoi</div>
<div class="card-body"> <div class="card-body">
<form method="POST" action="/form"> <form method="POST" action="{{ route('createTournament') }}">
@csrf @csrf
<div class="form-group row"> <div class="form-group row">
<label for="select-game" class="col-md-4 col-form-label text-md-right">Choisissez un jeu</label> <label for="description" class="col-md-4 col-form-label text-md-right">Nom du tournoi</label>
<div class="col-md-6">
<select name="select-game" id="select-game" class="custom-select" required autofocus>
@foreach ($games as $game)
<option value="{{ $game->id_game }}">{{ $game->id_game }}</option>
@endforeach
</select>
</div>
</div>
<div class="form-group row">
<label for="tournament-name" class="col-md-4 col-form-label text-md-right">Nom du tournoi</label>
<div class="col-md-6"> <div class="col-md-6">
<input name="tournament-name" id="tournament-name" type="text" class="form-control" required> <input name="description" id="description" type="text" class="form-control" required autofocus>
</div> </div>
<div class="invalid-feedback"> <div class="invalid-feedback">
Veuillez saisir un nom. Veuillez saisir un nom.
...@@ -41,50 +33,35 @@ ...@@ -41,50 +33,35 @@
</div> </div>
<div class="form-group row"> <div class="form-group row">
<label for="date-begin" class="col-md-4 col-form-label text-md-right">Date du début du tournoi</label> <label for="select-game" class="col-md-4 col-form-label text-md-right">Choisissez un jeu</label>
<div class="col-md-6 row pr-0" name="date-begin" id="date-begin"> <div class="col-md-6">
<div class="col-md-3"> <select name="select-game" id="select-game" class="custom-select" required>
<select name="day-begin" id="day-begin" class="custom-select" required autofocus> @foreach ($games as $game)
@for ($i = 1; $i < 32; $i++) <option value="{{ $game->id_game }}">{{ $game->titre }}</option>
<option value="{{ $i }}">{{ $i }}</option> @endforeach
@endfor </select>
</select>
</div>
<div class="col-md-5">
<select name="month-begin" id="month-begin" class="custom-select" required autofocus>
@for ($i = 1; $i < 13; $i++)
<option value="{{ $i }}">{{ date('F', mktime(0,0,0,$i) ) }}</option>
@endfor
</select>
</div>
<div class="col-md-4">
<select name="day-begin" id="day-begin" class="custom-select" required autofocus>
@for ($i = date('Y'); $i < date('Y') + 20; $i++)
<option value="{{ $i }}">{{ $i }}</option>
@endfor
</select>
</div>
</div> </div>
</div> </div>
<div class="form-group row"> <div class="form-group row">
<label for="date-end" class="col-md-4 col-form-label text-md-right">Date du fin du tournoi</label> <label for="date-begin" class="col-md-4 col-form-label text-md-right">Date du début du tournoi</label>
<div class="col-md-6 row pr-0" name="date-end" id="date-end"> <div class="col-md-6 row pr-0" name="date-begin" id="date-begin">
<div class="col-md-3"> <div class="col-md-3">
<select name="day-end" id="day-end" class="custom-select" required autofocus> <select name="day-begin" id="day-begin" class="custom-select" required autofocus>
@for ($i = 1; $i < 32; $i++) @for ($i = 1; $i < 32; $i++)
<option value="{{ $i }}">{{ $i }}</option> <option value="{{ $i }}">{{ $i }}</option>
@endfor @endfor
</select> </select>
</div> </div>
<div class="col-md-5"> <div class="col-md-5">
<select name="month-end" id="month-end" class="custom-select" required autofocus> <select name="month-begin" id="month-begin" class="custom-select" required>
@for ($i = 1; $i < 13; $i++) @for ($i = 1; $i < 13; $i++)
<option value="{{ $i }}">{{ date('F', mktime(0,0,0,$i) ) }}</option> <option value="{{ $i }}">{{ date('F', mktime(0,0,0,$i) ) }}</option>
@endfor @endfor
</select> </select>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<select name="day-end" id="day-end" class="custom-select" required autofocus> <select name="year-begin" id="year-begin" class="custom-select" required>
@for ($i = date('Y'); $i < date('Y') + 20; $i++) @for ($i = date('Y'); $i < date('Y') + 20; $i++)
<option value="{{ $i }}">{{ $i }}</option> <option value="{{ $i }}">{{ $i }}</option>
@endfor @endfor
...@@ -92,9 +69,10 @@ ...@@ -92,9 +69,10 @@
</div> </div>
</div> </div>
</div> </div>
<div class="form-group row"> <div class="form-group row">
<button class="btn btn-primary mx-auto" type="submit">Submit form</button> <button class="btn btn-primary mx-auto" type="submit">Enregistrer le tournoi</button>
</div> </div>
</form> </form>
...@@ -104,4 +82,16 @@ ...@@ -104,4 +82,16 @@
</div> </div>
</div> </div>
</div> </div>
@else
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="alert alert-danger" role="alert">
Vous devez être connecté pour accéder à cette page.
</div>
</div>
</div>
</div>
@endauth
@endsection @endsection
...@@ -4,18 +4,30 @@ ...@@ -4,18 +4,30 @@
<div class="container"> <div class="container">
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-md-8"> <div class="col-md-8">
<div class="card">
@if (isset($tournaments) && !empty($tournaments))
<div class="card-body"> <table class="table table-dark">
@if (session('status')) <thead>
<div class="alert alert-success" role="alert"> <tr>
{{ session('status') }} <th scope="col">#</th>
</div> <th scope="col">Nom</th>
<th scope="col">Jeu</th>
<th scope="col">Date</th>
</tr>
</thead>
<tbody>
@foreach($tournaments as $tournament)
<tr>
<th scope="row">{{$tournament->id_tournament}}</th>
<td>{{$tournament->description}}</td>
<td>{{$tournament->titre}}</td>
<td>{{$tournament->tournament_date}}</td>
</tr>
@endforeach
</tbody>
</table>
@endif @endif
Bienvenue sur ma page d'accueil.
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
<!-- Styles --> <!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet"> <link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head> </head>
<body> <body class="bg-secondary">
<div id="app"> <div id="app">
<nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm"> <nav class="navbar navbar-expand-md navbar-dark bg-dark shadow-sm">
<div class="container"> <div class="container">
<a class="navbar-brand" href="{{ url('/') }}"> <a class="navbar-brand" href="{{ url('/') }}">
{{ config('app.name', 'Laravel') }} {{ config('app.name', 'Laravel') }}
...@@ -32,12 +32,13 @@ ...@@ -32,12 +32,13 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent"> <div class="collapse navbar-collapse" id="navbarSupportedContent">
<!-- Left Side Of Navbar --> <!-- Left Side Of Navbar -->
@auth
<ul class="navbar-nav mr-auto"> <ul class="navbar-nav mr-auto">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{{ url('/form') }}">{{ __('Créer un tournoi') }}</a> <a class="nav-link" href="{{ url('/form') }}">{{ __('Créer un tournoi') }}</a>
</li> </li>
</ul> </ul>
@endauth
<!-- Right Side Of Navbar --> <!-- Right Side Of Navbar -->
<ul class="navbar-nav ml-auto"> <ul class="navbar-nav ml-auto">
<!-- Authentication Links --> <!-- Authentication Links -->
......
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@200;600&display=swap" rel="stylesheet">
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
<header>
<h1>@yield('Title')</h1>
</header>
<div id="page">
<article>
<p>@yield('content')</p>
</article>
</div>
<footer>
<p>Powered by <a href="https://laravel.com/">Laravel</a></p>
</footer>
</body>
</html>
@extends('layouts.app')
@section('Title', 'Page Title')
@section('content')
Du texte test.
@stop
\ No newline at end of file
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@200;600&display=swap" rel="stylesheet">
<!-- Styles -->
<style>
html, body {
background-color: #fff;
color: #636b6f;
font-family: 'Nunito', sans-serif;
font-weight: 200;
height: 100vh;
margin: 0;
}
.full-height {
height: 100vh;
}
.flex-center {
align-items: center;
display: flex;
justify-content: center;
}
.position-ref {
position: relative;
}
.top-right {
position: absolute;
right: 10px;
top: 18px;
}
.content {
text-align: center;
}
.title {
font-size: 84px;
}
.links > a {
color: #636b6f;
padding: 0 25px;
font-size: 13px;
font-weight: 600;
letter-spacing: .1rem;
text-decoration: none;
text-transform: uppercase;
}
.m-b-md {
margin-bottom: 30px;
}
</style>
</head>
<body>
<div class="flex-center position-ref full-height">
@if (Route::has('login'))
<div class="top-right links">
@auth
<a href="{{ url('/home') }}">Home</a>
@else
<a href="{{ route('login') }}">Login</a>
@if (Route::has('register'))
<a href="{{ route('register') }}">Register</a>
@endif
@endauth
</div>
@endif
<div class="content">
<div class="title m-b-md">
Laravel
</div>
<div class="links">
<a href="https://laravel.com/docs">Docs</a>
<a href="https://laracasts.com">Laracasts</a>
<a href="https://laravel-news.com">News</a>
<a href="https://blog.laravel.com">Blog</a>
<a href="https://nova.laravel.com">Nova</a>
<a href="https://forge.laravel.com">Forge</a>
<a href="https://vapor.laravel.com">Vapor</a>
<a href="https://github.com/laravel/laravel">GitHub</a>
</div>
</div>
</div>
</body>
</html>
...@@ -13,22 +13,16 @@ use Illuminate\Support\Facades\Route; ...@@ -13,22 +13,16 @@ use Illuminate\Support\Facades\Route;
| |
*/ */
Route::get('/', function () { Route::get('/', 'TournamentController@displayTournaments');
return view('home');
}); Route::get('/home', function () {
/* return redirect('/');
Route::get('/vue2', 'MonControleur@index');
Route::get('/{firstname}/{name}', function ($firstname, $name) {
return "Koukou $firstname $name";
}); });
*/
Auth::routes(); Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/form', 'TournamentController@index'); Route::get('/form', 'TournamentController@index');
Route::post('/form', 'TournamentController@createTournament')->name('createTournament');
//Routes de test
Route::get('/formtest', 'TournamentController@createTournament');
Markdown is supported
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