Returning JSON & CSV

Demonstrates sending JSON and CSV using Render and controller helpers.

JSON in a controller

use Stilmark\Base\Controller;

class UsersController extends Controller
{
    public function show()
    {
        $user = ['id' => 1, 'name' => 'Alice'];
        return $this->json($user); // 200 OK with application/json
    }
}

JSON anywhere with Render

use Stilmark\Base\Render;

Render::json(['ok' => true], 201);

CSV export

Verify

Last updated