public function index(Request $request, Region $region) { $regions = $region->orderBy('id', 'desc'); if ($request->has('state_id')) { $regions->where('state_id', $request->input('state_id')); } $regions = $regions->get(); return $regions; }
/** * Register the service provider. * * @return void */ public function register() { //City City::created(function ($city) { UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_city', 'reference_id' => $city->id]); }); City::updated(function ($city) { UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_city', 'reference_id' => $city->id]); }); City::deleted(function ($city) { UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_city', 'reference_id' => $city->id]); }); //Country Country::created(function ($country) { UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_country', 'reference_id' => $country->id]); }); Country::updated(function ($country) { UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_country', 'reference_id' => $country->id]); }); Country::deleted(function ($country) { UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_country', 'reference_id' => $country->id]); }); //Region Region::created(function ($region) { UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_region', 'reference_id' => $region->id]); }); Region::updated(function ($region) { UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_region', 'reference_id' => $region->id]); }); Region::deleted(function ($region) { UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_region', 'reference_id' => $region->id]); }); //State State::created(function ($state) { UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_state', 'reference_id' => $state->id]); }); State::updated(function ($state) { UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_state', 'reference_id' => $state->id]); }); State::deleted(function ($state) { UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_state', 'reference_id' => $state->id]); }); }