artisanコマンドなど使用頻度の高い基本をまとめてみました。
基本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | ---環境--- php 7.4.1 Mysql Ver 15.1 Distrib 10.4.11-MariaDB Laravel 7.23.0 composer 1.10.9 ---接続--- php artisan serve //ローカルに接続 ---オートロード--- composer dump-autoload //オートでロードする(自動読込) ---キャッシュをクリア--- php artisan config:clear //キャッシュをクリアする ---新規プロジュクトを作成--- composer create-project laravel/laravel newProject //(htdocsに作成) ---migration--- php artisan migrate //定義付テーブルをデータベースに作成 php artisan make:migration create_test_table --table=users //新規 php artisan make:migration add_col_table --table=users //追加 php artisan make:migration change_test_table --table=users //変更 php artisan migrate:refresh //テーブルの中身を消去 php artisan migrate:reset //テーブル消去 php artisan migrate:rollback //戻す php artisan migrate:rollback --step=5 //ロールバック回数指定 php artisan migrate:status migration //ファイルの確認 ---seeder--- php artisan make:seeder SampleSeeder php artisan db:seed --class=DatabaseSeeder //クラス名を指定して実行でDBにデータが挿入される(実行するためのファイル) ---route--- php artisan route:list ---contoroller--- php artisan make:controller BbsController php artisan make:model Models/User Models //配下にUserモデルを作成 ---model--- php artisan make:model board ---Faker--- ---$table--- $table->dropColumn('tel'); //カラムの削除 $table->bigIncrements('id'); //自動増分ID(主キー) $table->uuid('id'); //UUIDカラム $table->unique(); //ユニーク $table->after('id') //カラムの順番 ~の後ろに追加 $table->string('name', 255); //文字長を指定したVARCHARカラム $table->char('lastname',100); //文字 $table->bigInteger('postcode'); //int $table->integer('postcode'); //int $table->text('description');TEXTカラム $table->binary('data'); //BLOBカラム $table->rememberToken(); //リメンバートークンVARCHAR(100)でNULL値可能 $table->ipAddress('ip'); //ipアドレス $table->macAddress('mac'); //macアドレス $table->timestamps(0); $table->timestampsTz(0); //タイムゾーン付き ---変更・追加・削除--- $table->string('name', 50)->change(); //サイズを25から50に変更 $table->string('name', 50)->nullable()->change(); //更にnullを可能にする $table->renameColumn('from', 'to'); //カラム名変更 $table->dropColumn('votes'); //カラム削除 $table->dropColumn(['votes', 'avatar', 'location']); //配列を使用して複数カラム削除 ---修飾子--- ->after('column') //指定カラムの次に他のカラムを設置(MySQLのみ) ->autoIncrement() //整数カラムを自動増分ID(主キー)へ設定 ->charset('utf8mb4') //ラムへキャラクタセットを指定(MySQLのみ) ---Schema--- Schema::rename($from, $to); //テーブルリネーム Schema::drop('users'); //テーブルを削除 Schema::dropIfExists('users'); //テーブルを削除 ---INSERT--- DB::table('users')->insert([ [ 'username' => 'taro', 'tel' => 09012345678, 'email' => 'taro@example.com', 'password' => Hash::make('password'), 'user_type' => 1, 'remember_token' => str_random(10), ], [ 'username' => 'hanako', 'tel' => 08012345678, 'email' => 'hanako@example.com', 'password' => Hash::make('password'), 'user_type' => 2, 'remember_token' => str_random(10), ], ]); ---login作成--- composer require laravel/ui php artisan ui vue --auth npm install && npm run dev ---bladeで使用--- @auth <p>ログインしてます。ログイン時のみ表示されます!</p> @endauth @guest <p>ログインしていません。ログインしてない時のみ表示されます!</p> @endguest @unless (Auth::check()) <p>あなたはログインしていません。</p> @endunless ---auth--- Auth::user(); Auth::id(); Auth::user()->mail; Auth::logout(); ---ターミナル、cmd--- set path=%path%;C:\xampp\mysql\bin //一時的にパスを通す mysql -u root -p |
まとめ
こちらのコマンド等は重要度の高いものがあったら、少しずつ更新していきたい思います。
以上です。