Passed
Push — master ( f56560...ff4ea0 )
by Ron
03:41
created

WorldController::getTycoons()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Worlds;
4
5
use App\Http\Controllers\Controller;
6
use App\Http\Resources\WorldResource;
7
use Illuminate\Support\Facades\Cache;
8
use Starpeace\Models\Eloquent\Common\Tycoon;
9
use Starpeace\Models\Eloquent\Common\World;
10
11
class WorldController extends Controller
12
{
13
    public function getGalaxy($galaxy_id)
14
    {
15
        header('Content-Type: application/json');
16
        return WorldResource::collection(World::where('galaxy_id', $galaxy_id)
17
            ->investorCount()
18
            ->onlineCount()
19
            ->get());
20
//        return WorldResource::collection(
21
//            Cache::remember('galaxy_worlds_' . $galaxy_id, config('redis.cache_lives.worlds', 60), function () use ($galaxy_id) {
22
//
23
//            })
24
//        );
25
    }
26
27
    public function getTycoons($world_id, $initial = null)
28
    {
29
        if (!empty($initial)) {
30
           return Tycoon::where('name', 'like', $initial . '%')
31
               ->leftjoin('worlds_tycoons', 'tycoons.id', '=', 'worlds_tycoons.id')
32
               ->where('worlds_tycoons.world_id', $world_id)
33
               ->get();
34
35
        } else {
36
            return World::where('id', $world_id)->with('tycoons.tycoon')->get();
37
        }
38
39
    }
40
}