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:
- First, ensure that your
resources/imagesdirectory is publicly accessible by creating a symbolic link frompublictoresources/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.
- 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);
}
}
- 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.