-
-
Save andyvanee/6262c59a369ec9d4ed2e1ef221434cf8 to your computer and use it in GitHub Desktop.
An example of a public endpoint in cockpit
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 | |
// Place this file at config/api/public/testing.php | |
// Replace `mycollection` with the name of one of your collections | |
// Access it at http://yoursite.com/api/public/testing?myarg=testing | |
try { | |
$arg = $this->param('myarg') | |
$items = cockpit('collections')->find('mycollection', ['limit' => 10]); | |
return ['arg' => $arg, 'items' => $items]; | |
} catch (\Throwable $th) { | |
return ['error' => $th->getMessage() . "\n" . $th->getTraceAsString()]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment