ルートパラメータとはURLのパスの設定の事である。
ルーティング
<?php
Route::get('/route_parameter/{id_01}/comments/{id_02}', 'SampleController@routeParameter');
コントローラー
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class SampleController extends Controller
{
public function routeParameter($id_011, $id_021){
return view('samples.route_parameter', [
'title' => 'ルートパラメータのサンプル',
'id_0111' => $id_011,
'id_0211' => $id_021,
]);
}
}
ビュー
@extends('layouts.default')
@section('title', $title)
@section('content')
<h1>{{ $title }}</h1>
<p>id: {{ $id_0111 }}</p>
<p>comment_id: {{ $id_0211 }}</p>
@endsection
共通レイアウトファイル
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>@yield('title')</title>
<style>
.header_nav {
display: flex;
list-style: none;
padding-left: 0;
}
.header_nav li {
margin-right: 30px;
}
</style>
</head>
<body>
@yield('header')
@yield('content')
</body>
</html>