From 8a993a62abc505f3505ce8431dc32b95490bafab Mon Sep 17 00:00:00 2001 From: Gregorio Chiko Putra Date: Fri, 24 May 2019 16:49:45 +0700 Subject: [PATCH] Fixed access log conflict --- app/Http/Controllers/SiswaController.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/SiswaController.php b/app/Http/Controllers/SiswaController.php index 1fac937..ed85d37 100644 --- a/app/Http/Controllers/SiswaController.php +++ b/app/Http/Controllers/SiswaController.php @@ -47,8 +47,22 @@ class SiswaController extends Controller $siswa = Siswa::where('nisn', $request->nisn) ->where('tanggal_lahir', $tanggalLahir); - if ($request->with !== null) + if ($request->with !== null) { + if (is_array($request->with)) { + $relationships = []; + foreach ($request->with as $relation) { + if ($relation === 'accessLog') + $relationships[$relation] = function ($query) use ($request) { + $query->where('src', '=', $request->src); + }; + else + $relationships[$relation] = function ($query) { $query; }; + } + $request->with = $relationships; + } + $siswa = $siswa->with($request->with); + } $siswa = $siswa->first();