Skip to main content

Posts

Showing posts from 2023

How to create remove and add more inputs functionality with input type file and text in Laravel?

Create remove and add more inputs functionality with input type file and text in Laravel Blade file code       <form action="{{ route('storeDocuments') }}" method="post" enctype="multipart/form-data">         @csrf         <div id="inputFields">             @if(!empty($documents[0]))             @php $counter = 1000; @endphp                 @foreach($documents as $document)                     <input type="hidden" id="document_id" name="documents[{{$counter}}][document_id]" value="{{$document->id}}">                     <div class="field">                         <label for="title">Title:</label>             ...

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;         }                  ...

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 "...

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           ...

How to integrate one signal push notification in website (Laravel)?

Integrate one signal push notification     < script src = "https://cdn.onesignal.com/sdks/OneSignalSDK.js" async = "" ></ script >     < script >     var OneSignal = window . OneSignal || [];         var initConfig = {             appId: "{{ env('OneSignalApp_ID') }}" ,             notifyButton: {                 enable: true             },         };         OneSignal . push ( function () {             OneSignal . init ( initConfig );             console . log ( OneSignal );         });         OneSignal . push ( function () { /*             OneSignal.isPushNotificationsEnabled(function(isEnabled) {     ...

How to integrate pubnub chat in website?

Integrate pubnub chat   <script src="https://code.jquery.com/jquery-3.7.0.min.js" integrity="sha256-2Pmvv0kuTBOenSvLm6bvfBSSHrUJ+3A7x6P5Ebd07/g=" crossorigin="anonymous"></script> <script src="https://cdn.pubnub.com/sdk/javascript/pubnub.7.2.3.min.js"></script> <style> .user_pubnub_mgs {     height: 450px;     border: 1px solid #d0d0d0;     padding: 10px 12px;     overflow-y: auto; } .other_user_chat {     background: #b4b4b4;     margin-bottom: 10px;     padding: 10px;     width: fit-content;     font-size: 14px;     border-radius: 10px 0px 10px 10px;     color: #fff;     display: block;     word-break: break-word; } .current_user_chat {     background: #2695ee;     margin-bottom: 10px;     padding: 10px;     width: fit-content;     font-size: 14px;     border-radi...

How to create load more on scroll functionality in laravel?

Create load more on scroll functionality in laravel Main listing file <style> .notifications_page_cover_ui {     overflow: auto;     max-height: 474px; } </style> <div class="ps-section__right">     <div class="section-header">         <h3>Notifications</h3>     </div>     <div class="section-content">        <div class="notifications_page_cover_ui" id="load-more-container">         <?php echo $notification_list ?>        </div>     </div> </div> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() {     let lastNotificationID = {!! $lastNotificationID !!}; // Pass the last item ID from your controller or view     let loading = false;     function loadMoreData() {   ...

How to use Mutators and Accessors in Laravel?

Mutators and Accessors in Laravel       Set file path in model public function getFilePathAttribute($file_path)     {         if(!empty($file_path))         {              return $filepath = URL::to('/') . '/upload/' . $file_path; /*             return asset('/upoad/' . $file_path); */         }     } Set created time ago in model protected $appends = ["created_time_ago"]; public function getCreatedTimeAgoAttribute()     {         $created_at = $this->attributes['created_at'];         // Convert the date/time to a Carbon instance         $carbonCreatedAt = Carbon::parse($created_at);         // Get the "time ago" format         $timeAgo = $carbonCreatedAt->diffForHumans();       ...

How to upload multi file by base64 url in laravel?

Multi file upload by base64 url in laravel Function function uploadBase64File($base64_url){     $response = array();     $base64Data = $base64_url;     $pattern = '/data:(.*);base64,([^"]*)/';     // Perform the regular expression match     preg_match($pattern, $base64Data, $matches);     if (!empty($matches[1])) {         $mime = $matches[1];         // Remove the data:image/jpeg;base64, part from the string         $mimeToExt = [             'image/jpeg' => 'jpg',             'image/png' => 'png',             'image/gif' => 'gif',             'image/bmp' => 'bmp',             'image/webp' => 'webp',             'application/pdf' => 'pdf',          ...

How to use autofill google place APi(google Map APi)?

  < html >     < head >     < script src = "https://maps.googleapis.com/maps/api/js?key=AIzaSyBcRA4LijSY8e-FG4lN1sTYChasKAEsrGo&libraries=places" ></ script >     </ head >     < body >     < input type = "text" id = "autocomplete-input" placeholder = "Enter a location" >     </ body >     < script >     // Replace 'YOUR_API_KEY' with your actual API key     const apiKey = 'AIzaSyBcRA4LijSY8e-FG4lN1sTYChasKAEsrGo' ;     // Initialize the autocomplete object     const autocomplete = new google . maps . places . Autocomplete ( document . getElementById ( 'autocomplete-input' ), {     types: [ 'geocode' ],   // Restrict the results to geographical locations     apiKey: apiKey       // Provide your API key     });     // Add an event listener for whe...

How to preview, add more and remove file before upload?

  <! DOCTYPE html > <?php function decode_base64 ( $base64Data ){ $extension = null ; $pattern = '/data:(. * );base64,([^"] * )/' ; // Perform the regular expression match preg_match ( $pattern , $base64Data , $matches ); if (! empty ( $matches [ 1 ])){ $mime = $matches [ 1 ]; // Map MIME type to extension $mimeToExt = [     'image/jpeg' => 'jpg' ,     'image/png' => 'png' ,     'image/gif' => 'gif' ,     'image/bmp' => 'bmp' ,     'image/webp' => 'webp' ,     'application/pdf' => 'pdf' ,     'application/msword' => 'doc' ,     'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx' ,     // Add more mappings as needed ]; // Check if the MIME type exists in the mapping if ( isset ( $mimeToExt [ $mime ])) {     $extension = $mimeToExt [ $mime ]; } /*     print_r($matches);...