Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Add Native Timestamps method to Blueprint #52609

Closed
wants to merge 1 commit into from

Conversation

Nir-An
Copy link

@Nir-An Nir-An commented Aug 30, 2024

Introduced nativeTimestamps Method

This pull request introduces a new nativeTimestamps method that automatically adds timestamps to records using the database's native default settings for the current time.

Motivation

In the real world, the database is used in a wide variety of uses by a large number of applications Therefore, it is important to let the database update the respective time fields

Also, by allowing the database to handle default timestamps, we can avoid such errors sql errors and ensure smoother record insertion processes.

both of the 2 scenario will be with records of created_at and updated_at:
1.

$user = new \App\Models\User();
$user->name ='name';
$user->email='[email protected]';
$user->password='hashed_secret';
$user->save();
DB::table('users')
->insert([
'name'=>'name',
'email'=>'[email protected]',
'password'=>'hashed_secret'
]);

Database Migration Adjustments:

Updated database migration scripts to include created_at and updated_at columns using the timestamp method, which now optionally supports database-native defaults for timestamp fields,
adhering to Laravel's philosophy of convention over configuration.

Benefits of the Change:
Reduces Boilerplate Code: Developers no longer need to manually set created_at and updated_at fields for each record insertion, simplifying the development process.

Ensures Data Integrity: By using the database to manage timestamps, we guarantee accurate and consistent creation and modification times across all records, enhancing data reliability and consistency.

Improves Developer Experience: reduces the likelihood of errors and provides a more streamlined, efficient development workflow.

This function is not intended to change original timestamps function behavior.

Introduced nativeTimestamps method for adding timestamps with default current time settings. This complements existing timestamp methods by offering an option to use database native defaults.
@Nir-An Nir-An changed the title Add nativeTimestamps method to Blueprint [11.x] Add nativeTimestamps method to Blueprint Aug 30, 2024
@Nir-An Nir-An changed the title [11.x] Add nativeTimestamps method to Blueprint [11.x] Add Native Timestamps method to Blueprint Aug 30, 2024
@devfrey
Copy link
Contributor

devfrey commented Aug 30, 2024

See previous attempt: #52114

@Nir-An
Copy link
Author

Nir-An commented Aug 31, 2024

See previous attempt: #52114

thanks I really try to find something similar before my PR

I really like #52114 and

@taylorotwell
Given Laravel’s mission to provide an elegant and straightforward development experience,
I believe that incorporating this functionality natively could greatly enhance the developer experience and the overall ecosystem.

I understand the concerns regarding code maintenance and project scope, but I am confident that this feature aligns with Laravel’s core principles and brings meaningful benefits.

I am more than willing to further discuss this and address any concerns you might have. Alternatively, I'm open to suggestions on how we can achieve this functionality with minimal impact.

Thank you for reconsidering this proposal.
I truly appreciate your time and dedication to making Laravel such a remarkable framework.

@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants