create tipp
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
33
tippspiel/app/Http/Requests/TippCreateRequest.php
Executable file
33
tippspiel/app/Http/Requests/TippCreateRequest.php
Executable file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Auth;
|
||||
|
||||
class TippCreateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return (Auth::check()) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'resulta' => 'required|min:0|max:99',
|
||||
'resultb' => 'required|min:0|max:99',
|
||||
'matchid' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
38
tippspiel/app/Tipp.php
Executable file
38
tippspiel/app/Tipp.php
Executable file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Tipp extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
/**
|
||||
* The database table uses by the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'tipp';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'user',
|
||||
'matchid',
|
||||
'resulta',
|
||||
'resultb',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
//
|
||||
];
|
||||
}
|
@@ -8,7 +8,8 @@
|
||||
"php": "^7.1.3",
|
||||
"fideloper/proxy": "^4.0",
|
||||
"laravel/framework": "5.6.*",
|
||||
"laravel/tinker": "^1.0"
|
||||
"laravel/tinker": "^1.0",
|
||||
"laravelcollective/html": "^5.4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"filp/whoops": "^2.0",
|
||||
|
@@ -151,6 +151,7 @@ return [
|
||||
* Package Service Providers...
|
||||
*/
|
||||
|
||||
Collective\Html\HtmlServiceProvider::class,
|
||||
/*
|
||||
* Application Service Providers...
|
||||
*/
|
||||
@@ -209,6 +210,9 @@ return [
|
||||
'Validator' => Illuminate\Support\Facades\Validator::class,
|
||||
'View' => Illuminate\Support\Facades\View::class,
|
||||
|
||||
|
||||
'Form' => Collective\Html\FormFacade::class,
|
||||
'Html' => Collective\Html\HtmlFacade::class,
|
||||
],
|
||||
|
||||
];
|
||||
|
@@ -40,7 +40,12 @@
|
||||
<td>{!! $teams->find($match->teamb)->name !!}</td>
|
||||
<td>{!! $match->resulta . ':' . $match->resultb !!}</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>
|
||||
<!-- Edit -->
|
||||
{!! Form::model($match, ['method' => 'GET', 'action' => ['PagesController@createTipp', $match->id], 'style' => 'display:inline-block;']) !!}
|
||||
<button class="btn btn-primary" type="submit"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></button>
|
||||
{!! Form::close() !!}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@endforeach
|
||||
|
45
tippspiel/resources/views/tipp/create.blade.php
Executable file
45
tippspiel/resources/views/tipp/create.blade.php
Executable file
@@ -0,0 +1,45 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
|
||||
@section('content')
|
||||
<h1>Tipp<small>Spiel {!! $teama . ' vs. ' . $teamb !!}</small></h1>
|
||||
|
||||
@if ($errors->any())
|
||||
<div class="alert alert-danger">
|
||||
<ul>
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
|
||||
{!! Form::open(['action' => 'PagesController@storeTipp']) !!}
|
||||
|
||||
<!-- Team A -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('matchid', 'Match ID') !!}
|
||||
{!! Form::text('matchid', $matchid, ['class' => 'form-control']) !!}
|
||||
</div>
|
||||
|
||||
<!-- Team A -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('resulta', 'Ergebnis Team ' . $teama) !!}
|
||||
{!! Form::text('resulta', '', ['class' => 'form-control']) !!}
|
||||
</div>
|
||||
|
||||
<!-- Team A -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('resultb', 'Ergebnis Team ' . $teamb) !!}
|
||||
{!! Form::text('resultb', '', ['class' => 'form-control']) !!}
|
||||
</div>
|
||||
|
||||
<!-- Send Button -->
|
||||
<div class="form-group">
|
||||
{!! Form::submit('Tipp absenden', ['class' => 'btn btn-primary']) !!}
|
||||
</div>
|
||||
|
||||
{!! Form::close() !!}
|
||||
|
||||
@endsection
|
@@ -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');
|
||||
|
Reference in New Issue
Block a user