BBR - Add media from disk

4 years ago

jovertical

Code

$kriza = App\Models\User::find(19746);

// $kriza->profile
//   ->addMediaFromDisk('example/side-photo.jpg')
//   ->preservingOriginal()
//   ->toMediaCollection('body:side');

$kriza->profile->bodyPhotos;

Output

=> Illuminate\Database\Eloquent\Collection {#2625
     all: [
       App\Models\Media {#2630
         id: 46194,
         model_type: "App\Models\UserProfile",
         model_id: 19544,
         collection_name: "body:back",
         name: "back-photo",
         file_name: "back-photo.jpg",
         mime_type: "image/jpeg",
         disk: "public",
         size: 860746,
         manipulations: "[]",
         custom_properties: "{"generated_conversions": {"thumb": true}}",
         responsive_images: "[]",
         order_column: 46049,
         created_at: "2020-10-12 10:32:17",
         updated_at: "2020-10-12 10:32:18",
       },
       App\Models\Media {#2590
         id: 46195,
         model_type: "App\Models\UserProfile",
         model_id: 19544,
         collection_name: "body:front",
         name: "front-photo",
         file_name: "front-photo.jpg",
         mime_type: "image/jpeg",
         disk: "public",
         size: 834186,
         manipulations: "[]",
         custom_properties: "{"generated_conversions": {"thumb": true}}",
         responsive_images: "[]",
         order_column: 46050,
         created_at: "2020-10-12 10:32:49",
         updated_at: "2020-10-12 10:32:49",
       },
       App\Models\Media {#2606
         id: 46196,
         model_type: "App\Models\UserProfile",
         model_id: 19544,
         collection_name: "body:side",
         name: "side-photo",
         file_name: "side-photo.jpg",
         mime_type: "image/jpeg",
         disk: "public",
         size: 827982,
         manipulations: "[]",
         custom_properties: "{"generated_conversions": {"thumb": true}}",
         responsive_images: "[]",
         order_column: 46051,
         created_at: "2020-10-12 10:32:52",
         updated_at: "2020-10-12 10:32:52",
       },
     ],
   }
HELO: Local email testing for your desktop!