Skip to main content

Posts

Showing posts from September, 2023

How to show shape file (.shp)(map) on map with shape file?

Show shape file (.shp)(map) on map with shape file Include gasparesganga package in php code https://gasparesganga.com/labs/php-shapefile/ <?php // Register autoloader require_once('vendor/gasparesganga/php-shapefile/src/Shapefile/ShapefileAutoloader.php'); Shapefile\ShapefileAutoloader::register(); // Import classes use Shapefile\Shapefile; use Shapefile\ShapefileException; use Shapefile\ShapefileReader; try {     // Open Shapefile     $Shapefile = new ShapefileReader('filepath/shapefile.shp');         // $json_data = $Shapefile->fetchRecord()->getGeoJSON();     $geoJsonArray = [];     while ($Geometry = $Shapefile->fetchRecord()) {         // Skip the record if marked as "deleted"         if ($Geometry->isDeleted()) {             continue;         }                   // Print Geometry as an Array /*         print_r($Geometry->getArray());                  // Print Geometry as WKT         print_r($Geometry->getWKT());                  //

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "The date is not in the correct format."; */             }         }     }     return false; } 

How to delete previous image on update new image or delete record in laravel?

Delete previous image on update new image or delete record in laravel Laravel Model public function getProfileImageAttribute($profile_image)     {         if(!empty($profile_image))         {             return $filepath = URL::to('/') . '/public/upload/' . $profile_image;         }     }     // Custom method to get the original unmodified URL     public function getOriginalProfileImageAttribute()     {         return $this->attributes['profile_image'];     }     function deleteProfileImage(){         $model = $this;         // Check if the avatar attribute is changing         if ($model->isDirty('profile_image')) {             // Delete the previous profile image if it exists             $previousFile = $model->getOriginal('original_profile_image');             if (!empty($previousFile) && Storage::disk('uploads')->exists($previousFile)) {                 // Delete the file                 Storage::disk('uploads&#