PHP code example of bakkali / laravel-media

1. Go to this page and download the library: Download bakkali/laravel-media library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bakkali / laravel-media example snippets


 composer 


 php artisan vendor:publish --tag=media-migrations
 php artisan migrate


use Bakkali\Media\Traits\HasMedia;

class Post extends Model
{
    use HasMedia;

    // your code...
}


$post = Post::find(1);

// Add a media file to 'images' collection
$post->addMedia('/path/to/file.jpg', 'images');



$images = $post->getMedia('images');

foreach ($images as $media) {
    echo $media->file_name;
    echo $media->disk;
}



$post->updateMedia($mediaId, [
    'name' => 'New name'
]);



$post->destroyMedia($mediaId);



$post->forceDeleteMedia($mediaId);



- composer update bakkali/laravel-media:dev-main