PHP code example of jamosaur / foundation
1. Go to this page and download the library: Download jamosaur/foundation 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/ */
jamosaur / foundation example snippets
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Jamosaur\Foundation\ApiController;
class UserController extends ApiController
{
public function index(): JsonResponse
{
$users = User::all();
// By default this will try to find a transformer in `App\Transformers` called
// `UserTransformer`. It guesses the name of the transformer based on the controller
// name.
return $this->transformCollection('users', $users)
->respond();
}
public function definedTransformer(): JsonResponse
{
$users = User::all();
// You can override the transformer to use like this.
return $this->setTransformer(new CustomTransformer())
->transformCollection('users', $users)
->respond();
}
}