Laravel基本

更新日 2023-12-12 22:24:37
laravel

リソースコントローラ

コントローラ生成

php artisan make:controller PhotoController --resource
ルートの登録

Route::resource('photos', 'PhotoController');

リソースコントローラにより処理されるアクション
動詞      URI                  アクション ルート名
GET       /photos              index      photos.index
GET       /photos/create       create     photos.create
POST      /photos              store      photos.store
GET       /photos/{photo}      show       photos.show
GET       /photos/{photo}/edit edit       photos.edit
PUT/PATCH /photos/{photo}      update     photos.update
DELETE    /photos/{photo}      destroy    photos.destroy

ビュー・ブレード

layouts/app.blade.php

<html>
    <head>
        <title>アプリ名 - @yield('title')</title>
    </head>
    <body>
        @section('sidebar')
            ここがメインのサイドバー
        @show

        <div class="container">
            @yield('content')
        </div>
    </body>
</html>

child.blade.php

@extends('layouts.app')

@section('title', 'Page Title')

@section('sidebar')
    @@parent

    <p>ここはメインのサイドバーに追加される</p>
@endsection

@section('content')
    <p>ここが本文のコンテンツ</p>
@endsection

モデル生成


php artisan make:model Flight

Modelsディレクトリに作成する場合
php artisan make:model Models/Flight
マイグレーションも出力する場合

php artisan make:model Flight --migration

php artisan make:model Flight -m

マイグレーション生成


php artisan make:migration craete_companies_table --create=companies