2017 © Pedro Peláez
 

library funnel

A catch-all controller (for Laravel).

image

marklj/funnel

A catch-all controller (for Laravel).

  • Wednesday, September 28, 2016
  • by marklj
  • Repository
  • 1 Watchers
  • 1 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 10 % Grown

The README.md

Funnel

A catch-all controller (for Laravel), (*1)

Installation

  1. Install from Composer:
composer require marklj/funnel
  1. Add Marklj\Funnel\FunnelServiceProvider to your app.php service provider configuration values.
  2. Publish the packages configuration:
php artisan vendor:publish

Quick Start

1. Send a request

Send a POST request to /mailbox. You can do this with AJAX from your front-end library of choice (Angular / Vue / etc), but for simplicity, we'll use a simple HTML form example., (*2)

The default Funnel endpoint is /mailbox, but this can be configured in the funnel.php configuration file that was published in the installation section., (*3)

The command request parameter is required and is automatically converted to StudlyCase when processed by Funnel., (*4)

<form action="/mailbox" method="POST">
    <input type="hidden" name="command" value="post_blog" />
    <input type="text" name="payload[blog_title]" />
    <button>Submit</button>
</form> 

Note that data does not need to be contained in a payload[] array unless you want to filter exactly what perameters are passed to your action. If you do not namespace your inputs, like name="blog_title", all of your input data will be passed to your action., (*5)

2. Map to an Action

Funnel will try to associate the StudlyCase command, in this case PostBlog, to an action. This association is made in the funnel.php configuration file., (*6)

// config/funnel.php
[
    // ...

    'action_mappings' => [
        'PostBlog' => \App\Blog\Actions\PostAction::class,

        // other mappings here
    ]
]

3. Create Action

The action class must implement the Marklj\Funnel\Actionalble interface. You are free to place whatever code you need here., (*7)

All of your payload data data will be available in the ActionPayload object., (*8)

<?php namespace App\Blog\Actions;

use Marklj\Funnel\Actionable;
use Marklj\Funnel\ActionPayload;

class PostAction implements Actionable 
{
    public function __invoke(ActionPayload $payload) {
        print 'Hello Funnel!';
        print 'Blog Post Title: ' . $payload->get('blog_title');
    }
}

Since the action is instantiated using Laravel's IoC container, you are free to inject any dependancies into your action via the constructor., (*9)

The Versions

28/09 2016

dev-master

9999999-dev

A catch-all controller (for Laravel).

  Sources   Download

The Requires

 

The Development Requires

by Mark Johnson

28/09 2016

v1.0

1.0.0.0

A catch-all controller (for Laravel).

  Sources   Download

The Requires

 

The Development Requires

by Mark Johnson