diff --git a/app/Http/Controllers/APIS/AuthController.php b/app/Http/Controllers/APIS/CustomerApi/AuthController.php similarity index 100% rename from app/Http/Controllers/APIS/AuthController.php rename to app/Http/Controllers/APIS/CustomerApi/AuthController.php diff --git a/app/Http/Controllers/CustomerApi/AssetController.php b/app/Http/Controllers/CustomerApi/AssetController.php new file mode 100644 index 0000000..4cfe9a5 --- /dev/null +++ b/app/Http/Controllers/CustomerApi/AssetController.php @@ -0,0 +1,11 @@ +get(); + + return response()->json($userAssetLinks); + } +} diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 8c34919..56dde53 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -9,7 +9,7 @@ class Asset extends Model { use HasFactory; - protected $table = 'assets'; + protected $table = 'assets'; protected $fillable = [ 'id', @@ -34,4 +34,10 @@ class Asset extends Model 'external_id' => 'string', 'additional_info' => 'array', ]; + + public function devices() +{ + return $this->hasMany(Device::class, 'asset_id', 'id'); +} + } diff --git a/app/Models/AssetDeviceLink.php b/app/Models/AssetDeviceLink.php deleted file mode 100644 index fd6012d..0000000 --- a/app/Models/AssetDeviceLink.php +++ /dev/null @@ -1,19 +0,0 @@ - 'array', 'device_data' => 'array', ]; + + public function asset() +{ + return $this->belongsTo(Asset::class, 'asset_id'); +} + } diff --git a/app/Models/User.php b/app/Models/User.php index 749c7b7..7a8ef45 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -45,4 +45,9 @@ class User extends Authenticatable 'password' => 'hashed', ]; } + + public function assets() +{ + return $this->hasManyThrough(Asset::class, UserAssetLink::class, 'user_id', 'id', 'id', 'asset_id'); +} } diff --git a/app/Models/UserAssetLink.php b/app/Models/UserAssetLink.php new file mode 100644 index 0000000..e41902d --- /dev/null +++ b/app/Models/UserAssetLink.php @@ -0,0 +1,28 @@ +belongsTo(User::class, 'user_id'); + } + + public function asset() + { + return $this->belongsTo(Asset::class, 'asset_id'); + } +} diff --git a/composer.lock b/composer.lock index 38af1e8..c16a2a0 100644 --- a/composer.lock +++ b/composer.lock @@ -8729,5 +8729,5 @@ "php": "^8.2" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/routes/api.php b/routes/api.php index ccc387f..fa4419a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -2,7 +2,8 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; +use App\Models\UserAssetLink; Route::get('/user', function (Request $request) { return $request->user(); -})->middleware('auth:sanctum'); +})->middleware('auth:sanctum'); \ No newline at end of file