kely пре 9 месеци
родитељ
комит
f52afb179f
2 измењених фајлова са 7 додато и 1 уклоњено
  1. 2 1
      app/Http/Controllers/API/AssetController.php
  2. 5 0
      app/Models/Asset.php

+ 2 - 1
app/Http/Controllers/API/AssetController.php

@@ -25,6 +25,7 @@ class AssetController extends Controller
     public function index(Request $request)
     {
         $fullAsset=[];
+        $sort=$request->input('sort','desc');
         $paths = Asset::filter($request->all())
             ->where('company_id',Auth::user()->company_id)
             ->allowed()->pluck('path')->toArray();
@@ -34,7 +35,7 @@ class AssetController extends Controller
                 $fullAsset=  array_merge($parentAssets,$fullAsset);
             }
 
-        $resultAssets = Asset::whereIn('id', $fullAsset)->get()->each(function ($asset) {
+        $resultAssets = Asset::whereIn('id', $fullAsset)->orderBy('created_at',$sort)->get()->each(function ($asset) {
             $asset->requirement_total = $asset->total_requirements_count;
             $asset->plan_total = $asset->total_plans_count;
         });

+ 5 - 0
app/Models/Asset.php

@@ -24,6 +24,11 @@ class Asset extends Model
         "equity_interest","developer","date_completed","total_floor_area","contact_person","contact_phone","contact_email","property","building_type_description"
     ];
 
+    protected $casts = [
+        'created_at' => 'datetime:Y-m-d H:i:s',
+        'updated_at' => 'datetime:Y-m-d H:i:s',
+    ];
+
     protected static function booted(): void
     {
         static::addGlobalScope(new CompanyScope);