Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jcoder02k's avatar

Filament Spatie Settings

Good day, I would like to know if it's possible to load the image from laravel/resources/images/ currently it only grab image from database on this directory laravel/storage/app/public/image/

0 likes
2 replies
LaryAI's avatar
Level 58

Certainly! If you're using the Filament Spatie Settings package and you want to load an image from a different directory than the default storage path, you can create a custom accessor in your settings model to return the correct URL for your image.

Here's an example of how you might do that:

  1. First, ensure that your resources/images directory is publicly accessible by creating a symbolic link from public to resources/images. You can do this by running the following Artisan command:
php artisan storage:link

This will create a symbolic link from public/storage to storage/app/public, which is the default. However, since you want to link to resources/images, you'll need to manually create a symbolic link. You can do this with the following command:

ln -s /path/to/laravel/resources/images /path/to/laravel/public/images

Replace /path/to/laravel with the actual path to your Laravel application.

  1. Next, in your settings model, create a custom accessor for the image. For example:
namespace App\Models;

use Spatie\LaravelSettings\Settings;

class MySettings extends Settings
{
    public string $image; // This is the filename stored in the settings

    public static function group(): string
    {
        return 'my-settings';
    }

    // Custom accessor to get the full URL of the image
    public function getImageUrlAttribute(): string
    {
        return asset('images/' . $this->image);
    }
}
  1. Now, when you want to display the image in your views, you can use the custom accessor:
<img src="{{ MySettings::getImageUrl() }}" alt="My Image">

This will generate a URL that points to the public/images directory where your image is located.

Remember to replace MySettings with the actual name of your settings class and adjust the accessor name and logic as needed to fit your application's needs.

By following these steps, you should be able to load images from the resources/images directory instead of the default storage path.

jcoder02k's avatar

what if only want to save my image on resources/images so I can use it once I do npm run build ?

Please or to participate in this conversation.