130 lines
3.4 KiB
PHP
130 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Veranstaltung;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
|
|
class VeranstaltungController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
return view('veranstaltung.index', ['veranstaltungen' => Veranstaltung::get()->sortBy('beginn')]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$v = new Veranstaltung();
|
|
$v->beginn = \Carbon\Carbon::today();
|
|
$v->gaeste = 0;
|
|
|
|
return view ('veranstaltung.create',
|
|
$v);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param \App\Veranstaltung $veranstaltung
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show(Veranstaltung $veranstaltung)
|
|
{
|
|
if ($veranstaltung->has('eintragungen')) {
|
|
$veranstaltung->eintragungen;
|
|
}
|
|
return view('veranstaltung.show', $veranstaltung);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param \App\Veranstaltung $veranstaltung
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit(Veranstaltung $veranstaltung)
|
|
{
|
|
return view('veranstaltung.edit', $veranstaltung);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \App\Veranstaltung $veranstaltung
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param \App\Veranstaltung $veranstaltung
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(Veranstaltung $veranstaltung)
|
|
{
|
|
$veranstaltung->delete();
|
|
|
|
return redirect()->route('veranstaltung.index');
|
|
}
|
|
|
|
public function enter(Request $request, Veranstaltung $veranstaltung)
|
|
{
|
|
|
|
}
|
|
}
|