DALT.PHP
Reference

CLI Commands

Complete reference for DALT.PHP Artisan CLI commands

DALT.PHP includes a powerful command-line interface (CLI) called Artisan for common development tasks.

Getting Help

View all available commands:

php artisan help

Development Commands

serve

Start the PHP development server.

php artisan serve [host] [port]

Default: 127.0.0.1:8000

Examples:

# Start on default port 8000
php artisan serve

# Start on custom port
php artisan serve 127.0.0.1 8080

# Make accessible from network
php artisan serve 0.0.0.0 8000

If the specified port is in use, Artisan automatically finds the next available port.

What it does:

  • Starts PHP's built-in web server
  • Serves files from the public/ directory
  • Uses public/router.php for routing
  • Hot-reloads on file changes

dev

Start both PHP and Vite development servers simultaneously.

php artisan dev

What it does:

  • Starts PHP server on port 8000
  • Starts Vite dev server on port 5173
  • Enables hot module replacement (HMR) for frontend
  • Runs both servers in parallel

Requires Node.js and npm installed. Run npm install in .dalt/ directory first.

Press Ctrl+C to stop both servers.

Database Commands

migrate

Run all pending database migrations.

php artisan migrate

What it does:

  • Scans database/migrations/ directory
  • Executes .sql files in chronological order
  • Tracks executed migrations in migrations table
  • Skips already-run migrations

Output example:

Running migration: 20240315120000_create_users_table.sql
✓ Success

Running migration: 20240315130000_create_posts_table.sql
✓ Success

Ran 2 migrations.

Migrations are idempotent - safe to run multiple times.

migrate:fresh

Drop the database and run all migrations from scratch.

php artisan migrate:fresh

WARNING: This deletes ALL data! Only use in development.

What it does:

  • Deletes the SQLite database file
  • Recreates the database
  • Runs all migrations
  • Resets migration tracking

Use cases:

  • Starting fresh during development
  • Resetting test data
  • Fixing migration conflicts

make:migration

Create a new SQL migration file.

php artisan make:migration <name>

Examples:

# Create posts table migration
php artisan make:migration create_posts_table

# Create users table migration
php artisan make:migration create_users_table

# Add column migration
php artisan make:migration add_status_to_posts

Generated file:

database/migrations/20240315120000_create_posts_table.sql

Template content:

-- Migration: create_posts_table
-- Created: 2024-03-15 12:00:00

