GET YOUR ENVIRONMENT READY TO WELCOME LARAVEL V12

Feb 10, 2025

ุงู‡ู„ุงู‹ ุจูŠูƒูˆุง ู…ู† ุฌุฏูŠุฏ ููŠ ู…ู‚ุงู„ุฉ ู…ู‡ู…ุฉ ู„ูƒู„ ุงู„ู„ูŠ ุนุงูˆุฒ ูŠุนู…ู„ upgrade ู„ ู„ุงุฑููŠู„ 12 ๐Ÿคฉ

 

ุทุจุนุงู‹ ููŠ ุงู„ุจุฏุงูŠุฉ ูƒุฏุง Taylor Otwell ูˆุถุญ ููŠ Laracon EU ุฅู† ู„ุงุฑููŠู„ 12 ู‡ูŠุตุญู„ู‡ุง release ููŠ 24 ูุจุฑุงูŠุฑ, ูˆ ู‚ุงู„ ุฅู†ู‡ ู…ุด ู‡ูŠูƒูˆู† ููŠู‡ breaking change ุฃูˆ ุชุบูŠูŠุฑ ูƒุจูŠุฑ ู ุงู„ skeleton ุฒูŠ ู…ุง ุญุตู„ ููŠ ู„ุงุฑููŠู„ 11. ู„ู…ุง ุณู…ุนุช ุงู„ุฎุจุฑ ุฏุง ุงุชุญู…ู‘ูŽุณุช ู„ุงู† ุฏุง ู‡ูŠุดุฌุนู†ูŠ ุงุนู…ู„ upgrade ู„ู„ุจู„ูˆุฌ ุนุดุงู† ุชูƒูˆู† ุฌุงู‡ุฒุฉ ููŠ ุงุณุชู‚ุจุงู„ ุงู„ููŠุฑุฌู† ุงู„ุฌุฏูŠุฏ ๐Ÿ‘จ‍๐Ÿ’ป

 

ูˆ ูุนู„ุงู‹ ุนู…ู„ุช ุงู„ upgrade ุฏุง ูˆ ู‚ุฑุฑุช ุฃู†ุดุฑ ู…ู‚ุงู„ุฉ ุนุดุงู† ุงู‚ูˆู„ ุนู„ูŠ ุงู„ุฎุทูˆุงุช ุงู„ู„ูŠ ุนู…ู„ุชู‡ุง ููŠ ุงู„ upgrade ๐Ÿค

 

ุฃูˆู„ ุญุงุฌุฉ ุนู…ู„ุชู‡ุง ู‡ูŠ ุฅู†ูŠ ู†ู‚ู„ุช ูƒู„ ุงู„ุญุงุฌุงุช ุงู„ู„ูŠ ู…ุด ู‡ุชุชุงุซุฑ ู…ู† ููŠุฑุฌู† ู„ู„ุชุงู†ูŠ ุฒูŠ ุงู„ Actions ูˆ ุงู„ Repositories ูˆ ุงู„ Contracts ูˆ ู…ู…ูƒู† ุชู†ู‚ู„ ุงู„ Requests ูˆ ุงู„ Mails ูˆ ุงู„ Jobs ู„ุงู† ุงู„ุชุบูŠูŠุฑ ููŠู‡ู… ุจุณูŠุท ุฌุฏุงู‹ ๐Ÿ˜Ž

 

