LoginSignup
0
0

More than 1 year has passed since last update.

Laravel ルーティング・コントローラー組み合わせ、簡単なプロフィール

Posted at

image.png

ルーティング


<?php

Route::get('/show_profile', 'ShowProfile');

コントローラー

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;


class ShowProfile extends Controller
{
    function __invoke(){
        $title = 'プロフィール';
        $name = '山田 太郎';
        $address = '東京都港区六本木';
        $skill = '寝付きが良い';

        return view('samples.show_profile', [
            'title' => $title,
            'name' => $name,
            'address' => $address,
            'skill' => $skill,
        ]);
    }
}

レイアウトファイル

@extends('layouts.logged_in')

@section('title', $title)

@section('content')
<h1>{{ $title }}</h1>
  <dl>
      <dt>名前</dt>
      <dd>{{ $name }}</dd>
      <dt>住所</dt>
      <dd>{{ $address}}</dd>
      <dt>特技</dt>
      <dd>{{ $skill }}</dd>
    </dl>
@endsection

レイアウトファイル(ログイン後用)

@extends('layouts.default')

@section('header')
<header>
    <ul class="header_nav">
        <li>このサイトについて</li>
        <li>ユーザー設定</li>
        <li>プライバシーポリシー</li>
        <li>ログアウト</li>
    </ul>
</header>
@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