Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel multiple copy record

 
//contact_ids is ['10','11',''12], i mean multiple value;contact_ids data type is json so that we will use json_decode()

$sharedContact = SharedContact::all();
$contacts = Contact::whereIn('id',json_decode($sharedContact->contact_ids))->get();

            foreach ($contacts as $contact){
				// copying the old record
                $sharedContact = $contact->replicate();
                
				//change name for image and saving in local storage
                $newName = 'share_'.time().'_'.$contact->photo;
                $newPathWithName = 'public/photo/'.$newName;
                
                if (Storage::copy('public/photo/'.$contact->photo , $newPathWithName)) {
//                    dd("success");
                    $sharedContact->photo = $newName;
                    $sharedContact->user_id = Auth::id();
                    $result = $sharedContact->save();
                }
                dd($result);
                
            }
Comment

PREVIOUS NEXT
Code Example
Php :: extract text before last space php 
Php :: how to create resource controller in laravel 
Php :: Call to undefined function GuzzleHttp\_idn_uri_convert() 
Php :: laravel route multiple middleware 
Php :: php preg_quote 
Php :: wocommerce product image 
Php :: php copy array 
Php :: laravel array in lang 
Php :: array_chunk in php 
Php :: laravel pluck 
Php :: twig resto 
Php :: php array push with key 
Php :: wordpress query get results 
Php :: acos() php 
Php :: create a module laravel 
Php :: change verify email template laravel 
Php :: PHP $argv echo 
Php :: firstOrFail() 
Php :: laravel import xml to database 
Php :: php configuration in apache server 2.4 
Php :: match php 
Php :: laravel store blob image into database 
Php :: get diff array php 
Php :: variables in php 
Php :: check if column has value in laravel eloquent 
Php :: php multi elseif statement ternary 
Php :: @method overide form laravel 
Php :: how to import in laravel excel command 
Php :: laravel route 
Php :: laravel_login1 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =