From f10419004eeb09a2d79ed31d52d7555c24f52907 Mon Sep 17 00:00:00 2001 From: structix Date: Sat, 2 Jun 2018 01:08:41 +0200 Subject: [PATCH] create tipp --- .../app/Http/Controllers/PagesController.php | 24 ++++++++++ .../app/Http/Requests/TippCreateRequest.php | 33 ++++++++++++++ tippspiel/app/Tipp.php | 38 ++++++++++++++++ tippspiel/composer.json | 3 +- tippspiel/config/app.php | 4 ++ tippspiel/resources/views/dashboard.blade.php | 7 ++- .../resources/views/tipp/create.blade.php | 45 +++++++++++++++++++ tippspiel/routes/web.php | 2 + 8 files changed, 154 insertions(+), 2 deletions(-) create mode 100755 tippspiel/app/Http/Requests/TippCreateRequest.php create mode 100755 tippspiel/app/Tipp.php create mode 100755 tippspiel/resources/views/tipp/create.blade.php diff --git a/tippspiel/app/Http/Controllers/PagesController.php b/tippspiel/app/Http/Controllers/PagesController.php index cf71b01..dfa86fe 100644 --- a/tippspiel/app/Http/Controllers/PagesController.php +++ b/tippspiel/app/Http/Controllers/PagesController.php @@ -5,6 +5,8 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Team; use App\Match; +use App\Tipp; +use App\Http\Requests\TippCreateRequest; class PagesController extends Controller { @@ -17,4 +19,26 @@ class PagesController extends Controller 'matches' => $matches, ]); } + + function createTipp($matchid) { + $teams = Team::all(); + $matches = Match::findOrFail($matchid); + + $teama = $teams->find($matches->teama)->name; + $teamb = $teams->find($matches->teamb)->name; + + return view('dashboard')->with([ + 'teama' => $teama, + 'teamb' => $teamb, + 'matchid' => $matchid, + ]); + } + + function storeTipp(TippCreateRequest $request) { + $tipp = new Tipp($request->all()); + $tipp->user = Auth::user()->id; + $tipp->save(); + + return redirect('/dashboard'); + } } diff --git a/tippspiel/app/Http/Requests/TippCreateRequest.php b/tippspiel/app/Http/Requests/TippCreateRequest.php new file mode 100755 index 0000000..d603f88 --- /dev/null +++ b/tippspiel/app/Http/Requests/TippCreateRequest.php @@ -0,0 +1,33 @@ + 'required|min:0|max:99', + 'resultb' => 'required|min:0|max:99', + 'matchid' => 'required', + ]; + } +} diff --git a/tippspiel/app/Tipp.php b/tippspiel/app/Tipp.php new file mode 100755 index 0000000..1baf692 --- /dev/null +++ b/tippspiel/app/Tipp.php @@ -0,0 +1,38 @@ + Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, + + 'Form' => Collective\Html\FormFacade::class, + 'Html' => Collective\Html\HtmlFacade::class, ], ]; diff --git a/tippspiel/resources/views/dashboard.blade.php b/tippspiel/resources/views/dashboard.blade.php index e4ac335..2af7169 100644 --- a/tippspiel/resources/views/dashboard.blade.php +++ b/tippspiel/resources/views/dashboard.blade.php @@ -40,7 +40,12 @@ {!! $teams->find($match->teamb)->name !!} {!! $match->resulta . ':' . $match->resultb !!} - - - + + + {!! Form::model($match, ['method' => 'GET', 'action' => ['PagesController@createTipp', $match->id], 'style' => 'display:inline-block;']) !!} + + {!! Form::close() !!} + @endforeach diff --git a/tippspiel/resources/views/tipp/create.blade.php b/tippspiel/resources/views/tipp/create.blade.php new file mode 100755 index 0000000..3e5e348 --- /dev/null +++ b/tippspiel/resources/views/tipp/create.blade.php @@ -0,0 +1,45 @@ +@extends('layouts.app') + + +@section('content') +

TippSpiel {!! $teama . ' vs. ' . $teamb !!}

+ + @if ($errors->any()) +
+ +
+ @endif + + + {!! Form::open(['action' => 'PagesController@storeTipp']) !!} + + +
+ {!! Form::label('matchid', 'Match ID') !!} + {!! Form::text('matchid', $matchid, ['class' => 'form-control']) !!} +
+ + +
+ {!! Form::label('resulta', 'Ergebnis Team ' . $teama) !!} + {!! Form::text('resulta', '', ['class' => 'form-control']) !!} +
+ + +
+ {!! Form::label('resultb', 'Ergebnis Team ' . $teamb) !!} + {!! Form::text('resultb', '', ['class' => 'form-control']) !!} +
+ + +
+ {!! Form::submit('Tipp absenden', ['class' => 'btn btn-primary']) !!} +
+ + {!! Form::close() !!} + +@endsection diff --git a/tippspiel/routes/web.php b/tippspiel/routes/web.php index e79ca2b..cacedac 100644 --- a/tippspiel/routes/web.php +++ b/tippspiel/routes/web.php @@ -18,3 +18,5 @@ Route::get('/', function () { Auth::routes(); Route::get('/dashboard', 'PagesController@dashboard'); +Route::get('/tipp/create/{matchid}', 'PagesController@createTipp'); +Route::post('/tipp/store', 'PagesController@storeTipp');