CREATE TABLE IF NOT EXISTS posts (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name VARCHAR(255) NOT NULL,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

-- Add indexes here
-- CREATE INDEX IF NOT EXISTS idx_posts_name ON posts(name);

-- Notes:
-- SQLite: INTEGER PRIMARY KEY AUTOINCREMENT
-- MySQL:  INT AUTO_INCREMENT PRIMARY KEY
-- PostgreSQL: SERIAL PRIMARY KEY

Next steps:

  1. Edit the generated file
  2. Customize table structure
  3. Run php artisan migrate

Testing Commands

test

Run the Pest test suite.

php artisan test

What it does:

  • Executes all tests in tests/ directory
  • Uses Pest PHP testing framework
  • Shows test results with colors
  • Reports coverage (if configured)

Requires Pest installed: composer require pestphp/pest --dev

Output example:

PASS  Tests\Feature\RoutingTest
✓ homepage loads successfully
✓ posts index shows all posts
✓ single post shows correct data

Tests:  3 passed
Time:   0.12s

verify

Verify a challenge solution.

php artisan verify <challenge-name>

Available challenges:

  • broken-routing
  • broken-middleware
  • broken-auth
  • broken-database
  • broken-session

Example:

php artisan verify broken-routing

Output:

╔══════════════════════════════════════════════════════════════╗
║           DALT Challenge Verification System                ║
╚══════════════════════════════════════════════════════════════╝

Verifying: broken-routing
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✓ Route get /posts/create exists
✓ Route get /posts/{id}/edit exists
✓ Route order correct: specific before generic
✓ No problematic code found

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Results: 4/4 tests passed
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✅ All tests passed! Challenge complete!

What it does:

  • Runs automated tests for the challenge
  • Checks for specific bugs and fixes
  • Provides hints if tests fail
  • Logs results to storage/logs/challenges.log

Exit codes:

  • 0 - All tests passed
  • 1 - Some tests failed

Example Commands

example:install

Install pre-built example code.

php artisan example:install <example-name>

Available examples:

  • auth - Complete authentication system

Example:

php artisan example:install auth

What it does:

  • Copies controller files to Http/controllers/
  • Copies view files to resources/views/
  • Appends routes to routes/routes.php
  • Creates installation marker

Installed files:

Http/controllers/
├── session/
│   ├── create.php (login form)
│   ├── store.php (login handler)
│   └── destroy.php (logout)
└── registration/
    ├── create.php (register form)
    └── store.php (register handler)

resources/views/auth/
├── login.view.php
└── register.view.php

Added routes:

$router->get('/register', 'registration/create.php')->only('guest');
$router->post('/register', 'registration/store.php')->only(['guest','csrf']);
$router->get('/login', 'session/create.php')->only('guest');
$router->post('/session', 'session/store.php')->only(['guest','csrf']);
$router->delete('/session', 'session/destroy.php')->only(['auth','csrf']);

After installation, visit /register or /login to use the auth system.

Command Reference

Quick Reference Table

CommandPurposeExample
serveStart dev serverphp artisan serve
devStart PHP + Vitephp artisan dev
migrateRun migrationsphp artisan migrate
migrate:freshReset databasephp artisan migrate:fresh
make:migrationCreate migrationphp artisan make:migration create_posts
testRun testsphp artisan test
verifyCheck challengephp artisan verify broken-routing
example:installInstall examplephp artisan example:install auth
helpShow helpphp artisan help

Common Workflows

Starting Development

# Terminal 1: Start servers
php artisan dev

# Terminal 2: Watch logs (optional)
tail -f storage/logs/app.log

Database Setup

# Create migration
php artisan make:migration create_posts_table

# Edit: database/migrations/TIMESTAMP_create_posts_table.sql

# Run migration
php artisan migrate

Working on Challenges

# Copy challenge files
cp course/challenges/broken-routing/routes/routes.php routes/

# Fix the bugs...

# Verify solution
php artisan verify broken-routing

Fresh Start

# Reset database
php artisan migrate:fresh

# Clear logs
rm storage/logs/*.log

# Restart server
php artisan serve

Troubleshooting

Port Already in Use

If you see "Address already in use":

# Use different port
php artisan serve 127.0.0.1 8080

# Or kill existing process
lsof -ti:8000 | xargs kill -9

Migration Errors

If migrations fail:

# Check migration syntax
cat database/migrations/TIMESTAMP_file.sql

# Reset and try again
php artisan migrate:fresh

Vite Not Starting

If php artisan dev fails:

# Install dependencies
cd .dalt
npm install

# Try again
cd ..
php artisan dev

Permission Errors

If you see permission denied:

# Make artisan executable
chmod +x artisan

# Fix storage permissions
chmod -R 775 storage
chmod -R 775 database

Advanced Usage

Custom Server Configuration

# Bind to all interfaces
php artisan serve 0.0.0.0 8000

# Use specific PHP version
/usr/bin/php8.2 artisan serve

Running Specific Tests

# Run specific test file
vendor/bin/pest tests/Feature/RoutingTest.php

# Run with coverage
vendor/bin/pest --coverage

Migration Management

# Check migration status
sqlite3 database/app.sqlite "SELECT * FROM migrations;"

# Manually mark migration as run
sqlite3 database/app.sqlite "INSERT INTO migrations (migration) VALUES ('20240315_file.sql');"

Environment Variables

Some commands respect environment variables:

# Use different database
DB_DATABASE=database/test.sqlite php artisan migrate

# Enable debug mode
APP_DEBUG=true php artisan serve

Next Steps

On this page