mhmiton/laravel-turbolinks-form

Laravel form submission with Turbolinks.

v1.0.0 2021-05-07 01:39 UTC

This package is auto-updated.

Last update: 2024-11-13 22:18:26 UTC


README

Laravel form submission with Turbolinks.

Installation

Requires:

Install through Composer:

composer require mhmiton/laravel-turbolinks-form

You can publish the config file by running:

php artisan vendor:publish --provider="Mhmiton\\LaravelTurbolinksForm\\LaravelTurbolinksFormServiceProvider" --tag="config"

You can publish the views by running:

php artisan vendor:publish --provider="Mhmiton\\LaravelTurbolinksForm\\LaravelTurbolinksFormServiceProvider" --tag="views"

Register Middleware

The \Mhmiton\LaravelTurbolinksForm\Middleware\Turbolinks::class middleware must be registered in the kernel.

Example

// app/Http/Kernel.php

...

protected $middlewareGroups = [
    'web' => [
        ...
        \Mhmiton\LaravelTurbolinksForm\Middleware\Turbolinks::class,
    ],

    ...
];

Validation

For the form validation, you need to use the \Mhmiton\LaravelTurbolinksForm\Traits\TurbolinksValidatable trait in the exception handler.

Example

// app/Exceptions/Handler.php

...
use Mhmiton\LaravelTurbolinksForm\Traits\TurbolinksValidatable;

class Handler extends ExceptionHandler
{
    use TurbolinksValidatable;
    
    ...
}

Scripts

Include these package scripts in your layout file.

Example

@include('turbolinks-form::scripts')

// Laravel 7 or greater

<x:turbolinks-form::scripts />

Note: You can modify these scripts by publishing the views file.

Config

The config file is located at config/turbolinks-form.php after publishing the config file.

Enable or Disable

/*
|--------------------------------------------------------------------------
| TurbolinksForm settings
|--------------------------------------------------------------------------
| TurbolinksForm is enabled by default.
| You can override the value by setting enable to true or false.
|
*/

'enabled' => env('TURBOLINKS_FORM', true)

// or using .env file
TURBOLINKS_FORM=true

Selector

/*
|--------------------------------------------------------------------------
| TurbolinksForm selector
|--------------------------------------------------------------------------
| TurbolinksForm used form selector by default.
| You can use any DOM selector for the form.
|
*/

'selector' => 'form'

License

Copyright (c) 2021 Mehediul Hassan Miton mhmiton.dev@gmail.com

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