LoginSignup
0
0

More than 5 years have passed since last update.

【Laravelメモ⑩】データベースのデータ参照

Last updated at Posted at 2017-03-11

前提

  • DBと接続可能な設定が完了しておりテーブルといくつかのデータが入っている
    • テーブル名:users
    • フィールド:idがある
  • Eloquentモデル作成済(User.php)

動作

localhost:8000/select
にアクセスするとidフィールドの値を全部表示する

設定メモ

ルーティング

web.php抜粋
Route::get('select','testController@select');

コントローラー

testController.php抜粋
    public function select(){
        $user = new User();
        $users = $user::all();
    return view('select', compact("users"));
    }

ビュー

select.blade.php
@foreach ($users as $user)
    {{ $user->id }}
@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