PHP code example of sevming / laravel-api-resource
1. Go to this page and download the library: Download sevming/laravel-api-resource library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sevming / laravel-api-resource example snippets
namespace App\Http\Resources\Mock;
use Sevming\LaravelApiResource\BaseResource;
class MockUserResource extends BaseResource
{
public const SCENE_LIST = 'list';
public const SCENE_INFO = 'info';
public function toArray($request)
{
switch ($this->scene) {
case self::SCENE_LIST:
$this->show(['id', 'account']);
break;
case self::SCENE_INFO:
$this->hide(['password']);
break;
default:
break;
}
return $this->filterFields([
'id' => $this->id,
'account' => $this->account,
'password' => $this->password,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
}
public function with($request)
{
return [
'with' => 'with resource',
];
}
}