・laravel new sqlapp でプロジェクト作成
・.env内のtimeをAsia/Tokyo 言語をjaに
DB_CONNECTION=sqlsrv
DB_HOST=192.168.0.7\sql2016
DB_PORT=55037 データベース構成マネージャのネットワーク構成のipアドレスのIPALL
DB_DATABASE=DB名
DB_USERNAME=sa
DB_PASSWORD=xxxxx
・モデルの作成
php artisan make:model テーブル名s (laravelの仕様でテーブル名はSの複数)
・コントローラの作成
php artisan make:controller テーブル名Controller
・WEB.php
Route::get(‘/’,’テーブル名Controller@index’);
・テーブル名S.PHP
protected $fillable = [‘title’,’body’]; 項目名の変更許可
・テーブル名Controller.php
public function index(){ $datas = \App\co_hinmtas::all(); //dd($datas->toArray()); return view(‘テーブル名’, [‘datas’ => $datas]); //return view(‘テーブル名’)->with(‘datas’, $datas); }
・viewテーブル名.blade.php
<!DOCTYPE html><html> <head> <meta charset=”utf-8″> <title>hinmta</title> </head> <body> <ul> <?php foreach ($datas as $post):?> <?php $cd= mb_convert_encoding($post[“CD”], “UTF-8”, “AUTO”); $na = mb_convert_encoding($post[“NA”], “UTF-8”, “AUTO”); ?> <li><?php print $cd.’:’.$na; ?></li> <?php endforeach; ?> </ul> </body></html>