コンテンツにスキップ

Php

  • PHP

インストール

Mac

1
brew install php

Composerは公式参照.

CakePHP

起動しようとしたときのエラー対応

You must enable the intl extension to use CakePHP

1
2
You must enable the intl extension to use CakePHP. ~~ requirements.php on line 31
Fatal error: You must enable the intl extension to use CakePHP. in C:\xampp\htdocs\my_app\config\requirements.php on line 31

解決方法: 「php.ini」にある;extension=intlを開放してXAMPP再起動.

No such file or directory ~~ index.php on line 31

自分のCakePHPアプリのディレクトリに移動してcomposer update.

An Internal Error Has Occurred.

config/app.phpのデバッグレベルを以下のように変更.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
    /*
     * Debug Level:
     *
     * Production Mode:
     * false: No error messages, errors, or warnings shown.
     *
     * Development Mode:
     * true: Errors and warnings shown.
     */
    'debug' => filter_var(env('DEBUG', true), FILTER_VALIDATE_BOOLEAN),

Security::setSalt() must be of the type string, null given, called in~~

envの第二引数に32文字指定.

1
2
3
    'Security' => [
        'salt' => env('SECURITY_SALT', 'dfc123c6c22d84f4bc12273f3df67c6ae55009696e4126b36ac2f755778faccc'),
    ],

Laravel

PHPとComposerのインストールまで済ませていること.

APIのエラー処理

Laravel Sail

OpenAPI

REPL(tinker)

1
2
3
4
php artisan tinker

$user = App\Models\User::where("id", "=", "3500")->get();
$orders = App\Models\OrderHeader::where("id", "<", "3500")->get();

起動

1
2
mysql.server start
php artisan serve

既にあるプロジェクトの導入

  • .env作成
  • データベース作成
1
2
3
4
composer install
php artisan migrate
php artisan key:generate
php artisan serve # 起動

開発環境ではhttp, 本番ではhttpsで接続

  • 参考
  • app/Providers/AppServiceProvider.phpを編集
1
2
3
4
5
6
7
8
use Illuminate\Support\Facades\URL;

    public function boot()
    {
        if (config('app.env') === 'production') {
            \URL::forceScheme('https');
        }
    }

ユーザー作成

  • php artisan tinkerを実行
  • REPLで次のように書く
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
$user = new User;
$user->name = "ユーザー名";
$user->email = "メールアドレス";
$user->password = Hash::make('パスワード');
$user->save();

$user = new User;
$user->name = "test";
$user->email = "test@phasetr.com"; # このメールアドレスは存在しない
$user->password = Hash::make('test');
$user->save();

$user = new User;$user->name = "user";$user->email = "user@phasetr.com";$user->password = Hash::make('test');$user->save();
$user = new User;$user->name = "admin";$user->email = "admin@phasetr.com";$user->password = Hash::make('test');$user->save();
$user = new User;$user->name = "shopper";$user->email = "shopper@phasetr.com";$user->password = Hash::make('test');$user->save();
1
App\Models\User::first();

認証