0
1

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の初期設定

Last updated at Posted at 2021-06-24

config/app.php

  • アプリケーションの設定ファイル
'timezone' => 'Asia/Tokyo',

'locale' => 'ja',

app/Http/MiddleWare/TrustProxies.php

AWS上で正しく動作させるファイル

protected $proxies = '*'; // 全てのプロクシを信頼する。

データベースの作成

phpMyAdminからlaravel_diary_developmentを作成。
作成の際の照合順序はutf8mb4_unicode_ciを選択する。

データベースの動作確認

php artisan migrate

エラーメッセージの日本語化

インストーラをダウンロード

php -r "copy('https://readouble.com/laravel/6.x/ja/install-ja-lang-files.php', 'install-ja-lang.php');"

resources/langフォルダにjaフォルダを追加

php -f install-ja-lang.php

ルーティング


<?php

Route::get('/model_sample', 'SampleController@modelSample');

Route::get('/messages', 'MessageController@index');

Route::post('/messages', 'MessageController@store');

コントローラー

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;

// Messageモデルをインポート
use App\Message;

class SampleController extends Controller{
  
      public function modelSample(){
      // Messageモデルを利用してid:1のmessageを取得
      $message = Message::find(2);
      return view('samples.model_sample', [
        'title' => 'モデルの使いかた',
        'message' => $message,
      ]);
    }

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?