Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel copy data

 
//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 :: yii1 refresh cache schema 
Php :: carbon if date is today 
Php :: how to search like in php 
Php :: wp+get tags for custom post type 
Php :: how to create foreign key in laravel 
Php :: php try to decode json 
Php :: php run command terminal 
Php :: saving an image from pc to php 
Php :: resource route laravel 8 
Php :: Laravel run seed table 
Php :: woocommerce_variation_option_name on frontend 
Php :: Program for factorial of a number in php 
Php :: php join 
Php :: Predefined Constants php 
Php :: Best Security tools for php 
Php :: laravel file uploads 
Php :: php epoch conversion 
Php :: types of method in api 
Php :: php get array key 
Php :: laravel pagination 
Php :: clear cache using laravel controller 
Php :: php sort by key 
Php :: Get data from array (from an API) in Laravel 
Php :: php artisan serve stop 
Php :: yii2 migration --fields foreign 
Php :: laravel admin multi images 
Php :: magento 2 colllection set select 
Php :: sqlstate[22023]: invalid parameter value: 
Php :: laravel collection contains 
Php :: laravel swagger 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =