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?

More than 3 years have passed since last update.

Laravel routes→Controller→view

Posted at

Laravel6における、routes→Controller→viewの基本的な流れをメモ。

routes

.php
Route::get('/', function () {
    return view('welcome');
});
.php
Route::get('/home', 'HomeController@index')->name('home');
Route::get('[view名](ディレクトリ/ファイル)',[Controller名]'@[method名]')->name('[リンク名をつける](controller名.method名)など');

Controller

.php
public function index()
    {
       
        //クエリビルダ

        $hoges = DB::table('log_me_events')
                ->select('id', ...)//取得したいカラム
                ->orderBy('year', 'desc')//ソートをかけたり
                ->get();//最終データベースから取得する
        
        return view('[view名](ディレクトリ.ファイル)', compact(''));

    }

view

.php

@foreach($hoges as $hoge)
  <tr>
    <td>{{$hoge->id}}</td>
    <td>{{$hoge->...}}</td>
  </tr>                                    
@endforeach

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?