1. Installation
composer create-project --prefer-dist laravel/laravel project-name
2. Directory Structure
app/
config/
database/
public/
resources/
routes/
storage/
tests/
vendor/
3. Routing
Route::get('/', function () {
return view('welcome');
});
4. Controllers
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class MyController extends Controller
{
public function index()
{
return view('my-view');
}
}
5. Views
// resources/views/my-view.blade.php
<h1>Hello, World!</h1>
6. Blade Templates
// resources/views/my-view.blade.php
<h1>{{ $title }}</h1>
7. Models
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class MyModel extends Model
{
protected $fillable = ['name', 'email'];
}
8. Migrations
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateMyTable extends Migration
{
public function up()
{
Schema::create('my_table', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('my_table');
}
}
9. Eloquent
use App\Models\MyModel;
$myModel = MyModel::find(1);
echo $myModel->name;
10. Validation
use Illuminate\Support\Facades\Validator;
$validator = Validator::make($request->all(), [
'name' => 'required',
'email' => 'required|email',
]);
11. Authentication
use Illuminate\Support\Facades\Auth;
Auth::login($user);
12. Authorization
use Illuminate\Support\Facades\Gate;
Gate::define('my-gate', function ($user) {
return $user->isAdmin();
});
13. Middleware
use Illuminate\Support\Facades\Route;
Route::get('/my-route', function () {
// ...
})->middleware('my-middleware');
14. Events
use Illuminate\Support\Facades\Event;
Event::listen('my-event', function ($data) {
// ...
});
15. Jobs
use Illuminate\Support\Facades\Bus;
Bus::dispatch(new MyJob());
16. Notifications
use Illuminate\Support\Facades\Notification;
Notification::send($user, new MyNotification());
17. Cache
use Illuminate\Support\Facades\Cache;
Cache::put('my-key', 'my-value');
18. Sessions
use Illuminate\Support\Facades\Session;
Session::put('my-key', 'my-value');
19. Cookies
use Illuminate\Support\Facades\Cookie;
Cookie::make('my-key', 'my-value');
20. Filesystem
use Illuminate\Support\Facades\Storage;
Storage::disk('local')->put('my-file.txt', 'my-content');
21. Database
use Illuminate\Support\Facades\DB;
DB::table('my_table')->insert(['name' => 'John', 'email' => 'john@example.com']);
22. Query Builder
use Illuminate\Support\Facades\DB;
DB::table('my_table')->where('name', 'John')->first();
23. Eloquent Relationships
use App\Models\MyModel;
class MyModel extends Model
{
public function myRelationship()
{
return $this->hasMany(MyRelatedModel::class);
}
}
24. API Routes
use Illuminate\Support\Facades\Route;
Route::apiResource('users', 'UserController');
// routes/api.php
Route::get('/users', 'User Controller@index');
Route::post('/users', 'User Controller@store');
25. Resource Controllers
use Illuminate\Support\Facades\Route;
Route::resource('users', 'User Controller');
26. Form Requests
use App\Http\Requests\MyRequest;
public function store(MyRequest $request)
{
// Validation is automatically handled
}
27. Localization
// resources/lang/en/messages.php
return [
'welcome' => 'Welcome to our application!',
];
28. Testing
use Tests\TestCase;
class ExampleTest extends TestCase
{
public function testBasicTest()
{
$this->assertTrue(true);
}
}
29. Debugging
use Illuminate\Support\Facades\Log;
Log::info('This is a log message');
30. Environment Variables
$envValue = env('MY_ENV_VARIABLE');
31. Configuration
$configValue = config('app.name');
32. Service Providers
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class MyServiceProvider extends ServiceProvider
{
public function register()
{
// Register services
}
}
33. Facades
use Illuminate\Support\Facades\Cache;
Cache::get('my-key');
34. Custom Artisan Commands
namespace App\Console\Commands;
use Illuminate\Console\Command;
class MyCommand extends Command
{
protected $signature = 'my:command';
public function handle()
{
$this->info('Command executed!');
}
}
35. Middleware Parameters
Route::get('/my-route', function () {
// ...
})->middleware('my-middleware:param1,param2');
36. Custom Validation Rules
use Illuminate\Contracts\Validation\Rule;
class MyCustomRule implements Rule
{
public function passes($attribute, $value)
{
return $value === 'valid';
}
public function message()
{
return 'The :attribute is invalid.';
}
}
37. Blade Components
// resources/views/components/my-component.blade.php
<div>This is my component</div>
38. Blade Slots
// resources/views/components/my-component.blade.php
<div>{{ $slot }}</div>
39. Blade Conditionals
@if($condition)
<p>Condition is true</p>
@else
<p>Condition is false</p>
@endif
40. Blade Loops
@foreach($items as $item)
<p>{{ $item }}</p>
@endforeach
41. Blade Includes
@include('partials.header')
42. Blade Extends
@extends('layouts.app')
43. Blade Yield
@section('content')
<p>This is the content section.</p>
@endsection
44. Route Parameters
Route::get('/user/{id}', function ($id) {
return 'User ' . $id;
});
45. Route Groups
Route::group(['prefix' => 'admin'], function () {
Route::get('/users', 'Admin\UserController@index');
});
46. Route Middleware
Route::get('/dashboard', 'DashboardController@index')->middleware('auth');
47. CSRF Protection
<form method="POST" action="/submit">
@csrf
<input type="text" name="name">
<button type="submit">Submit</button>
</form>
48. File Uploads
$request ->file('my_file')->store('uploads'); // Handle file upload
49. Sending Emails
use Illuminate\Support\Facades\Mail;
Mail::to('recipient@example.com')->send(new MyMailable());
50. Queues
use Illuminate\Support\Facades\Queue;
Queue::push(new MyJob());
51. Broadcasting
use Illuminate\Support\Facades\Broadcast;
Broadcast::channel('my-channel', function ($user) {
return true; // Authorize user
});
52. Caching
use Illuminate\Support\Facades\Cache;
Cache::remember('my-key', 60, function () {
return 'my-value';
});
53. Rate Limiting
use Illuminate\Support\Facades\RateLimiter;
RateLimiter::hit('my-key');
54. Custom Exception Handling
namespace App\Exceptions;
use Exception;
class MyCustomException extends Exception
{
// Custom exception logic
}
55. API Resources
use Illuminate\Http\Resources\Json\JsonResource;
class UserResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
];
}
}
56. Form Validation
$request->validate([
'name' => 'required|string|max:255',
'email' => 'required|email',
]);
57. Custom Middleware
namespace App\Http\Middleware;
use Closure;
class MyMiddleware
{
public function handle($request, Closure $next)
{
// Middleware logic
return $next($request);
}
}
58. Service Container
app()->make(MyClass::class);
59. Dependency Injection
public function __construct(MyService $service)
{
$this->service = $service;
}
60. Configuration Caching
php artisan config:cache
61. Route Caching
php artisan route:cache
62. View Caching
php artisan view:cache
63. Database Seeding
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
public function run()
{
$this->call(MyTableSeeder::class);
}
}
64. Database Factories
use App\Models\User;
User ::factory()->create();
65. Soft Deletes
use Illuminate\Database\Eloquent\SoftDeletes;
class MyModel extends Model
{
use SoftDeletes;
}
66. Accessors
public function getFullNameAttribute()
{
return $this->first_name . ' ' . $this->last_name;
}
67. Mutators
public function setNameAttribute($value)
{
$this->attributes['name'] = strtolower($value);
}
68. Events and Listeners
use App\Events\MyEvent;
use App\Listeners\MyListener;
Event::dispatch(new MyEvent($data));
69. Custom Artisan Commands
php artisan make:command MyCommand
70. Task Scheduling
$schedule->command('my:command')->hourly();
71. Middleware Groups
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
// ...
],
];
72. Route Model Binding
Route::get('/user/{user}', function (User $user) {
return $user;
});
73. Custom Validation Messages
$request->validate([
'name' => 'required',
], [
'name.required' => 'Name is required.',
]);
74. Blade Directives
Blade::directive('datetime', function ($expression) {
return "<?php echo ($expression)->format('Y-m-d H:i:s'); ?>";
});
75. Route Caching
php artisan route:cache
76. View Caching
php artisan view:cache
77. Database Seeding
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
public function run()
{
$this->call(MyTableSeeder::class);
}
}
78. Database Factories
use App\Models\User;
User ::factory()->create();
79. Soft Deletes
use Illuminate\Database\Eloquent\SoftDeletes;
class MyModel extends Model
{
use SoftDeletes;
}
80. Accessors
public function getFullNameAttribute()
{
return $this->first_name . ' ' . $this->last_name;
}
81. Mutators
public function setNameAttribute($value)
{
$this->attributes['name'] = strtolower($value);
}
82. Events and Listeners
use App\Events\MyEvent;
use App\Listeners\MyListener;
Event::dispatch(new MyEvent($data));
83. Custom Artisan Commands
php artisan make:command MyCommand
84. Task Scheduling
$schedule->command('my:command')->hourly();
85. Middleware Groups
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
// ...
],
];
86. Route Model Binding
Route::get('/user/{user}', function (User $user) {
return $user;
});
87. Custom Validation Messages
$request->validate([
'name' => 'required',
], [
'name.required' => 'Name is required.',
]);
88. Blade Directives
Blade::directive('datetime', function ($expression) {
return "<?php echo ($expression)->format('Y-m-d H:i:s'); ?>";
});
89. Localization
return [
'welcome' => 'Welcome to our application!',
];
90. Testing
use Tests\TestCase;
class ExampleTest extends TestCase
{
public function testBasicTest()
{
$this->assertTrue(true);
}
}
91. Debugging
use Illuminate\Support\Facades\Log;
Log::info('This is a log message');
92. Environment Variables
$envValue = env('MY_ENV_VARIABLE');
93. Configuration
$configValue = config('app.name');
94. Service Providers
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class MyServiceProvider extends ServiceProvider
{
public function register()
{
// Register services
}
}
95. Facades
use Illuminate\Support\Facades\Cache;
Cache::get('my-key');
96. Custom Artisan Commands
php artisan make:command MyCommand
97. Task Scheduling
$schedule->command('my:command')->hourly();
98. Middleware Groups
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
// ...
],
];
99. Route Model Binding
Route::get('/user/{user}', function (User $user) {
return $user;
});
100. Custom Validation Messages
$request->validate([
'name' => 'required',
], [
'name.required' => 'Name is required.',
]);