Skip to content

Instantly share code, notes, and snippets.

@raank
Last active June 1, 2021 12:49
Show Gist options
  • Save raank/fe2319635103b2bee8738cda30b8116b to your computer and use it in GitHub Desktop.
Save raank/fe2319635103b2bee8738cda30b8116b to your computer and use it in GitHub Desktop.
<?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;
}
<?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' => 'john@doe.com'
])
];
}
/**
* 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