1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravelのコントローラー

Posted at

概要

Laravelの学習に伴って最低限の知識を整理した個人的な備忘録です。
以前の記事の続きになります。

Laravelのモデルとマイグレーション - Qiita

tinker

tinkerとはLaravelフレームワークに標準搭載されている対話シェルのこと、 Railsでいうbinding.pry的なやつ。

Laravel Tinker is a powerful REPL for the Laravel framework.
laravel/tinker - GitHub

REPLとはRead Eval Print Loopの略で入力・評価・出力のループのこと。

Laravel 標準搭載のデバッグ機能 tinker コマンドのご紹介 -Qiita

tinkerを使うには以下コマンドを入力。

php artisan tinker

tinkerを使ってデータベースにレコードを挿入してみる。

>>> $test = new App\Models\Test;
=> App\Models\Test {#3258}
>>> $test->text = "aaa";
=> "aaa"
>>> $test->save();
=> true
>>> App\Models\Test::all();
=> Illuminate\Database\Eloquent\Collection {#3981
     all: [
       App\Models\Test {#3980
         id: 1,
         text: "aaa",
         created_at: "2021-02-01 17:17:51",
         updated_at: "2021-02-01 17:17:51",
       },
     ],
   }
>>> exit
Exit:  Goodbye

tinkerから抜けたい場合はexitを入力。

コントローラー

実際にTestControllerを作成してみる。

php artisan make:controller TestController

以下実行結果。

app/Http/Controllers/TestController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
    //
}

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?