前提
店舗新規データを作成するときにuuidを生成して一緒にデータ登録する流れを作っています。
ローカルでは問題なく機能していたのに、サーバーに上げたら新規データを登録できません
実現したいこと
ローカルサイドで出来ていたように、uuidを生成して新しいデータを登録したい
発生している問題
サーバーサイドでは新規データ登録画面で登録しても、テーブルに登録されない
該当のソースコード
php
1/**お店登録 */ 2Route::post('/guest/create', [\App\Http\Controllers\GuestController::class, 'uuid'])->middleware('auth:admin')->name('guest.uuid');
php
1/*UUID生成*/ 2public function uuid (Request $request){ 3 4 5 $validate = $request->validate([ 6 'type' => ['required', 'string', 'max:255'], 7 'name' => ['required', 'string', 'max:255'], 8 'name_kana' => ['required', 'string', 'max:255'], 9 'code' => ['required', 'string', 'max:255'], 10 'tel' => ['required','numeric','digits_between:10,11'], 11 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 12 ]); 13 14 $store= new Store; 15 $store->type = $request->type; 16 $store->name =$request->name; 17 $store->name_kana =$request->name_kana; 18 $store->code = $request->code; 19 $store->tel = $request->tel; 20 $store->email = $request->email; 21 $store->uuid =(string) Str::uuid(); 22 $store->save(); 23 24 25 return view ('/guest/list'); 26 }
php
1<?php 2 3use Illuminate\Database\Migrations\Migration; 4use Illuminate\Database\Schema\Blueprint; 5use Illuminate\Support\Facades\Schema; 6 7class CreateStoresTable extends Migration 8{ 9 /** 10 * Run the migrations. 11 * 12 * @return void 13 */ 14 public function up() 15 { 16 Schema::create('stores', function (Blueprint $table) { 17 $table->id(); 18 $table->string('name')->unique(); 19 $table->string('name_kana')->unique(); 20 $table->string('email')->unique(); 21 $table->string('tel')->unique(); 22 $table->string('point')->default(0); 23 $table->string('image')->nullable(); 24 $table->string('code'); 25 $table->string('type')->default(1)->index(); 26 $table->string('uuid')->unique(); 27 $table->timestamps(); 28 }); 29 } 30 31 /** 32 * Reverse the migrations. 33 * 34 * @return void 35 */ 36 public function down() 37 { 38 Schema::dropIfExists('stores'); 39 } 40} 41
php
1<?php 2 3namespace App\Models; 4 5use Illuminate\Database\Eloquent\Factories\HasFactory; 6use Illuminate\Database\Eloquent\Model; 7 8class Store extends Model 9{ 10 use HasFactory; 11 /** 12 * The attributes that are mass assignable. 13 * 14 * @var array<int, string> 15 */ 16 protected $fillable = [ 17 'name','uuid','tel','name_kana','email','image','type','code' 18 ]; 19} 20
php
1 <form method="POST" action="{{ route('guest.create') }}"> 2 @csrf 3 <div> 4 <label for="name">店舗名</label> 5 <input type="text" id="name" name="name"> 6 </div> 7 <div> 8 <label for="name">クーポンタイプ</label> 9 <input type="text" id="type" name="type"> 10 </div> 11 <div> 12 <label for="name_kana">かな</label> 13 <input type="text" id="name_kana" name="name_kana"> 14 </div> 15 <div> 16 <label for="tel">電話番号</label> 17 <input type="text" id="tel" name="tel"> 18 </div> 19 <div> 20 <label for="email">email</label> 21 <input type="text" id="email" name="email"> 22 </div> 23 <div> 24 <label for="email">5桁コード</label> 25 <input type="text" id="code" name="code"> 26 </div> 27 <div class="store"> 28 <label for="image" class="col-md-4 col-form-label text-md-end">{{ __('プロフィール写真') }}</label> 29 <input type="file" name="image" id="image" class="form-control"> 30 </div> 31 <div> 32 <button type="submit">UUID生成</button> 33 </div> 34 </form> 35</body>
試したこと
- サーバーサイドにuuidをインストール
- テーブルが間違っていってないかとmysqlにデータを挿入すると、きちんとそのデータはリストページに表示される
補足情報(FW/ツールのバージョンなど)
laravel8
回答1件