Last active
June 1, 2021 12:49
-
-
Save raank/fe2319635103b2bee8738cda30b8116b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Models; | |
class User extends \Framework\Package\Model | |
{ | |
/** | |
* The identification of this resource. | |
* | |
* @var integer | |
*/ | |
public $id; | |
/** | |
* The name of this current user. | |
* | |
* @var string | |
*/ | |
public $name; | |
/** | |
* The email of this current email. | |
* | |
* @var string | |
*/ | |
public $email; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
class UsersController extends \App\Http\Controller | |
{ | |
/** | |
* Listing all resources | |
* | |
* @return array | |
*/ | |
public function index(): array | |
{ | |
return [ | |
'message' => 'Successful action!', | |
'data' => \App\Models\User::all() | |
]; | |
} | |
/** | |
* Storing a new resource. | |
* | |
* @return array | |
*/ | |
public function store(array $data): array | |
{ | |
return [ | |
'message' => 'Successful action!', | |
'data' => \App\Models\User::create([ | |
'name' => 'John Doe', | |
'email' => '[email protected]' | |
]) | |
]; | |
} | |
/** | |
* Show a specific resource | |
* | |
* @param int $id | |
* @return array | |
*/ | |
public function show(int $id): array | |
{ | |
return [ | |
'message' => 'Successful action!', | |
'data' => \App\Models\User::find($id) | |
]; | |
} | |
/** | |
* Updating a specific resource. | |
* | |
* @param int $id | |
* @param array $data | |
* @return array | |
*/ | |
public function update(int $id, array $data): array | |
{ | |
return [ | |
'message' => 'Successful action!', | |
'data' => \App\Models\User::find($id)->update($data) | |
]; | |
} | |
/** | |
* Deleting a specific resource. | |
* | |
* @param int $id | |
* @return array | |
*/ | |
public function destroy(int $id): array | |
{ | |
return [ | |
'message' => 'Successful action!', | |
'data' => \App\Models\User::delete($id) | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment