laravel timestamps code example

Example 1: laravel current timestamp

use Carbon\Carbon;
$current_date_time = Carbon::now()->toDateTimeString(); // Produces something like "2019-03-11 12:25:00"

Example 2: laravel property

// Create a new user in the database...
$user = User::create(array('name' => 'John'));

// Retrieve the user by the attributes, or create it if it doesn't exist...
$user = User::firstOrCreate(array('name' => 'John'));

// Retrieve the user by the attributes, or instantiate a new instance...ddd
$user = User::firstOrNew(array('name' => 'John'));

Example 3: laravel property

// Create a new user in the database...dddd
$user = User::create(array('name' => 'John'));

// Retrieve the user by the attributes, or create it if it doesn't exist...
$user = User::firstOrCreate(array('name' => 'John'));

// Retrieve the user by the attributes, or instantiate a new instance...
$user = User::firstOrNew(array('name' => 'John'));

Example 4: timestamp in model laravel

$user = User::find(1);
$user->profile_views_count = 123;
$user->timestamps = false;
$user->save();

Tags:

Php Example