carcleo's avatar

What i make the field into table working with Eloquent?

<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('diaries', function (Blueprint $table) {
            $table->id();     
            $table->date("Y-m-d");
            ......

The idea this

$table->date("Y-m-d");

is a field so: '2024-10-11' , only this

its correcty?

0 likes
5 replies
Shivamyadav's avatar

You can do it without specifying the format, laravel will handle it's format same as you want behind the scenes.

public function up(): void
    {
        Schema::create('diaries', function (Blueprint $table) {
            $table->id();     
            $table->date('diary_date'); // This will store a date in Y-m-d format
           
        });
    }
carcleo's avatar

@Shivamyadav how it should be at mysql?

$table->date('diary_date');

its shall be

date('Y-m-d')

?

and, what is the 'diary_date'?

carcleo's avatar

i think hhat understand; the 'diary_date ' will be the field name at mysql

Tray2's avatar

@carcleo A date field in the most common databases uses the ISO standard YYYY-MM-DD HH:MI:SS, Orcale uses their own stadard.

This

$table->date('start_date');  

creates a date column with the name start_date and if you don't care about the time, you just format it in your view.

carcleo's avatar

@Tray2 yes, its that PHP foamt date with date('Y-m-d'), and i remember this, rsrs, thank you

Please or to participate in this conversation.