1. Go to this page and download the library: Download tofandel/inertia-bundle 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/ */
namespace App\Controller;
use Rompetomp\InertiaBundle\Service\InertiaInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class DashboardController extends AbstractController
{
public function index(InertiaInterface $inertia)
{
return $inertia->render('Dashboard', ['prop' => 'propValue']);
}
}
namespace App\EventSubscriber;
use Rompetomp\InertiaBundle\Service\InertiaInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
class InertiaSubscriber implements EventSubscriberInterface
{
/** @var \Rompetomp\InertiaBundle\Service\InertiaInterface */
protected $inertia;
/**
* AppSubscriber constructor.
*
* @param \Rompetomp\InertiaBundle\Service\InertiaInterface $inertia
*/
public function __construct(InertiaInterface $inertia)
{
$this->inertia = $inertia;
}
public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER => 'onControllerEvent',
];
}
public function onControllerEvent($event)
{
$this->inertia->share(
'Auth::user',
[
'name' => 'Hannes', // Synchronously
'posts' => function () {
return [1 => 'Post'];
}
]
);
}
}