Change timestamps column names

Submitted by seriousfred - 9 years ago

Change the created_at, updated_at and deleted_at column names (deleted_at not working @ Laravel 4.2)

/**
 * app/models/BaseModel.php
 **/
 
class BaseModel extends Eloquent {
    
	const CREATED_AT = 'createdAt';
	const UPDATED_AT = 'updatedAt';
	const DELETED_AT = 'deletedAt';

}

/**
 * app/models/MySoftDeleTrait.php
 * (you can save this file where you like)
 **/
 
use Illuminate\Database\Eloquent\SoftDeletingTrait;
use Illuminate\Database\Eloquent\SoftDeletingScope;

trait MySoftDeleteTrait {

    use SoftDeletingTrait;


	/**
	 * Boot the soft deleting trait for a model.
	 *
	 * @return void
	 */
	public static function bootMySoftDeleteTrait()
	{
		static::addGlobalScope(new SoftDeletingScope);
	}

	/**
	 * Get the name of the "deleted at" column.
	 *
	 * @return string
	 */
	public function getDeletedAtColumn()
	{
		return static::DELETED_AT;
	}


}


/**
 * app/models/User.php
 *
 **/

use \MySoftDeleteTrait;

class User extends BaseModel {

	public    $timestamps = true;

	protected $dates      = ['deletedAt'];

	use MySoftDeleteTrait;

    /**
     * ... etc ...
     **/

}