PHP code example of mojahed / spa

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

    

mojahed / spa example snippets


use Mojahed\Spa\SpaRequest;

public function index(Request $request)
{
    $employees = Employee::all();

    return SpaRequest::fragmentIf($request,
        view('employees.index', compact('employees')),
        'list'
    );
}

return view('employees.index', compact('employees'))
    ->fragmentIf($request->hasHeader('X-SPA-Request'), 'list');

return [
    'asset_path'       => 'assets/spa',
    'asset_version'    => null,         // e.g. '1.0' for cache busting
    'default_loader'   => 'spinner',    // spinner | skeleton | table | card
    'auto_run_scripts' => true,
    'confirm' => [
        'title'  => 'Are you sure?',
        'text'   => "You won't be able to revert this!",
        'type'   => 'warning',
        'ok'     => 'Yes, proceed!',
        'cancel' => 'Cancel',
    ],
];
bash
php artisan spa:setup
bash
php artisan spa:publish
javascript
function myAppData() {
    return {
        ...spa(),
        // your custom properties and methods
    };
}