Getting to Know Routing and Controllers in Laravel
How a URL finds the code that answers it, and when to reach for a controller.
C Codesakura 2分 コメント0件
目次
Every page starts with a route: a rule that connects a URL to code. In this part we write our first route and move its logic into a controller.
Your first route
Open routes/web.php and add:
Route::get('/hello', fn () => 'Hello from Laravel');Using a controller
Once the logic grows, move it into a controller so the routes file stays short.
php artisan make:controller ProductControllerRoute::get('/products', [ProductController::class, 'index']);URL parameters
The part of a URL in curly braces is passed to the controller. If it is type-hinted as a model, Laravel looks it up in the database for you.
シリーズの一部
Laravel from Scratch
コメント0件
コメントするにはログインしてください。 ログイン