LoginSignup
0
0

More than 1 year has passed since last update.

Laravelの基礎を身につける

Last updated at Posted at 2022-10-25

概要

初心者の方向けに、Laravelの基本構造を具体的なコードを用いて理解するための記事です。

前提条件

Laravel Framework 9.35.1

Larabelの基本

LaravelとはPHPのフレームワークの1つであり、PCのブラウザで動作するWeb開発に用いられるものです。Webの仕組みの1つとして、MVCモデルというものがあります。
MVCモデルとは、ユーザーがサーバーにリクエストし、サーバーがユーザーにレスポンスをする基本的な仕組みを実現するための仕組みです。例えば、Modelであればデータベースとの役割、Viewであればユーザーに表示する役割、ControllerであればModelやViewを繋ぐ役割をしています。

Laravelにおける一連の流れ

web.php
use App\Http\Controllers\TableController;

Route::get('/', 'index')->name('index');
TableController.php
use App\Http\Controllers\TableController;

class TableController extends Controller
{
    public function index(Table $table)
    {
        return view('tables/index')->with([
            'id' => $table->getfirstid()
        ]);
    }
}
index.blade.php
$id
Table.php
public function getfirstid()
    {
        return $this->orderBy('created_at', 'ASC')->first();
    }
}

出力結果

Tableテーブルにあるレコードの一番初めのidが出力されます。

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