RichText image upload on private disk

Hi there,

I am trying to find a way on how to display images in the RichText editor that are private (ie. only viewable by the user that created the note). Using the public disk works, but as soon as I use private disk it fails to fetch the image (404).

Section::make()->columns(1) ->schema([ RichEditor::make('notes')->label('Bilješke') ->fileAttachmentsDisk('private') ->fileAttachmentsDirectory('form-attachments') ->fileAttachmentsVisibility('private') ])]);

filesystems.php

'private' => [ 'driver' => 'local', 'root' => storage_path('app/private'), 'url' => env('APP_URL').'/private', 'visibility' => 'private', ],
Solution
I figured it out. Dumb mistake. I was using 127.0.0.1, but my .env was set to localhost... Different domains...

Anyway, it works now. All users that are team members, can see those attachmentes and download them through the link (if they decide to copy the link from the richtextbox editor).

If they get removed from the team, they get 404. If they are not logged in, they get redirected to login page.

Controller

public function getAttachedMedia($team_id, $file_name) { $team = Team::where('slug', $team_id)->first(); if(Auth::id() && Auth::user()->canAccessTenant($team)) { $file = Storage::disk('notes_attachments')->get($team_id . '/' . $file_name); return (new \Illuminate\Http\Response($file))->header('Content-Type', 'application/png'); } else { abort(404); } }

filesystem.php

'notes_attachments' => [ 'driver' => 'local', 'root' => storage_path('app/notes_attachments'), 'url' => env('APP_URL').'/notes_attachments', 'visibility' => 'private', 'throw' => true, ],

Routes (I only have one panel anyways, for multiple panels, some more work would need to be done)
Route::get('/notes_attachments/{team_slug}/{file_name}', [AttachmentsMediaController::class, 'getAttachedMedia'])->middleware(['auth']); Route::redirect('//login', '/app/login')->name('login');

Model
public function teams(): BelongsToMany { return $this->belongsToMany(Team::class)->withTimestamps()->wherePivot('status', 'A'); } public function team() { return Filament::getTenant(); } public function canAccessTenant(Model $tenant): bool { return $this->teams->contains($tenant); }
Was this page helpful?