1
1

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 5 years have passed since last update.

Laravel Contoller Action Routing まとめ

Posted at

① Controllerとは

・Laravelの中枢。主にルートから受け取ったデータをM(モデル)に渡してデータベースの変更や保存を受け取って、そのデータをV(ビュー)に渡して表示させる。

逆にビューで表示されたデータをC(コントローラ)に送って、モデルにデータの変更の処理を行わせる、ビューとモデルの橋渡しをする仲介役的な存在。

・コントローラ生成方法

 php artisan make:controller コントローラー名

作成後は以下の中身が生成される。

<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ProfileController extends Controller
{
    //

Actionとは

Controllerが持つ機能。正確にはControllerに実装されたメソッドのことを指す。

Action生成方法

public function add()
  {

Actionを定義してもActionとControllerが紐づいていないと機能しないままになる。
Routingを使ってこの2つを紐づけする。

Routingとは

定義されたControllerとActionを紐づける。

・Routingの役割

PCを伝ってユーザーからアクセスを受け取ったら、その処理を実行する経路を決定して、Contoroller内Actionにアクセスを渡す。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?