Skip to main content

Posts

Showing posts from June, 2023

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();         // Set the modified value to the column         return $timeAgo;     } Set created time ago in model public function getRequestedTimeAttribute($requested_time)     {         if(!empty($requested_time))         {              re

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',             'application/msword' => 'doc',             'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',             // Add more mappings as needed    

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 when a place is selected     autocomplete . addListener ( 'place_changed' , onPlaceSelected );  

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);

How to use form validations(Jquery validations) in step form?

<! DOCTYPE html > < html > < head > < title > Multi-file Upload </ title > < style > fieldset {   display : none ; } fieldset:first-child {   display : block ; } button {   margin-top : 10px ; } .prev {   margin-right : 10px ; } .drop-zone {   border : 2px dashed #ccc ;   width : 300px ;   height : 200px ;   padding : 20px ;   text-align : center ;   cursor : pointer ; } .file-preview {   display : flex ;   flex-wrap : wrap ;   margin-top : 10px ; } .file-item {   display : flex ;   align-items : center ;   margin-right : 10px ;   margin-bottom : 10px ; } .file-item img {   width : 50px ;   height : 50px ;   margin-right : 5px ; } .remove-btn {   cursor : pointer ;   color : red ;   font-weight : bold ; } .file_preview_error {   color : red ; } .error {   color : red ;   display : block ; } </ style > < script src = "https://code.jquery.com/jquery-3.6.0.min.js" ></ script > < script src = "https://cd