The Database Operations
package provides a trait for Laravel models to handle database operations and track user activity. It automatically populates database columns and simplifies the implementation of user tracking features.
To install the Database Operations
package, follow these steps:
-
Ensure that you have Composer installed on your machine.
-
Open your terminal and navigate to your Laravel project's directory.
-
Run the following command to install the package:
composer require database-operations/common-database-operations
- After the package is installed, Laravel will automatically discover the package and register its service provider.
- Add the
DatabaseOperations
trait to the model(s) where you want to implement database operations. For example:
use Common\DatabaseOperations\Traits\CommonDatabaseOperations;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Common\DatabaseOperations\Traits\CommonDatabaseOperations;
class CreateMyTable extends Migration
{
use CommonDatabaseOperations;
public function up()
{
Schema::create('my_table', function (Blueprint $table) {
$table->id();
// Add other columns as needed
$this->addCommonDBFields($table);
});
}
// ...
}