PHP Laravel Introduction
Route::get("/path", [ControllerName::class, "method"]); // routes/web.php
@foreach ($items as $item) {{-- Blade template --}}
{{ $item->property }}
@endforeach
$model = ModelName::find($id); // Eloquent
Laravel क्या है?
Laravel सबसे widely adopted PHP framework है, MVC pattern के आसपास बना है और expressive syntax और built-in tools के एक rich set के through developer productivity को prioritize करने के लिए जाना जाता है।
उदाहरण: What is Laravel?
<?php
// Print "Laravel: MVC-based, developer-friendly PHP framework" to the output
echo "Laravel: MVC-based, developer-friendly PHP framework";
?>
Login to try C/C++/Java/PHP code in the editor
Basic Routing
Laravel का router incoming URLs को एक single, readable routes file में specific controller methods या inline closures में map करता है, आपके application के URL structure को एक नज़र में देखना आसान रखते हुए।
उदाहरण: Basic Routing
<?php
// routes/web.php:
// Route::get('/users/{id}', [UserController::class, 'show']);
echo "Maps a URL pattern to a controller method";
?>
Login to try C/C++/Java/PHP code in the editor
Blade Templating
Blade, Laravel का templating engine, familiar-looking template syntax (जैसे @if और @foreach) को plain, cached PHP में compile कर देता है, आपको performance से समझौता किए बिना clean templates देते हुए।
उदाहरण: Blade Templating
<?php
// Blade template syntax (compiles to plain PHP):
// @if($isAdmin) <p>Admin</p> @endif
echo "@if and @foreach compile down to cached plain PHP";
?>
Login to try C/C++/Java/PHP code in the editor
Eloquent ORM
Eloquent Laravel का ActiveRecord-style ORM है, आपको database rows को PHP objects (जैसे User::find(1)->save()) की तरह query और manipulate करने देते हुए common operations के लिए raw SQL लिखने के बजाय।
उदाहरण: Eloquent ORM
<?php
// $user = User::find(1);
// $user->name = "Alice";
// $user->save();
echo "Query and manipulate rows as PHP objects instead of raw SQL";
?>
Login to try C/C++/Java/PHP code in the editor
Artisan CLI Commands
Artisan Laravel का command-line tool है, कुछ सेकंड में नए controllers, models, और migrations scaffold करने और caches clear करने या test suite चलाने जैसे maintenance tasks चलाने के लिए इस्तेमाल होता है।
उदाहरण: Artisan CLI Commands
<?php
// Run in terminal: php artisan make:controller UserController
echo "Artisan scaffolds controllers, models, and migrations";
?>
Login to try C/C++/Java/PHP code in the editor
- किसी project clone करने के बाद
composer installचलाना या.envcopy करना भूल जाना। - Blade में
{{ }}इस्तेमाल करना उस HTML के लिए जिसे escape नहीं होना चाहिए, जबकि{!! !!}raw output print करता है। - POST routes पर
webmiddleware या CSRF token भूल जाना, ताकि forms एक 419 error के साथ fail हों।
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: