PHP Laravel Basics Cheat Sheet
Covers Artisan CLI commands, routing and controllers, Eloquent ORM models, and core Laravel concepts like Blade and middleware.
2 PagesBeginnerMar 22, 2026
Artisan CLI
Common commands for scaffolding and running a Laravel app.
bash
composer create-project laravel/laravel myapp # Create new Laravel appphp artisan serve # Start dev server (localhost:8000)php artisan make:model Post -m # Model + migrationphp artisan make:controller PostController -r # Resource controllerphp artisan migrate # Run pending migrationsphp artisan migrate:rollback # Roll back last migration batchphp artisan tinker # Interactive REPL
Routes & Controllers
Resourceful routing and request validation.
php
// routes/web.phpuse App\Http\Controllers\PostController;Route::get('/', function () { return view('welcome');});Route::resource('posts', PostController::class);// generates index, create, store, show, edit, update, destroy// app/Http/Controllers/PostController.phpclass PostController extends Controller{ public function index() { $posts = Post::latest()->paginate(10); return view('posts.index', compact('posts')); } public function store(Request $request) { $validated = $request->validate([ 'title' => 'required|max:255', 'body' => 'required', ]); Post::create($validated); return redirect()->route('posts.index'); }}
Eloquent Models
Defining relationships and running queries.
php
// app/Models/Post.phpclass Post extends Model{ protected $fillable = ['title', 'body', 'user_id']; public function author() { return $this->belongsTo(User::class, 'user_id'); } public function comments() { return $this->hasMany(Comment::class); }}// Query examplesPost::where('published', true)->orderBy('created_at', 'desc')->get();Post::find(1);Post::create(['title' => 'Hello', 'body' => 'World']);$post->comments()->create(['body' => 'Nice!']);
Core Laravel Concepts
Key building blocks every Laravel app relies on.
- Blade- Laravel's templating engine; files end in .blade.php and use {{ $var }} plus @if/@foreach directives
- Middleware- Filters HTTP requests, e.g. auth and throttle; registered in app/Http/Kernel.php and applied via ->middleware('auth')
- Migrations- Version-controlled schema changes in database/migrations/, run with php artisan migrate
- Service Container- Laravel's IoC container that resolves class dependencies automatically via type-hinting
- Eloquent ORM- ActiveRecord-style ORM mapping model classes to database tables by convention (Post maps to posts)
- .env / config- Environment-specific settings loaded from .env and accessed via the config() or env() helpers
Pro Tip
Always mass-assign through $fillable (or $guarded) on Eloquent models — leaving both empty and calling create() with raw request input opens mass-assignment vulnerabilities.
Was this cheat sheet helpful?
Explore Topics
#PHPLaravelBasics#PHPLaravelBasicsCheatSheet#Programming#Beginner#ArtisanCLI#RoutesControllers#EloquentModels#CoreLaravelConcepts#CommandLine#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance