Commit 068ffdc4 authored by dm141569's avatar dm141569 Committed by BZ

Finish API for GET requests, with workarounds

parent 7a6a47ab
......@@ -4,8 +4,15 @@ use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Response;
use App\Event;
use App\Participant;
use DB;
/**
* Bug? Es wird die Version 5 verwendet, ist noch in Entwicklung
* Die Querys, in denen gleich die Teilnehmer mit abgerufen werden, funktionieren.
* Es ist aber nicht möglich diese als JSON zurück zu geben.
* Deshalb Workaround: Eigene Funktion = +1 Requests
*/
class HomeController extends Controller {
/**
......@@ -40,20 +47,27 @@ class HomeController extends Controller {
*/
public function show($id)
{
// $event = DB::table('events')->find($id);
// $participants = DB::table('participants')->where('event_id', $id)->get();
// funkt nicht, WHY?: Event::with('participants')...
// $event = DB::table('events')->find($id);
$event = Event::find($id);
/* $ps = $event->participants;
foreach ($ps as $p) {
echo $p->name;
} die(); */
User::with('images')->find($userId)
return Response::json($event);
}
/**
* Workaround, Get participants by event id
*
* @Get("{id}/ps")
*/
public function participants($id) {
$ps = DB::table('participants')
->where('event_id', $id)
->get();
// funkt nicht, WHY?: $ps = Participant::find($id);
return Response::json($ps);
}
/**
* Add new event
*
......
......@@ -4,6 +4,9 @@ use Illuminate\Database\Eloquent\Model as Eloquent;
class Participant extends Eloquent {
public function event()
{
return $this->belongsTo('Event');
}
}
\ No newline at end of file
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