اذهب إلى المحتوى
  • 0

ما الحقل الموافق لهذا الحقل CURRENT_DATE في لارافيل؟

محمود سامي حسين

السؤال

ما الحقل الموافق لهذا الحقل ؟

CURRENT_DATE في قاعدة البيانات ؟ 

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class AddExpiryDateToCouponsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('coupons', function (Blueprint $table) {
            $table->date('expiry_date')->default(DB::raw('CURRENT_DATE'));
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('coupons', function (Blueprint $table) {
            $table->date('expiry_date')->default(DB::raw('CURRENT_DATE'));
        });
    }
}
// نص الخطأ
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'current_date' at line 1 (SQL: alter table `coupons` add `expiry_date` date not null default current_date)

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 1

هناك method تدعى carbon في laravel

$table->date('expiry_date')->default(Carbon::now());

في هذا ال method يقوم بتحويل الوقت الحالي ويشبه ما يتم تخزينه في Database ، ويمكنك أيضا استخدام Carbon مع الأيام مثل :

Carbon::now();
Carbon::today();
Carbon::yesterday();

وكذلك يمكنك إستخدامها مع الوقت الزمني لدولة معينة مثل : 

Carbon::tomorrow('Europe/London');

 

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 1

في لارافل 8 يوجد عدة طرق لوضع الطابع الزمني

$table->timestamp('created_at')->useCurrent();

// للتعديل عند التحديث
$table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();

$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();

// طريقة أخرى
$table->timestamps()->default('CURRENT_TIMESTAMP');

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...