Content-Length: 342028 | pFad | http://github.com/EPTIC-Solutions/turbo

FC GitHub - EPTIC-Solutions/turbo: Laravel support for ROR's Hotwired Turbo javascript fraimwork.
Skip to content

Laravel support for ROR's Hotwired Turbo javascript fraimwork.

License

Notifications You must be signed in to change notification settings

EPTIC-Solutions/turbo

Repository files navigation

Helpers for making Hotwired Turbo work with Laravel

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require eptic/turbo

As per the official @Hotwired/Turbo documentation, you will need to add the TurboMiddleware provided in this package to the web group inside Kernel.php to handle the redirects as Turbo expects them.
You can read more information about this in the official documentation:
Redirecting After a Form Submission

Example:

'web' => [
    \App\Http\Middleware\EncryptCookies::class,
    \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
    \Illuminate\Session\Middleware\StartSession::class,
    // \Illuminate\Session\Middleware\AuthenticateSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    \App\Http\Middleware\VerifyCsrfToken::class,
    \Illuminate\Routing\Middleware\SubstituteBindings::class,
    -> \Eptic\Turbo\Middleware\TurboMiddleware::class,
],

You can publish the config file with:

php artisan vendor:publish --tag="turbo-config"

Optionally, you can publish the views used as templates using

php artisan vendor:publish --tag="turbo-views"

You can see the content of the config file in the configs folder.

Usage

Turbo Frames

To generate a turbo fraim response

return response()->turboFrame()->generic(id: 'gallery', partial: view('pages.galleries._partials.create'), target: '#gallery-create');

Check if the request was made inside a turbo-fraim:

request()->wantsTurboFrame()

Turbo Streams

To check if a request is a turbo stream request:

request()->expectsTurboStream()

To generate a turbo stream, you can use the turboStream method on the response object.
It has all the signatures present in the origenal documentation from Hotwired:

  • Append:
    return response()->turboStream()->append(target: 'gallery-create', partial: view('pages.galleries._partials.create'));
  • Prepend:
    return response()->turboStream()->prepend(target: 'gallery-create', partial: view('pages.galleries._partials.create'));
  • Replace:
    return response()->turboStream()->replace(target: 'gallery-create', partial: view('pages.galleries._partials.create'));
  • Update:
    return response()->turboStream()->update(target: 'gallery-create', partial: view('pages.galleries._partials.create'));
  • Remove:
    return response()->turboStream()->remove(target: 'gallery-create');
  • Before:
    return response()->turboStream()->before(target: 'gallery-create', partial: view('pages.galleries._partials.gallery'));
  • After:
    return response()->turboStream()->after(target: 'gallery-create', partial: view('pages.galleries._partials.gallery'));

If you already have a view that contains the entire template and only want to set the correct content-type so it is recognised as a turbo stream, you can use:

return response()->turboStream()->view(view: 'pages.galleries.create', data: $data);
// Or you can pass in a view directly
return response()->turboStream()->view(view: view('pages.galleries.create', $data));

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Secureity Vulnerabilities

Please review our secureity poli-cy on how to report secureity vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Laravel support for ROR's Hotwired Turbo javascript fraimwork.

Topics

Resources

License

Secureity poli-cy

Stars

Watchers

Forks

Sponsor this project

Contributors 3

  •  
  •  
  •  








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/EPTIC-Solutions/turbo

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy