Adding a Controller to a Collection? #5621
-
Is it possible to tie a controller to a specific collection? If so, what's the best practice for this? Here's my use case: I've got a standard Statamic page. I'm wanting to pull data from a third-party API and then pass that data to the front-end. It seems like it makes sense for this code to live in a Controller, but I'm not sure how to tie that controller in before the page is rendered. It seems like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can just create a route in your regular Laravel routes file, pointing to your own controller. Route::get('/third-party/{entry}', 'MyController@show'); use Statamic\Facades\Entry;
use Statamic\View\View;
public function show($entry)
{
$entry = Entry::find($entry);
$collection = $entry->collection();
$data = [...]; // not sure what you want to do, but you can add whatever variables you need in the view.
return View::make()
->template('templatename')
->layout('layoutname')
->with($data);
} |
Beta Was this translation helpful? Give feedback.
You can just create a route in your regular Laravel routes file, pointing to your own controller.