Laravel Authentication Scaffolding: A Deep Dive into Laravel Breeze & Jetstream
Implement authentication quickly with Laravel's starter kits.
Before installing Laravel, ensure you have:
composer global require laravel/installer
laravel new my-first-blog
cd my-first-blog
php artisan serve
Visit http://localhost:8000 in your browser - you should see the Laravel welcome page!
composer create-project laravel/laravel teachyleaf-blog
cd teachyleaf-blog
php artisan serve
Once your project is created, let's explore the folder structure. This is crucial for understanding how Laravel organizes code.
my-first-blog/
├── app/
├── bootstrap/
├── config/
├── database/
├── public/
├── resources/
├── routes/
├── storage/
├── tests/
├── vendor/
└── environment files
This is where you'll spend most of your time.
app/
├── Console/ # Custom Artisan commands
├── Exceptions/ # Exception handlers
├── Http/
│ ├── Controllers/ # All your controllers
│ ├── Middleware/ # Custom middleware
│ └── Kernel.php # HTTP kernel
├── Models/ # Eloquent models
└── Providers/ # Service providers
Key Files:
Contains the app.php file that bootstraps the framework. You rarely need to touch this.
All configuration files live here.
config/
├── app.php # Application settings
├── auth.php # Authentication configuration
├── database.php # Database connections
├── mail.php # Email settings
└── services.php # Third-party services
Example config/app.php:
'name' => env('APP_NAME', 'Laravel'),
'env' => env('APP_ENV', 'production'),
'debug' => (bool) env('APP_DEBUG', false),
database/
├── factories/ # Model factories for testing
├── migrations/ # Database migration files
├── seeders/ # Database seeder classes
└── .gitignore
Example migration:
// database/migrations/2014_10_12_000000_create_users_table.php
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamps();
});
}
This is the document root for your web server.
public/
├── index.php # Entry point for all requests
├── css/ # Your CSS files
├── js/ # Your JavaScript files
└── storage/ # Symbolic link to storage/app/public
resources/
├── css/ # CSS preprocessor files
├── js/ # JavaScript files
├── views/ # Blade templates
└── lang/ # Language files
Example Blade view:
// resources/views/welcome.blade.php
<html>
<head>
<title>{{ $title ?? 'My Site' }}</title>
</head>
<body>
@yield('content')
</body>
</html>
Define your application endpoints here.
routes/
├── web.php # Web routes (session, cookies)
├── api.php # API routes (stateless)
├── console.php # Artisan command routes
└── channels.php # Broadcast channels
Example routes/web.php:
Route::get('/', function () {
return view('welcome');
});
Route::get('/about', function () {
return 'About Page';
});
Route::get('/users', [UserController::class, 'index']);
storage/
├── app/ # Store generated files
│ └── public/ # Publicly accessible files
├── framework/ # Framework generated files
├── logs/ # Application log files
└── .gitignore
tests/
├── Unit/ # Unit tests
├── Feature/ # Feature tests
└── TestCase.php # Base test case
Example test:
// tests/Feature/ExampleTest.php
public function test_basic_test()
{
$response = $this->get('/');
$response->assertStatus(200);
}
All third-party packages installed via Composer. Never modify files here manually.
APP_NAME=TeachyLeaf Blog
APP_ENV=local
APP_KEY=base64:...
APP_DEBUG=true
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=teachyleaf_blog
DB_USERNAME=root
DB_PASSWORD=
# Never commit .env to version control!
{
"require": {
"php": "^8.1",
"laravel/framework": "^10.10"
},
"require-dev": {
"laravel/pint": "^1.0"
}
}
// routes/web.php
Route::get('/hello', function () {
return 'Hello, TeachyLeaf Readers!';
});
// resources/views/welcome.blade.php
@extends('layouts.app')
@section('content')
<h1>Welcome to My First Laravel App!</h1>
<p>This is running on Laravel {{ app()->version() }}</p>
@endsection
php artisan serve
Visit http://localhost:8000/hello to see your message!
Problem: laravel command not found
Solution: Add Composer's global bin directory to your PATH
export PATH="$PATH:$HOME/.composer/vendor/bin"
Problem: PHP version too low
Solution: Update PHP or use Laravel Sail (Docker)
curl -s https://laravel.build/teachyleaf-blog | bash
Problem: Permission errors
Solution: Fix storage and bootstrap cache permissions
chmod -R 775 storage
chmod -R 775 bootstrap/cache
1. What's the purpose of the .env file?
The .env file stores environment-specific configuration like database credentials and API keys, keeping sensitive data out of your codebase.
2. What's the difference between resources/ and public/ directories?
resources/ contains source files (Blade templates, Sass, JS) that get compiled, while public/ contains the web-accessible assets like CSS, JS, and images.
3. Where would you put a new controller?
In the app/Http/Controllers/ directory, following PSR-4 autoloading standards.
4. What are migrations and where are they stored?
Migrations are version control for your database schema, stored in the database/migrations/ directory.
5. How do you start a Laravel development server?
Run php artisan serve from the project root directory.
# Create new project
laravel new project-name
# Or using Composer
composer create-project laravel/laravel project-name
# Start development server
php artisan serve
# Generate application key
php artisan key:generate
# Run migrations
php artisan migrate
# Clear configuration cache
php artisan config:clear
Congratulations! You've set up your first Laravel project. Now that you understand the structure, our next post will dive into Laravel Routing: All You Need to Know About GET, POST, and Resource Routes where you'll learn to create application endpoints.