PHP code example of inventor96 / inertia-mako

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

    

inventor96 / inertia-mako example snippets


    [
        'packages' => [
            'web' => [
                inventor96\Inertia\InertiaPackage::class,
            ],
        ],
    ];
    

    $dispatcher->registerGlobalMiddleware(inventor96\Inertia\InertiaCsrf::class);
    $dispatcher->registerGlobalMiddleware(inventor96\Inertia\InertiaInputValidation::class);
    $dispatcher->registerGlobalMiddleware(inventor96\Inertia\InertiaMiddleware::class);

    // optionally, define the middleware order. e.g.:
    $dispatcher->setMiddlewarePriority(inventor96\Inertia\InertiaCsrf::class, 50);
    $dispatcher->setMiddlewarePriority(inventor96\Inertia\InertiaInputValidation::class, 60);
    $dispatcher->setMiddlewarePriority(inventor96\Inertia\InertiaMiddleware::class, 70);
    


return [
    /**
     * The view to use when rendering the full HTML page for the
     * initial response to the browser. This config is relative
     * to the `app/resources/views` directory.
     * e.g. `'app'` would resolve to `resources/views/app.tpl.php`.
     */
    'html_template' => 'inertia::default',

    /**
     * The initial title for the full HTML page.
     */
    'title' => 'Loading...',
];


return [
    /**
     * The path to the manifest file generated by Vite.
     * Only needed if you change the default path in Vite,
     * otherwise the key should be omitted entirely.
     */
    //'manifest' => null,

    /**
     * The path to the hot module replacement file generated
     * by Vite. Only needed if you change the default path in
     * Vite, otherwise the key should be omitted entirely.
     */
    //'hot_file' => null,

    /**
     * The base path for the Vite assets. Should match the
     * `base` option in your Vite configuration, but could
     * also point to a CDN or other asset server, if you are
     * serving assets from a different domain.
     */
    'base_path' => '/build/',
];


return [
    /*
     * Use a shared page prop for passing CSRF errors to the
     * frontend. When set to `false`, the middleware will
     * throw an `InvalidTokenException`. If set to any other
     * value, the middleware will populate that prop with the
     * CSRF error message. Dot notation can be used to set
     * nested props. To tap into the form validation errors,
     * you can use the `inertia_errors` prop.
     */
    'use_prop' => false,

    /*
     * The lifetime of the cookie in seconds. 0 means "until
     * the browser is closed".
     */
    'cookie_ttl' => 0,

    'cookie_options' => [
        /*
         * The path on the server in which the cookie will
         * be available on. If set to '/', the cookie will
         * be available within the entire domain. If set to
         * '/foo/', the cookie will only be available within
         * the /foo/ directory and all sub-directories.
         */
        'path' => '/',

        /*
         * The domain that the cookie is available to. To
         * make the cookie available on all subdomains of
         * example.org (including example.org itself) then
         * you'd set it to '.example.org'.
         */
        'domain' => '',

        /*
         * Indicates that the cookie should only be
         * transmitted over a secure HTTPS connection from
         * the client. When set to TRUE, the cookie will
         * only be set if a secure connection exists. On
         * the server-side, it's on the programmer to send
         * this kind of cookie only on secure connection
         * (e.g. with respect to $this->request->isSecure()).
         */
        'secure' => false,

        /*
         * When TRUE the cookie will be made accessible only
         * through the HTTP protocol. This means that the
         * cookie won't be accessible by scripting languages,
         * such as JavaScript. Since the cookie is likely needed
         * by the JavaScript HTTP library in the frontend, it is
         * highly recommended to set this to FALSE.
         */
        'httponly' => false,

        /*
         * The supported values are 'Lax', 'Strict' and 'None'.
         *
         * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
         */
        'samesite' => 'Lax',
    ],
];


return ['1.0'];


$head_file = file_get_contents(__DIR__ . '/../../../../.git/HEAD');
if (strpos($head_file, 'ref: ') === 0) {
    $ref_file = trim(substr($head_file, 5));
    if (file_exists(__DIR__.'/../../../../.git/' . $ref_file)) {
        $commit_hash = trim(file_get_contents(__DIR__.'/../../../../.git/' . $ref_file));
    } else {
        // this fallback will only be used if the git commit hash cannot be found.
        // this will cause a full page load on almost every request, so it's not ideal.
        // hopefully this will only be used when you first create your repo, and never again once you've made your first commit.
        $commit_hash = date('YmdHis');
    }
} else {
    $commit_hash = trim($head_file);
}
return [$commit_hash];