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