Coder Social home page Coder Social logo

Comments (2)

Rezrazi avatar Rezrazi commented on July 26, 2024 1

Hi,

The on-demand filesystem feature on the file manager saves the disk name as default as your disk wouldn't actually have a name, you need to apply your same business logic when you'll need to retrieve the assets from the disks.

Otherwise you'll need to create those disks in filesystems.php with specific names and then reuse that name with Storage::disk() if you want ease of access to the assets.

Regards
Charaf

from nova-file-manager.

mikaelpopowicz avatar mikaelpopowicz commented on July 26, 2024 1

You may add a method on your user model which provides the disk instance. So you will be able to configure the filemanager and also retrieve the user's files

<?php

namespace App\Models;

use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Oneduo\NovaFileManager\Casts\Asset;

class User extends Authenticatable
{
    protected $fillable = [
        'role',
        'slug',
        'avatar',
        'name',
        'email',
        'password',
    ];
    
    protected $casts = [
        'avatar' => Asset::class,
    ];

    public function storage(): Filesystem
    {
        return Storage::build([
            'driver' => 'local',
            'root' => storage_path("app/public/pouzivatelia/{$this->role}/{$this->slug}"),
            'url' => config('app.url')."/storage/pouzivatelia/{$this->role}/{$this->slug}",
        ]);
    }

    // this is an example on how to use the custom filesystem
    public function avatarExists(): bool
    {
        if (!$this->avatar) {
            return false;
        }
        
        return $this->storage()->exists($this->avatar->path);
    }
}

You may configure the field like this :

<?php

use Laravel\Nova\Http\Requests\NovaRequest;
use Oneduo\NovaFileManager\FileManager;

class User extends Resource
{
    // ...

    public function fields(NovaRequest $request): array
    {
        return [
            // ... any other fields
            FileManager::make(__('Avatar'), 'avatar')
                ->filesystem(fn(NovaRequest $request) => $request->user()->storage()),
        ];
    }
}

from nova-file-manager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.