PHP code example of basekit-laravel / basekit-laravel-media

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

    

basekit-laravel / basekit-laravel-media example snippets


return [
    // Where uploads are stored: a Laravel disk and a directory on it.
    'disk' => env('BASEKIT_MEDIA_DISK', 'public'),
    'path' => env('BASEKIT_MEDIA_PATH', 'media'),

    // true: delete() keeps the row and restore() brings it back.
    // false: delete() removes the row and the file.
    'soft_deletes' => true,

    'uploads' => [
        'max_size' => env('BASEKIT_MEDIA_MAX_SIZE'),   // kilobytes; null for Filament's 12 MB
        'accepted_file_types' => ['image/*'],
    ],

    // Gate names. null allows the ability without asking.
    'permissions' => [
        'view' => env('BASEKIT_MEDIA_VIEW_PERMISSION'),
        'create' => env('BASEKIT_MEDIA_CREATE_PERMISSION'),
        'update' => env('BASEKIT_MEDIA_UPDATE_PERMISSION'),
        'delete' => env('BASEKIT_MEDIA_DELETE_PERMISSION'),
    ],
];

use BasekitLaravel\BasekitLaravelMedia\Filament\MediaPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugin(new MediaPlugin);
}

Gate::define('manage-media', fn (User $user): bool => $user->isEditor());

'permissions' => [
    'view' => 'manage-media',
],

Media::maxUploadSize();      // 5120, or null
Media::acceptedFileTypes();  // ['image/*']

$media->delete();        // gone from the library, still on the disk
$media->restore();       // back in the library, still on the disk
$media->forceDelete();   // row and file gone for good

'soft_deletes' => false,

use BasekitLaravel\BasekitLaravelMedia\Models\Media;

Media::query()->orderBy('id', 'desc')->paginate(24);       // index pages
$media->storageUrl();                                       // web URL for an <img>
$media->humanSize();                                        // "1.2 MB" for a listing
Media::findByStorageValue('/storage/media/cover.jpg');     // resolve a stored value
bash
php artisan vendor:publish --tag="basekit-laravel-media-migrations"
php artisan migrate
bash
php artisan filament:assets
bash
php artisan vendor:publish --tag="basekit-laravel-media-config"
bash
php artisan vendor:publish --tag="basekit-laravel-media-views"
php artisan vendor:publish --tag="basekit-laravel-media-translations"