PHP code example of toneflix-code / laravel-fileable

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

    

toneflix-code / laravel-fileable example snippets


ToneflixCode\LaravelFileable\FileableServiceProvider::class

'Fileable' => ToneflixCode\LaravelFileable\Facades\Fileable::class

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use ToneflixCode\LaravelFileable\Traits\Fileable;

class User extends Model
{
    use HasFactory, Fileable;

    public function registerFileable()
    {
        $this->fileableLoader([
            'avatar' => 'default',
        ]);
    }
}


$this->fileableLoader([
    'avatar' => 'avatar',
]);

$this->fileableLoader([
    'avatar' => 'avatar',
    'image' => 'default',
]);

$this->fileableLoader('avatar', 'default');

$this->fileableLoader('avatar', 'default', true);

$this->fileableLoader([
    'avatar' => 'avatar',
], 'default', true);

$this->fileableLoader('avatar', 'default', true, true);

$this->fileableLoader([
    'avatar' => 'avatar',
], 'default', true, true);

$this->fileableLoader('admin_avatar', 'default', true, true, 'image');

$this->fileableLoader([
    'admin_avatar' => 'avatar',
], 'default', true, true, 'image');

$this->fileableLoader([
    'cover' => 'cover',
    'admin_avatar' => 'avatar',
], 'default', true, true, [
    'cover' => 'cover_image',
    'admin_avatar' => 'image',
]);

public static function registerEvents()
{
    static::creating(function ($item) {
        $item->slug = str($item->title)->slug();
    });
}

$post = Post::first();
var_dump($post->default_image);

$user = User::first();
$avatar = $user->media_file;
var_dump($avatar);

$post = Post::first();
var_dump($post->media_file_info);

$post = Post::first();
var_dump($post->get_files);
var_dump($user->get_files['image']);

$user = User::first();
var_dump($user->files);
var_dump($user->files['avatar']);

$post = Post::first();
var_dump($post->files['image']);

$user = User::first();
var_dump($user->responsive_images);
var_dump($user->responsive_images['avatar']);

$post = Post::first();
var_dump($post->responsive_images['image']);
var_dump($post->responsive_images['banner']);

use ToneflixCode\LaravelFileable\Media;
use App\Models\User;

$user = User::find(1);

$user->image = (new Media())->save('media', "image", $user->image);
$user->saveQuietly();

['forms' => $forms] = $this->validate($request, [
    'users.*.id' => ['each ($forms as $i => $form) {
    $user = User::find($form['id']);

    $user->image = (new Media())->save('media', "users.*.image", $user->image, $i);
    $user->saveQuietly();
}
bash
php artisan vendor:publish --provider="ToneflixCode\LaravelFileable\FileableServiceProvider"
bash
php artisan storage:link