示例#1
0
 /**
  * check if there is a barangay and if it already exists in the database
  * if not, add it to the database
  *
  * @param Request $request
  * @param         $site
  *
  * @return bool|int
  */
 protected function _checkNewBarangay(Request $request, $site)
 {
     if (isset($request['barangay_name']) && $request['barangay_name'] != '') {
         $barangay_model = new Barangay();
         $request['barangay_name'] = ucfirst(strtolower($request['barangay_name']));
         if (!($barangay = $barangay_model->whereName($request['barangay_name'])->whereCityId($site->city_id)->first(['id']))) {
             $barangay = Barangay::create(['name' => $request['barangay_name'], 'city_id' => $site->city_id]);
         }
         return $barangay->id;
     }
     return false;
 }