PHP code example of jessegall / inertia-static-props

1. Go to this page and download the library: Download jessegall/inertia-static-props 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/ */

    

jessegall / inertia-static-props example snippets


\JesseGall\InertiaStaticProps\ServiceProvider::class

use JesseGall\InertiaStaticProps\StaticProp;
use Inertia\Inertia;

class HandleInertiaRequests extends Middleware
{
    public function share(Request $request): array
    {
        return [
            ...parent::share($request),
  
            // Using a StaticProp instance
            'translations' => new StaticProp(fn() => $this->resolveTranslations()),
            
            // Using the Inertia helper
            'enums' => Inertia::static(fn() => $this->resolveEnums()),
        ];
    }
}

class LocaleController extends Controller
{
    public function update(...)
    {
        // Something that 

return Inertia::render('Component', [
    'regularProp' => 'value',
    'staticPropExample' => new StaticProp(fn() => 'static value'),
]);

return Inertia::render(...)->withStaticProps(); // Add static props to the response