
Datetime field in Laravel migration
Datetime field in Laravel migration
We’ll attempt to use programming in this lesson to solve the "Datetime field in Laravel migration" puzzle.
Create datetime field in Laravel using migration.You have to create a migration file after that you have to add a column using $table->dateTime('posted_at')->nullable();
code snippet. After changes in migration file you have to run php artisan migrate
command to create a datetime column type in database table.
-
Create datetime field in Laravel using migration
Create migration file using below command.
php artisan make:migration add_posted_at_column_to_posts_table --table=posts
Open created migration file under database/migrations folder and paste below code in up method.
$table->dateTime('posted_at')->nullable();
After implementation your code will look like below.
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::table('posts', function (Blueprint $table) { $table->dateTime('posted_at')->nullable(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::table('posts', function (Blueprint $table) { // }); } };
Run the below command to migrate.
php artisan migrate
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Add [name] to fillable property to allow mass assignment on [App\Models\Project]
- Attempt to read property "avatar" on null in Laravel
- How to get images from AWS s3 and display in Laravel blade
- Symlink(): No such file or directory
- Use withCount() to get total number of records with relationship
- Add class to body in laravel view
- Get Array of IDs from Eloquent Collection
- How to get database name in Laravel 9 ?
- How to pass external link in laravel blade to anchor tag
- JQuery each loop on json response after ajax in laravel
- How to get the id of last record from collection object in laravel view
- Laravel get count with where condition
- How to send ID to another page in Laravel
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- How to insert multiple rows in mysql using loop in laravel?
- Count all and get 10 records after where condition in laravel
- Redirect to previous page or url in laravel
- Convert input array to comma-separated string in laravel controller
- How to get date from created_at field in laravel
- The openssl extension is required for SSL/TLS protection but is not available
- Get latest record by created at in Laravel
- Get count of filter data, while return a small set of records
- Print last executed query in laravel
- Get all users except the followings users in overtrue laravel-follow
- How to get column names from table in Laravel