services:
  app:
    build:
      context: .
      dockerfile: php.Dockerfile
    container_name: laravel_app
    working_dir: /var/www/html
    volumes:
      - .:/var/www/html
    depends_on:
      - db
      - mailhog
    environment:
      DB_CONNECTION: mysql
      DB_HOST: db
      DB_PORT: 3306
      DB_DATABASE: ${DB_DATABASE}
      DB_USERNAME: ${DB_USERNAME}
      DB_PASSWORD: ${DB_PASSWORD}
    networks:
      - laravel

  web:
    build:
      context: .
      dockerfile: nginx.Dockerfile
    container_name: laravel_nginx
    volumes:
      - .:/var/www/html
    depends_on:
      - app
    expose:
      - "80" # Internal port for Traefik
    networks:
      - laravel

  db:
    image: mysql:8.0
    container_name: laravel_mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_USER: ${DB_USERNAME}
      MYSQL_PASSWORD: ${DB_PASSWORD}
    volumes:
      - db_data:/var/lib/mysql
    networks:
      - laravel

  mailhog:
    image: mailhog/mailhog:latest
    container_name: laravel_mailhog
    ports:
      - "1025:1025"  # SMTP port
      - "8025:8025"  # Web interface port
    networks:
      - laravel

volumes:
  db_data:

networks:
  laravel:
    driver: bridge