1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\API; |
4
|
|
|
|
5
|
|
|
use App\Http\Requests\CreateLeague; |
6
|
|
|
use App\League; |
7
|
|
|
use App\Transformers\LeagueTransformer; |
8
|
|
|
use App\Transformers\TeamTransformer; |
9
|
|
|
use Illuminate\Support\Facades\Input; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @SWG\Swagger( |
13
|
|
|
* schemes={"http"}, |
14
|
|
|
* host="", |
15
|
|
|
* basePath="/", |
16
|
|
|
* @SWG\Info( |
17
|
|
|
* version="1.0.0", |
18
|
|
|
* title="GGF", |
19
|
|
|
* description="This is a sample server GGF", |
20
|
|
|
* @SWG\Contact( |
21
|
|
|
* email="" |
22
|
|
|
* ) |
23
|
|
|
* ) |
24
|
|
|
* ) |
25
|
|
|
*/ |
26
|
|
|
class LeagueController extends Controller |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @SWG\Get( |
30
|
|
|
* tags={"League"}, |
31
|
|
|
* path="/api/v1/leagues", |
32
|
|
|
* description="Returns all leagues from the database", |
33
|
|
|
* operationId="catalogue", |
34
|
|
|
* produces={"application/json"}, |
35
|
|
|
* @SWG\Response( |
36
|
|
|
* response="200", |
37
|
|
|
* description="Successfully get list of leagues" |
38
|
|
|
* ) |
39
|
|
|
* ) |
40
|
|
|
*/ |
41
|
|
|
public function catalogue() |
42
|
|
|
{ |
43
|
|
|
return $this->response->collection(League::all(), new LeagueTransformer(), 'leagues'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @SWG\Post( |
48
|
|
|
* tags={"League"}, |
49
|
|
|
* path="/api/v1/leagues", |
50
|
|
|
* description="Add new league to database", |
51
|
|
|
* operationId="store", |
52
|
|
|
* produces={"application/json"}, |
53
|
|
|
* @SWG\Parameter( |
54
|
|
|
* description="League name", |
55
|
|
|
* in="formData", |
56
|
|
|
* name="league[name]", |
57
|
|
|
* required=true, |
58
|
|
|
* type="string" |
59
|
|
|
* ), |
60
|
|
|
* @SWG\Parameter( |
61
|
|
|
* description="Path to league logo", |
62
|
|
|
* in="formData", |
63
|
|
|
* name="league[logoPath]", |
64
|
|
|
* required=false, |
65
|
|
|
* type="file" |
66
|
|
|
* ), |
67
|
|
|
* @SWG\Response( |
68
|
|
|
* response="200", |
69
|
|
|
* description="Successfully add new league" |
70
|
|
|
* ) |
71
|
|
|
* ) |
72
|
|
|
* @param CreateLeague $request |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function store(CreateLeague $request) |
76
|
|
|
{ |
77
|
|
|
$league = new League(); |
78
|
|
|
$league = $league->addLeague($request); |
79
|
|
|
$league = League::where(['id' => $league->id])->get(); |
|
|
|
|
80
|
|
|
return $this->response->collection($league, new LeagueTransformer(), 'leagues'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @SWG\Get( |
85
|
|
|
* tags={"League"}, |
86
|
|
|
* path="/api/v1/leagueTeams", |
87
|
|
|
* description="Returns all teams from the specified league", |
88
|
|
|
* operationId="teams", |
89
|
|
|
* produces={"application/json"}, |
90
|
|
|
* @SWG\Parameter( |
91
|
|
|
* description="ID of league which teams we need", |
92
|
|
|
* in="query", |
93
|
|
|
* name="leagueId", |
94
|
|
|
* required=true, |
95
|
|
|
* type="integer" |
96
|
|
|
* ), |
97
|
|
|
* @SWG\Response( |
98
|
|
|
* response="200", |
99
|
|
|
* description="Successfully get list of leagues" |
100
|
|
|
* ) |
101
|
|
|
* ) |
102
|
|
|
*/ |
103
|
|
|
public function teams() |
104
|
|
|
{ |
105
|
|
|
$collection = League::findOrFail(Input::get('leagueId'))->teams(); |
106
|
|
|
|
107
|
|
|
return $this->response->collection($collection->get(), new TeamTransformer(), 'leagueTeams'); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.