-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created user activity model to track user activities across the website
- Loading branch information
1 parent
af3fe62
commit 7fec85c
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
class UserActivity extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
'user_id', | ||
'activity', | ||
'description', | ||
'device', | ||
'browser', | ||
'ip', | ||
'user_agent', | ||
]; | ||
|
||
/** | ||
* Get the user that owns the activity. | ||
*/ | ||
public function user(): BelongsTo | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\UserActivity; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class UserActivityFactory extends Factory | ||
{ | ||
protected $model = UserActivity::class; | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
|
||
]; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
database/migrations/2024_06_24_084544_create_user_activities_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('user_activities', function (Blueprint $table) { | ||
$table->id(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('user_activities'); | ||
} | ||
}; |