public function parse(Request $request) { $parsed = json_decode($request['json'], true); foreach ($parsed as $key => $value) { unset($parsed[$key]['images']); unset($parsed[$key]['href']); $city = City::where('name', $value['city_id'])->first(); if ($city === null) { unset($parsed[$key]); continue; } $parsed[$key]['category_id'] = 5; $parsed[$key]['city_id'] = $city->id; $parsed[$key]['created_at'] = Carbon::now()->subMinutes(rand(1, 59)); $parsed[$key]['updated_at'] = Carbon::now()->subMinutes(rand(1, 59)); } // dd($parsed); Ad::insert($parsed); return response('OK', 200); }