ู†ูŠุฌูŠ ุจู‚ุง ู„ู„ุฌุฒุก ุงู„ุฎุงุต ุจุงู„ routes ูˆ ุงู„ middlewares ู„ุงู† ุฏูˆู„ ููŠู‡ู… ุดุบู„ ูƒุชูŠุฑ, ุฏู„ูˆู‚ุชูŠ ุชุนุงู„ูˆุง ู†ูุชุญ ุงู„ bootstrap/app.php ู„ุงู† ุฏุง ุงู„ู„ูŠ ู‡ู†ุนุฑู‘ู ููŠู‡ ู…ูƒุงู† ุงู„ routes ุจุชุงุนุชู†ุง

 

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: [
            __DIR__ . '/../routes/web.php',
            __DIR__ . '/../routes/dashboard.php',
        ],
        api: __DIR__ . '/../routes/api.php'
    )
    ->withMiddleware(function (Middleware $middleware) {
        //
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();

 

ู„ูˆ ุญุฐูุช ู…ูŠุซูˆุฏ ุงู„ withMiddleware ู‡ูŠุถุฑุจ ุงูƒุณุจุดู† ู…ุนุงูƒ.

 

ุฒูŠ ู…ุง ูˆุงุถุญ ููŠ ุงู„ูƒูˆุฏ ุฏุง, ุฅู†ูƒ ู…ู…ูƒู† ุชู…ุฑุฑ array ุจ ู…ูƒุงู† ุงู„ route files ูˆ ู„ูˆ ุนู†ุฏูƒ ูุงูŠู„ ูˆุงุญุฏ ู…ู…ูƒู† ุชูƒุชุจ string ุนุงุฏูŠ, ูˆ ู‡ูƒุฐุง ุจุงู„ู†ุณุจุฉ ู„ู„ API route files, ุทุจุนุงู‹ ุฏุง ู‡ูŠุฎู„ูŠ ุงู„ route file ุจุชุงุนูƒ ุดูƒู„ู‡ ูƒุฏุง ู…ุซู„ุงู‹ ๐Ÿ™„

 

Route::middleware('auth')
    ->prefix('cats')
    ->name('cats.')
    ->controller(CatController::class)
    ->group(function () {
        //
    });

 

ุงู„ุทุฑูŠู‚ุฉ ุงู„ู„ูŠ ุฌุงูŠุฉ ุฏูŠ ู‡ูŠ ุงู„ู„ูŠ ุงุณุชุฎุฏู…ุชู‡ุง ูˆ ู…ุด ู‡ุชุชุนุจูƒ ู„ุงู†ูƒ ู‡ุชู†ู‚ู„ ุงู„ูƒูˆุฏ ุงู„ู„ูŠ ููŠ ุงู„ RouteServiceProvider ูˆ ุงู„ route file ู…ุด ู‡ูŠูƒูˆู† ุฒูŠ ุงู„ู„ูŠ ูุงุช

 

use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        api: __DIR__ . '/../routes/api.php',
        then: function () {
            Route::middleware(['web', 'throttle:preventDDOS'])
                ->prefix('admin')
                ->name('admin.')
                ->group(base_path('routes/dashboard.php'));

            Route::middleware(['web', 'throttle:preventDDOS'])
                ->name('blog.')
                ->group(base_path('routes/web.php'));
        }
    )
    ->withMiddleware(function (Middleware $middleware) {
        //
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();

 

ููŠ ุงู„ุดูƒู„ ุฏุง ู…ุฑุฑู†ุง closure ู„ู„ then argument, ูˆ ู‡ุชู„ุงุญุธ ุฅู†ูŠ ู…ุณุชุญุฏู… throttle ูˆ ุนุดุงู† ุชุนู…ู„ register ู„ู„ throttle ููŠ ุงู„ููŠุฑุฌู† ุงู„ุฌุฏูŠุฏ ู‡ุชุฑูˆุญ ู„ู„ AppServiceProvider ูˆ ุชูƒุชุจ ุงู„ูƒูˆุฏ ุฏุง

 

use Illuminate\Http\Request;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        RateLimiter::for('preventDDOS', function (Request $request) {
            return auth()->check() ? 
                Limit::none() : Limit::perMinute(60)->by($request->ip());
        });
    }
}

 

ุฏูŠ ู…ู‚ุงู„ุฉ ุงุชูƒู„ู…ุช ููŠู‡ุง ุนู† ุงู„ RateLimiter ุจุฅุณุชูุงุถุฉ.

 

ูˆ ุจูƒุฏุง ุงูƒูˆู† ุฎู„ุตุช ูƒู„ ุญุงุฌุฉ ุชุฎุต ุงู„ routes. ุชุนุงู„ูˆุง ุจู‚ุง ู†ุดูˆู ุงู„ middlewares ู‡ู†ู„ุงู‚ูŠ ุฅู† ู…ุด ู…ูˆุฌูˆุฏ ุงูŠ middleware, ุฒูŠ ู…ุซู„ุงู‹ ุงู„ู„ูŠ ุจูŠุนู…ู„ redirect ู„ู„ูŠูˆุฒุฑ ู„ูˆ ูƒุงู† auth ุฃูˆ guest ูˆ ุฏุง ู„ุงู† ุชู… ุฅุณุชุจุฏุงู„ู‡ู… ุจู…ูŠุซูˆุฏุฒ...ุงูŠูˆุงุง ุฒูŠ ู…ุง ู‚ุฑุฃุช ูƒุฏุง, ุชู… ุฅุณุชุจุฏุงู„ู‡ู… ูƒู„ู‡ู… ุจ ู…ูŠุซูˆุฏุฒ! ๐Ÿคฏ

 

ุชุนุงู„ูˆุง ู†ุดูˆู ุจุนุถ ุงู„ู…ูŠุซูˆุฏุฒ ุฏูŠ ูˆ ุฅุฒุงูŠ ู‡ู†ุณุชุฎุฏู…ู‡ุง

 

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
       ...
    )
    ->withMiddleware(function (Middleware $middleware) {
        $middleware
            ->redirectGuestsTo('/admin/login')
            ->redirectUsersTo('/admin');
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();

 

ู…ูŠุซูˆุฏ redirectGuestsTo ู‡ูŠ ุชุนุชุจุฑ ุจุฏูŠู„ ู„ู„ Authenticate middleware ูˆ ู…ูŠุซูˆุฏ redirectUsersTo ู‡ูŠ ุชุนุชุจุฑ ุจุฏูŠู„ ู„ู„ RedirectIfAuthenticate middleware ูˆ ุฒูŠ ู…ุง ุงู†ุช ุดุงูŠู ุจุชู…ุฑุฑ ุงู„ู…ุณุงุฑ ุงู„ู„ูŠ ุนุงูˆุฒู‡ ุฃูˆ ู…ู…ูƒู† ุชู…ุฑุฑ closure ูƒู…ุงู† ๐Ÿ˜‰

 

ู‡ุชู„ุงู‚ูŠ ู‡ู†ุง ุทุฑู‚ ุงุณุชุฎุฏุงู… ุงู„ methods ุฏูŠ.

 

ุฃู…ุง ุนู† ุฌุฒุก ุงู„ุฅูƒุณุจุดู†ุฒ, ู„ูˆ ุฅู†ุช ุนุงูŠุฒ ุชุนู…ู„ overwrite ุนู„ูŠ ุงู„ุฅูƒุณุจุดู†ุฒ ุงู„ุฎุงุตุฉ ุจ ู„ุงุฑููŠู„ ุฒูŠ ุงู„ NOT FOUND ุฅูƒุณุจุดู†, ู‡ุชูƒุชุจ ุงู„ูƒูˆุฏ ุงู„ู„ูŠ ุฌุงูŠ ุฏุง

 

use Illuminate\Foundation\Application;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
       ...
    )
    ->withMiddleware(function (Middleware $middleware) {
       ...
    })
    ->withExceptions(function (Exceptions $exceptions) {
        $exceptions->respond(function (Response $response) {
            return CustomExceptionClass::render($response);
        });
    })->create();

 

ุทุจุนุงู‹ ุงู„ render ู…ูŠุซูˆุฏ ุงู„ู…ูุฑูˆุถ ู‡ุชุฑุฌุน ุงู„ custom view ุจุชุงุนูƒ ุฒูŠ ูƒุฏุง ๐Ÿ’†‍โ™‚๏ธ

 

namespace App\Exceptions;

class CustomExceptionClass
{
    /*
     * Render the exception into an HTTP response.
     */
    public static function render($response)
    {
        $statusCode = $response->getStatusCode();

        if (($statusCode >= 200 && $statusCode < 400) || request()->ajax()) {
            return $response;
        }

        $message = array_key_exists($statusCode, $response::$statusTexts) ?
            $response::$statusTexts[$statusCode] : $statusCode;

        return response()->view('your-custom-view', [
            'statusCode' => $statusCode,
            'message'    => $message,
        ], $statusCode);
    }
}

 

ุญุงุจุจ ุงูˆุถุญู„ูƒ ุฅู† ู„ุงุฑููŠู„ ู…ุด ู‡ุชุฑูˆุญ ู„ู„ูƒู„ุงุณ ุฏุง ููŠ ุญุงู„ุฉ ุงู„ุฅูƒุณุจุดู†ุฒ ุจุณ, ู‡ุชุฑูˆุญ ููŠ ุญุงู„ุฉ ุงู„ redirect request ูƒู…ุงู† (ู…ุซู„ุงู‹) ุนุดุงู† ูƒุฏุง ุถูุช ุงู„ูƒูˆู†ุฏุดู† ุงู„ู„ูŠ ููŠ ุงู„ุงูˆู„ ุฏุง.

 

ุฏุง ู…ุซุงู„ ู…ู† ู„ุงุฑููŠู„ ุจูŠูˆุถุญ ุฅุฒุงูŠ ุชุนู…ู„ ูƒุฏุง ุจุดูƒู„ ู…ููุตู„ ุงูƒุชุฑ.

 

ูƒุฏุง ุชูƒูˆู† ุนู…ู„ุช upgrade ุจุดูƒู„ ุตุญูŠุญ ุงู† ุดุงุก ุงู„ู„ู‡ ูˆ ู…ุณุชุนุฏ ู„ุฅุณุชู‚ุจุงู„ ู„ุงุฑููŠู„ 12 โŒ›

ูˆ ุฏู„ูˆู‚ุชูŠ ุฌู‡ ูˆู‚ุช ุงู„ุฌู…ู„ุฉ ุงู„ุดู‡ูŠุฑุฉ ุจุชุงุนุชู†ุง...ูˆ ุจูƒุฏุง ุฃูƒูˆู† ุฎู„ุตุช ูˆ ุฃุชู…ู†ูŠ ุชูƒูˆู† ุฅุณุชูุฏุช โœ”


AI Assistant

Choose AI provider

Text Tools

Make content clear and easy to read

Ask a Question

Get clear answers based on this content

0/500
Mahmoud Ramadan

Mahmoud Ramadan

Mahmoud is the creator of Digging Code and a contributor to Laravel since 2020.