LoginSignup
0
0

More than 1 year has passed since last update.

Laravelルートパラメータ解説

Posted at

ルートパラメータとはURLのパスの設定の事である。

image.png

ルーティング

<?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>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0