lookup($isbn); $arr = [ 'success' => false ]; if ($result) { $arr = array_merge($arr, [ 'success' => true, 'data' => $result ]); } $book = Book::where('barcode', $isbn)->first(); if ($book) { $arr['warning'] = 'Item already exists.
Location: ' . $book->location->name; } return response()->json($arr); } }