عرض ادب بنده در بخش درگاه پرداخت با این ارور مواجه شدم منظورشو متوجه نمی شم؟
Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 1364 Field 'order_id' doesn't have a default value (SQL: insert into `payments` (`status`, `updated_at`, `created_at`) values (1, 2021-07-04 15:03:02, 2021-07-04 15:03:02))
http://localhost:8000/payment/callback?clientrefid=CnBiKli3IQsvqv7I&refid=70016622541
ربطی به مدل و فیل ایبل نداره؟
شاید پاسخ شما همینجا باشد
مهندسین عزیز @ajdar9667
من یه دستوری دادم که در صورت موفقیت آمیز بودن این بخش اجراشود
$payment->orders()->create([
'status'=>'paid'
]);
و ارور مربوط به کد بالاست. و این مایگریشن و مدل payment
Schema::create('payments', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('order_id');
$table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');
$table->boolean('status')->default(0);
$table->string('resnumber');
$table->timestamps();
});
class Payment extends Model
{
protected $fillable=['status','resnumber'];
use HasFactory;
public function orders(){
return $this->belongsTo(Order::class);
}
}
اینم مایگریشن و مدل order
Schema::create('orders', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->bigInteger('price');
$table->enum('status',['unpaid','paid','preparation','posted','received','cancel']);
$table->string('serials')->nullable();
$table->timestamps();
});
class Order extends Model
{
use HasFactory;
protected $fillable=['price','serials','status'];
public function payment(){
return $this->hasMany(Payment::class);
}
```خیلی ممنون میشم راهنماییم کنید🙏@rezajahangir مهندس عزیز این کارم کردم اما همون ارور یعنی
Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 1364 Field 'order_id' doesn't have a default value (SQL: insert into `payments` (`status`, `updated_at`, `created_at`) values (1, 2021-07-04 21:12:22, 2021-07-04 21:12:22))
میاد. مثل کد استاد موسوی میزنم اما نمی دونم مشکل چیه
شما یه جا داری اشتباه میکنی، مایگریشن payments رو به صورت زیر بنویس.
Schema::create('payments', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
$table->boolean('status')->default(0);
$table->string('resnumber');
$table->timestamps();
});
مدل Payment هم باید به صورت زیر تغییر کنه.
protected $fillable=['user_id', 'status', 'resnumber'];@rezajahangir @ajdar9667 @ali.bayat متوجه ایراد کار شدم
$payment->orders()->create([
'status'=>'paid'
]);
به جای create باید update می گذاشتم 😭
دست بوس تک تکتونم خیلی ممنون از وقتی گرانبهایی که گذاشتید 🙏🙏🙏🙏یه دنیا ممنون.بازم معذرت می خوام