forked from laravel-json-api/laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
38 lines (34 loc) · 1.23 KB
/
api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/*
* Copyright 2024 Cloud Creativity Limited
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/
use LaravelJsonApi\Laravel\Facades\JsonApiRoute;
JsonApiRoute::server('v1')
->prefix('v1')
->namespace('Api\V1')
->resources(function ($server) {
/** Posts */
$server->resource('posts')->relationships(function ($relationships) {
$relationships->hasOne('author')->readOnly();
$relationships->hasMany('comments')->readOnly();
$relationships->hasMany('media');
$relationships->hasMany('tags');
})->actions('-actions', function ($actions) {
$actions->delete('purge');
$actions->withId()->post('publish');
});
/** Users */
$server->resource('users')->only('show','destroy')->relationships(function ($relationships) {
$relationships->hasOne('phone');
})->actions(function ($actions) {
$actions->get('me');
});
/** Videos */
$server->resource('videos')->relationships(function ($relationships) {
$relationships->hasMany('tags');
});
});