#development #laravel #php

When you use the Laravel Filesystem classes, by default, it doesn't throw any exceptions.

For example, when you write a file, you have to check the return value to see if it was written or not:

1if (! Storage::put('file.jpg', $contents)) {
2    // The file could not be written to disk...

I personally find this a little tricky as it's one of those things which are easy to forget and overlook. I much prefer that an exception is thrown instead.

According to the Laravel documentation, you can do this:

If you wish, you may define the throw option within your filesystem disk's configuration array. When this option is defined as true, "write" methods such as put will throw an instance of League\Flysystem\UnableToWriteFile when write operations fail.

1'public' => [
2    'driver' => 'local',
3    // ...
4    'throw' => true,