#!/bin/sh
set -e

# docker-compose.yml bind-mounts the repo into /var/www/html for local dev
# (see its "Mount source for local development" comment), which replaces
# whatever ownership the Dockerfile's build-time `chown -R www-data:www-data`
# set — bind mounts show the host filesystem's permissions, not the image
# layer's. On this Windows/Docker Desktop setup that leaves
# laravel/storage/* and laravel/bootstrap/cache owned by root with no
# write bit for www-data, so Blade's view cache (tempnam() under the hood)
# fails with a 500. Fix it at container start, every start, since it can't
# survive in the image itself.
chmod -R 777 /var/www/html/laravel/storage /var/www/html/laravel/bootstrap/cache 2>/dev/null || true

exec docker-php-entrypoint "$@"
