mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 22:07:29 -08:00
Experimental transformers
This commit is contained in:
parent
ca2fa3dab9
commit
6d7c226acd
34
app/Http/Transformers/LocationsTransformer.php
Normal file
34
app/Http/Transformers/LocationsTransformer.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
namespace App\Http\Transformers;
|
||||
|
||||
use App\Models\Location;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class LocationsTransformer
|
||||
{
|
||||
|
||||
public function transformLocations( Collection $locations)
|
||||
{
|
||||
$locations_array = array();
|
||||
foreach ($locations as $location) {
|
||||
$locations_array[] = self::transformLocation($locations);
|
||||
}
|
||||
return $users_array;
|
||||
}
|
||||
|
||||
public function transformLocation(Location $location = null)
|
||||
{
|
||||
if ($location) {
|
||||
$locations_array[] = [
|
||||
'id' => e($location->id),
|
||||
'name' => e($location->name)
|
||||
];
|
||||
return $locations_array;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
36
app/Http/Transformers/UsersTransformer.php
Normal file
36
app/Http/Transformers/UsersTransformer.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
namespace App\Http\Transformers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class UsersTransformer
|
||||
{
|
||||
|
||||
public function transformUsers( Collection $users)
|
||||
{
|
||||
$users_array = array();
|
||||
foreach ($users as $user) {
|
||||
$users_array[] = self::transformUser($user);
|
||||
}
|
||||
return $users_array;
|
||||
}
|
||||
|
||||
public function transformUser(User $user)
|
||||
{
|
||||
$user_array[] = [
|
||||
'id' => e($user->id),
|
||||
'first_name' => e($user->first_name),
|
||||
'last_name' => e($user->last_name),
|
||||
'location' => (new LocationsTransformer)->transformLocation($user->userloc),
|
||||
'permissions' => $user->decodePermissions(),
|
||||
'created_at' => $user->created_at,
|
||||
'updated_at' => $user->updated_at,
|
||||
];
|
||||
|
||||
return $user_array;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue