If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.

Updates in Laravler 12
Laravel 12 officially release हो चुका है, और इस version में कई features जोड़े गए हैं। और आज हम इस blog men ऐसे कुछ major updates के बारे में बात करेंगे।
●●●
अब आप Str::of('secret')->encrypt() और .decrypt() helper methods को chained code में use कर सकते हैं — बाहरी encryption wrapper लिखने की ज़रूरत अब नहीं। official changelog के अनुसार, ये सितम्बर 2025 से Laravel 12.x में शेयर किया गया feature है।
$value = Str::of('secret')->encrypt()->prepend('Encrypted: ');
$original = Str::of($value)->decrypt();इससे string-chain and encryption logic cleaner और DRY होता है।
Why care ? string manipulation compact बनता है, boilerplate कमी और readability बढ़ जाती है।
Laravel 12 में HasUuids trait अब by default time-ordered UUID v7 generate करता है। यानी अब model IDs पहले जैसा unordered v4 नहीं होंगे।
अगर आप legacy v4 UUID चाहें, तो :
use Illuminate\Database\Eloquent\Concerns\HasVersion4Uuids as HasUuids;
लेकिन default v7 backward‑compatible और recommended है।
Laravel 12 में, यदि आपने filesystems.php में local disk define नहीं किया, तो default storage path अब storage/app/private होगा (पहले केवल storage/app था)।
इस behaviour से previously stored files को private रखना आसान होगा, और extra storage-structure flexibility मिलती है।
Laravel 12 में by default image validation अब SVG files को allow नहीं करता। SVG को allow करना हो तो आपको explicit rule use करना होगा।
'photo' => ['required', File::image(allowSvg: true)],यह default security implications और worst-case SVG exploits avoid करने के लिए implement किया गया है।
Laravel 12 Routing Documentation पर new methods और recommendations दिए गए हैं, जो developers के लिए काफी काम के हैं।
Route::get('/search/{term?}', [SearchController::class,'index'])
->defaults('term', 'laravel‑12');इससे अगर {term} URL में missing हो → 'laravel‑12' default use करेगा। Equally valid है Route::defaults([...])->group(...).
अब routes को controller के according से group करना और भी elegant हो गया है। अब controller class names को बार-बार repeat करने कि need नहीं है — DRY (Don't Repeat Yourself) और neat!
Route::controller(ProfileController::class)->group(function () {
Route::get('/profile', 'show');
Route::post('/profile', 'update');
});Laravel 12 के new structure में:
app/Http/Kernel.php अब “user‑generated” folder होता हुआ fallback है, framework officially Kernel‑based registration को remove कर देता है।
पर Laravel 12 installers अब "bootstrap/app.php" में ->withMiddleware(...) closure use करते हैं , जिसमे register, prepend, append, alias, etc method मिलते हैं।
->withMiddleware(function (Middleware $middleware) {
$middleware->append(App\Http\Middleware\EnsureAdmin::class);
$middleware->alias(['log' => SomeLogMiddleware::class]);
$middleware->prependToGroup('api', HandleCors::class);
$middleware->priority([FirstMiddleware::class, SecondMiddleware::class]);
})
अब आप controllers के अंदर directly middleware define कर सकते हो HasMiddleware interface use करके।
मतलब, पहले जहाँ middleware को separately routes या kernel में define करते थे, अब आप middleware को directly अपने controller में भी specify कर सकते हो। इससे code clean और ज़्यादा manageable हो जाता है।
use Illuminate\Routing\Controllers\HasMiddleware;
class UserController implements HasMiddleware
{
public static function middleware(): array
{
return ['auth', new Middleware('log', only: ['index'])];
}
}आप अब unnecessary HTML routes (जैसे create और edit) को easily exclude कर सकते हो जब आप apiResource use करते हो।
इससे सिर्फ वो routes ही include होते हैं जो API के लिए relevant होते हैं और HTML routes (like create/edit) generate नहीं होते। जिससे आपका code ज़्यादा clean और optimized होता है।
Route::apiResource('posts', PostController::class);Laravel 12 अब auto-detect करता है __invoke() method को, मतलब आपको routes में method name लिखने कि need नहीं है। बस controller का नाम specify करो, और Laravel automatically __invoke() method को call करेगा ।
यह feature काफी time save करता है और code को और भी concise बनाता है!
// No need to specify a method!
Route::get('/profile', ProfileController::class);
// controller
class ProfileController
{
public function __invoke()
{
return view('profile');
}
}●●●
Loading ...