Home » Intermediate » Working with DateTime and format in laravel
Hello everyone, Welcome back! Here am with another interesting topic, it is about DateTime and changing the format of it in our applications.
We come across many situations where we need to use some date and also format it, and sometimes also to change the language of it.
Here we display the date in the Arabic language.
The simple approach we follow is, initially we add an item, get its actual date using PHP DateTime function, then convert its month to Arabic and finally store it in the database.
Adding data :
So a simple form is needed, to store an item along with created date, the form is as below,
{{ csrf_field() }}
ADD
ADD |
Storing data :
To store this data we create a table, in migrations up function,
public function up() { Schema::create(‘users’, function (Blueprint $table) { $table->increments(‘id’); $table->string(‘name’); $table->string(’email’)->unique(); $table->string(‘password’); $table->rememberToken(); $table->timestamps(); }); }
Schema::create(‘users’, function (Blueprint $table) { $table->increments(‘id’); $table->string(’email’)->unique(); $table->string(‘password’); |
and a model file for it,