From b978b2bc0be8555ce1f9bfccca5f02ea7f21668d Mon Sep 17 00:00:00 2001 From: jedi Date: Mon, 2 Dec 2019 18:41:40 +0100 Subject: [PATCH] filter items by event in Controller --- app/Container.php | 2 +- app/Http/Controllers/ItemController.php | 7 +++++-- app/Item.php | 5 +---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/Container.php b/app/Container.php index f51791c..3d961e2 100644 --- a/app/Container.php +++ b/app/Container.php @@ -22,5 +22,5 @@ class Container extends Model * * @var array */ - protected $hidden = ['created_at','updated_at']; + protected $hidden = ['created_at', 'deleted_at', 'updated_at']; } diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index 91f4eed..57b3ff6 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Item; +use App\Event; use Illuminate\Http\Request; class ItemController extends Controller @@ -15,12 +16,14 @@ class ItemController extends Controller public function showByEvent($event) { - return response()->json(Item::byEvent($event)); + $eid = Event::where('slug','=',$event)->first()->eid; + return response()->json(Item::where('eid','=',$eid)->get()); } public function searchByEvent($event, $query) { - return response()->json(Item::byEvent($event)); //TODO actually search + $eid = Event::where('slug','=',$event)->first()->eid; + return response()->json(Item::where('eid','=',$eid)->get()); //TODO actually search } public function showOneItem($event, $id) diff --git a/app/Item.php b/app/Item.php index 9e4d42f..c2d2be8 100644 --- a/app/Item.php +++ b/app/Item.php @@ -23,9 +23,6 @@ class Item extends Model * * @var array */ - protected $hidden = ['created_at','updated_at']; + protected $hidden = ['created_at','updated_at', 'deleted_at', 'eid']; - public static function byEvent($event){ - return DB::table('users')->join('events', 'users.eid', '=', 'events.eid')->get(); - } }