diff --git a/app/Http/Controllers/VeranstaltungController.php b/app/Http/Controllers/VeranstaltungController.php index 8ac7bd11..68feff6c 100644 --- a/app/Http/Controllers/VeranstaltungController.php +++ b/app/Http/Controllers/VeranstaltungController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use App\Veranstaltung; use Illuminate\Http\Request; +use Illuminate\Http\Response; class VeranstaltungController extends Controller { @@ -24,8 +25,11 @@ class VeranstaltungController extends Controller */ public function create() { + $v = new Veranstaltung(); + $v->beginn = \Carbon\Carbon::today(); + return view ('veranstaltung.create', ['model' => - new Veranstaltung()]); + $v]); } /** @@ -36,7 +40,21 @@ class VeranstaltungController extends Controller */ public function store(Request $request) { - // + $input = $request->input(); + $v = new Veranstaltung(); + $v->name = $input['name']; + $v->gaeste = (int)$input['gaeste']; + $v->beginn = new \Carbon\Carbon($input['beginn']); + if ($input['ende']) { + $v->ende = new \Carbon\Carbon($input['ende']); + } + $v->hinweise = $input['hinweise'] ?: ""; + + if ($v->save()) { + return redirect()->route('veranstaltung.show', [$v] ); + } + + return response()->json($v); } /** @@ -47,7 +65,8 @@ class VeranstaltungController extends Controller */ public function show(Veranstaltung $veranstaltung) { - // + + return view('veranstaltung.show', $veranstaltung); } /** @@ -58,7 +77,7 @@ class VeranstaltungController extends Controller */ public function edit(Veranstaltung $veranstaltung) { - // + return view('veranstaltung.edit', $veranstaltung); } /** @@ -70,7 +89,21 @@ class VeranstaltungController extends Controller */ public function update(Request $request, Veranstaltung $veranstaltung) { - // + + if ($request->isMethod('put')) { + $i = $request->input(); + $veranstaltung->gaeste = $i['gaeste']; + $veranstaltung->name = $i['name']; + $veranstaltung->hinweise = $i['hinweise']; + $veranstaltung->beginn = new \Carbon\Carbon($i['beginn']); + $veranstaltung->ende = $i['ende'] ? new \Carbon\Carbon($i['ende']) : null; + if($veranstaltung->save()){ + return redirect()->route('veranstaltung.show', [$veranstaltung]); + } + + + } + return response()->json($veranstaltung); } /** @@ -81,6 +114,13 @@ class VeranstaltungController extends Controller */ public function destroy(Veranstaltung $veranstaltung) { - // + $veranstaltung->delete(); + + return redirect()->route('veranstaltung.index'); + } + + public function enter(Request $request, Veranstaltung $veranstaltung) + { + } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 70219816..8883c9c1 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -4,6 +4,7 @@ namespace App\Providers; use Illuminate\Support\Facades\Schema; use Illuminate\Support\ServiceProvider; +use Carbon\Carbon; class AppServiceProvider extends ServiceProvider { @@ -15,6 +16,9 @@ class AppServiceProvider extends ServiceProvider public function boot() { Schema::defaultStringLength(191); + date_default_timezone_set("Europe/Berlin"); + setlocale(LC_TIME, "German"); + Carbon::setLocale('de'); } /** diff --git a/app/Veranstaltung.php b/app/Veranstaltung.php index 8791e0b7..6d4da0b7 100644 --- a/app/Veranstaltung.php +++ b/app/Veranstaltung.php @@ -7,5 +7,8 @@ use Illuminate\Database\Eloquent\Model; class Veranstaltung extends Model { protected $table = "veranstaltungen"; - // + + protected $fillable = ['name','beginn','ende','geaste','hinweise']; + + protected $dates = ['beginn', 'ende']; } diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index cdd07e81..52cdb87f 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -10,10 +10,11 @@
@section('navbar') @show diff --git a/resources/views/veranstaltung/create.blade.php b/resources/views/veranstaltung/create.blade.php index 82f875e3..d9013422 100644 --- a/resources/views/veranstaltung/create.blade.php +++ b/resources/views/veranstaltung/create.blade.php @@ -2,12 +2,39 @@ @section('title', 'Neue Veranstaltung') @section('content') -