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

Laravel:Requestとは何か

0
Posted at

Controllerのこういう部分。

public function store(Request $request)

これは、Request オブジェクトを渡してください、の意味。

このRequestはHTTPリクエストを表すオブジェクトのこと。
HTTPリクエストはブラウザがサーバーに送る情報です。

  • POSTメソッドフォームの body=今日は眠い
  • GET url?date=2026-03-15 など

この手のブラウザから送られてくるデータ全部をRequestオブジェクトとしてまとめて扱う。

何が入っているのか

<form method="POST" action="/boyaku/store">
<textarea name="body"></textarea>
</form>

で、送信されたデータは body=今日は眠い
Laravelでは $request->body で取り出せる。

POST,GET

Blog::create([
    'body' => $request->body,
]);

これは、フォームの body の内容→DBの body カラムに保存するということになる。

/blog?date=2026-03-15

これもRequestに入るので、
$request->data で取得できる。

PHPとの比較

$_POST['body']
$_GET['date']

=

$request->body
$request->date

public function **(Request $request)

()の中身

  • Request 型(クラス名)
  • $request 変数名

Request型の変数 $request という意味。
PHPの関数の引数に型指定を書けることの延長。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?