Laravel Framework: A Beginner's Guide for Developers
Laravel Framework: A Beginner's Guide for Developers
Specialized Guide by Alaa Amer – Professional Web & App Developer
Laravel is one of the most powerful and popular PHP frameworks in the world. It features ease of use, high security, and advanced tools that accelerate development.
2️⃣ Installing Laravel
Basic Requirements:
- PHP 8.1 or newer
- Composer
- Node.js & NPM (optional for Frontend)
Installation Method:
# Install Laravel globally
composer global require laravel/installer
# Create new project
laravel new my-project
# Or using Composer
composer create-project laravel/laravel my-project
# Enter project
cd my-project
# Start local server
php artisan serve
4️⃣ Database Setup
.env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my_project_db
DB_USERNAME=root
DB_PASSWORD=
Create Migration:
# Create new migration
php artisan make:migration create_users_table
# Run migrations
php artisan migrate
# Reset database
php artisan migrate:refresh
Migration Example:
<?php
// database/migrations/2023_xx_xx_create_posts_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->text('content');
$table->string('slug')->unique();
$table->boolean('is_published')->default(false);
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('posts');
}
};
6️⃣ Routes
<?php
// routes/web.php
use App\Http\Controllers\PostController;
use Illuminate\Support\Facades\Route;
// Homepage
Route::get('/', function () {
return view('welcome');
});
// Post routes
Route::get('/posts', [PostController::class, 'index'])->name('posts.index');
Route::get('/posts/create', [PostController::class, 'create'])
->middleware('auth')
->name('posts.create');
Route::post('/posts', [PostController::class, 'store'])
->middleware('auth')
->name('posts.store');
Route::get('/posts/{slug}', [PostController::class, 'show'])->name('posts.show');
// Protected routes
Route::middleware('auth')->group(function () {
Route::get('/posts/{post}/edit', [PostController::class, 'edit'])->name('posts.edit');
Route::put('/posts/{post}', [PostController::class, 'update'])->name('posts.update');
Route::delete('/posts/{post}', [PostController::class, 'destroy'])->name('posts.destroy');
});
// Authentication Routes
require __DIR__.'/auth.php';
💡 Important Artisan Commands
# Create new components
php artisan make:model ModelName
php artisan make:controller ControllerName
php artisan make:migration create_table_name
php artisan make:seeder SeederName
php artisan make:middleware MiddlewareName
# Database management
php artisan migrate
php artisan migrate:rollback
php artisan db:seed
# Cache management
php artisan cache:clear
php artisan config:cache
php artisan route:cache
# Application maintenance
php artisan down
php artisan up
# Generate application key
php artisan key:generate
Next Step
After mastering the basics, move to APIs, Testing, and Advanced Laravel Features.
Article Category
Laravel Framework: A Beginner's Guide for Developers
Comprehensive introduction to Laravel PHP framework explaining core concepts and how to build your first web application.
Consultation & Communication
Direct communication via WhatsApp or phone to understand your project needs precisely.
Planning & Scheduling
Creating clear work plan with specific timeline for each project phase.
Development & Coding
Building projects with latest technologies ensuring high performance and security.
Testing & Delivery
Comprehensive testing and thorough review before final project delivery.