PHP code example of tahirrasheed208 / laravel-medialibrary

1. Go to this page and download the library: Download tahirrasheed208/laravel-medialibrary 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/ */

    

tahirrasheed208 / laravel-medialibrary example snippets


<x-medialibrary-file-upload name="image" />

<x-medialibrary-file-upload name="image" :model="$model" />

$model = Model::find(1);
$model->handleMediaFromRequest()->toMediaCollection();

$model->handleMediaFromRequest('banner')->toMediaCollection();

$model->handleMediaFromRequest()->toMediaCollection('images');

public function defaultCollection(): string
{
    return 'post_images';
}

$model->handleMediaFromRequest()->useDisk('s3')->toMediaCollection();

public function registerMediaConversions()
{
    $this->addMediaConversion('post_main')
        ->width(420)
        ->height(350);
}

public function registerMediaConversions()
{
    $this->addMediaConversion('post_main')
        ->width(420)
        ->height(350);

    $this->addMediaConversion('post_detail')
        ->width(700)
        ->height(550);
}

$this->addMediaConversion('post_main')
    ->width(420)
    ->height(350)
    ->crop();

$model->handleMediaFromRequest()->withoutConversions()->toMediaCollection();

<x-medialibrary-dropzone name="gallery" />

$model->attachGalleryToModelFromRequest('gallery')->toMediaCollection();

<x-medialibrary-dropzone name="gallery" collection="dropzone" />

<x-medialibrary-dropzone name="gallery" :model="$model" />

<x-medialibrary-dropzone name="gallery" message="Drop files here" />

$model->addMediaFromUrl($url, 'image')->toMediaCollection();

<x-medialibrary-file-upload name="image" setting="{{ setting()->get('name') }}" />

setting()->upload($request->toArray(), 'file_name');

setting()->upload($request->toArray(), 'file_name', 'option_name');

setting()->getFile('name');
bash
php artisan vendor:publish --provider="TahirRasheed\MediaLibrary\MediaLibraryServiceProvider" --tag=medialibrary-config
bash
php artisan vendor:publish --provider="TahirRasheed\MediaLibrary\MediaLibraryServiceProvider" --tag=medialibrary-migration
bash
php artisan migrate