# Setup Complete - Environment & Database Configuration

## ✅ Files Created

### Environment Files
- ✅ `.env.example` - Template environment file
- ✅ `.env` - Active environment file (created from .env.example)

### Database Migrations
- ✅ `database/migrations/2024_01_01_000000_create_permission_tables.php` - Spatie Permission tables
- ✅ All existing migrations are in place:
  - Users table
  - Companies table
  - Subscription plans table
  - Subscriptions table
  - Properties table
  - Property images table
  - Tenants table
  - Leases table
  - Payments table
  - Sessions table
  - Personal access tokens table

### Configuration Files
- ✅ `config/permission.php` - Spatie Permission configuration

## 📋 Next Steps

### 1. Install Dependencies
```bash
composer install
npm install
```

### 2. Generate Application Key
```bash
php artisan key:generate
```

### 3. Configure Database

Edit `.env` file and update database settings:

```env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=real_estate_saas
DB_USERNAME=root
DB_PASSWORD=your_password_here
```

**For XAMPP:**
- Default username is usually `root`
- Default password is usually empty (leave blank)
- Create database `real_estate_saas` in phpMyAdmin

### 4. Create Database

**Option A: Using phpMyAdmin (XAMPP)**
1. Open http://localhost/phpmyadmin
2. Click "New" to create a database
3. Name it: `real_estate_saas`
4. Choose collation: `utf8mb4_unicode_ci`
5. Click "Create"

**Option B: Using MySQL Command Line**
```sql
CREATE DATABASE real_estate_saas CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
```

### 5. Run Migrations and Seeders

```bash
php artisan migrate --seed
```

This will:
- Create all database tables
- Create Spatie Permission tables (roles, permissions, etc.)
- Seed default roles (super_admin, company_admin, agent, accountant, tenant, owner)
- Seed subscription plans (Basic, Pro, Enterprise)
- Create super admin user:
  - Email: `admin@realestate.com`
  - Password: `password`

### 6. Create Storage Link

```bash
php artisan storage:link
```

This creates a symbolic link for file uploads (property images).

### 7. Build Frontend Assets

```bash
npm run build
```

Or for development with hot reload:
```bash
npm run dev
```

### 8. Start the Server

```bash
php artisan serve
```

Visit: http://127.0.0.1:8000

## 🔐 Default Login Credentials

**Super Admin:**
- Email: `admin@realestate.com`
- Password: `password`

⚠️ **Important:** Change the password after first login!

## 📊 Database Structure

The system includes the following tables:

1. **users** - User accounts with company association
2. **companies** - Multi-tenant company records
3. **subscription_plans** - Subscription tiers
4. **subscriptions** - Active company subscriptions
5. **properties** - Real estate listings
6. **property_images** - Property images
7. **tenants** - Tenant profiles
8. **leases** - Rental agreements
9. **payments** - Payment records
10. **roles** - User roles (Spatie Permission)
11. **permissions** - System permissions (Spatie Permission)
12. **model_has_roles** - User-role assignments
13. **model_has_permissions** - User-permission assignments
14. **role_has_permissions** - Role-permission assignments
15. **sessions** - User sessions
16. **personal_access_tokens** - API tokens

## 🛠 Troubleshooting

### Migration Errors

If you get errors about missing config/permission.php:
```bash
php artisan config:clear
php artisan cache:clear
```

### Database Connection Errors

1. Check MySQL is running (XAMPP Control Panel)
2. Verify database credentials in `.env`
3. Ensure database exists
4. Check MySQL user has proper permissions

### Permission Errors

If you get permission errors on storage:
```bash
# Windows (PowerShell as Admin)
icacls storage /grant Users:F /T
icacls bootstrap\cache /grant Users:F /T
```

## ✅ Verification Checklist

- [ ] Composer dependencies installed
- [ ] NPM dependencies installed
- [ ] Application key generated
- [ ] Database created
- [ ] `.env` file configured
- [ ] Migrations run successfully
- [ ] Seeders run successfully
- [ ] Storage link created
- [ ] Assets built
- [ ] Server running
- [ ] Can login with super admin credentials

## 🚀 Ready to Use!

Once all steps are complete, you can:
1. Login as Super Admin
2. Create companies
3. Manage subscription plans
4. Companies can register and select plans
5. Full CRUD operations for properties, tenants, leases, and payments
