🧙‍♂️ Simple Wizard Controller for Laravel.

Overview

Laravel Wizards

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Simple Wizard Controller for Laravel. If you need a more sophisticated solution, then have a look at Laravel Aracanist.

Installation

Install this package via composer:

composer require marvinrabe/laravel-wizards

Usage

Register a route using the wizard macro in your web.php:

Route::wizard('order', OrderWizardController::class);

Create a controller for your wizard. For example OrderWizardController.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use MarvinRabe\LaravelWizards\Wizard;
use MarvinRabe\LaravelWizards\WizardController;

class OrderWizardController extends WizardController
{
    // Prepare a payload. This payload will be available in $wizard->payload on each step. It will be saved
    // automatically after each step{number}Submit method. It is used to store each partial result until onFinish.
    // The simplest payload is an array. But you could use anything you want. It only needs to be serializable!
    public function preparePayload(Request $request, Wizard $wizard): array
    {
        return [];
    }

    // A step is simply a method with the name step{number}.
    // You can do anything you want! Return a view, redirect to somewhere else, etc.
    public function step1(Request $request, Wizard $wizard): mixed
    {
        return view('order.payment');
    }

    // For each step there might be a submit action with the name step{number}Submit. This will be called on POST.
    // In here you could validate the request and afterwards store it in the prepared payload like so:
    public function step1Submit(Request $request, Wizard $wizard): void
    {
        $request->validate([
            'credit_card' => ['required', 'string']
        ]);

        $wizard->payload['credit_card'] = $request->boolean('credit_card');
    }

    // You don't have to specify a step2Submit. If you omit this method the wizard will simply jump to the next step.
    // In each step you have access to the previously populated payload. By default it is stored in the session.
    public function step2(Request $request, Wizard $wizard): mixed
    {
        return view('order.summary', [
            'credit_card' => $wizard->payload['credit_card']
        ]);
    }
    
    // Continue with more step{number} and step{number}Submit methods. As many as you like!
    
    // After the last step the onFinish method will be called instead of the step{number}Submit.
    // The wizard will be deleted from the session and is no longer available.
    public function onFinish(Request $request, Wizard $wizard): mixed
    {
        // Do something! This is your final chance.
        return view('order.success');
    }
}

Navigate to /orders to start a wizard. Each wizard has a unique ID and is by default stored in the current Session. The URL follows the following convention:

/{name}/{id?}/{step?}

For our previous example a real URL might look like this /order/6e00f3db-c1c9-48b7-a90b-0081f75ed56c/2.

If the id is missing it will create a new wizard instance using preparePayload. If the step is missing it will resume the wizard at the last step.

License

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

You might also like...
Simple PHP/Laravel app that displays Todoist tasks in a view designed for a Kindle Touch
Simple PHP/Laravel app that displays Todoist tasks in a view designed for a Kindle Touch

productivity-dashboard Just a simple PHP/Laravel app that retrieves (so far) tasks from Todoist and displays them in a simple view designed for a Kind

Simple PHP/Laravel app that displays Todoist tasks in a view designed for a Kindle Touch
Simple PHP/Laravel app that displays Todoist tasks in a view designed for a Kindle Touch

productivity-dashboard Just a simple PHP/Laravel app that retrieves (so far) tasks from Todoist and displays them in a simple view designed for a Kind

A simple twitter-feed-style RSS aggregator written in PHP, Laravel, Inertia.js, Tailwind and Vue.js
A simple twitter-feed-style RSS aggregator written in PHP, Laravel, Inertia.js, Tailwind and Vue.js

RSS A simple, opinionated, RSS feed aggregator. Features The following features are built into the application: Supports RSS and ATOM formats. Regular

Simple opinionated PHP 8.1 enum helper for Laravel
Simple opinionated PHP 8.1 enum helper for Laravel

Laravel Enum Helper This is an extension of the datomatic/enum-helper package based on Laravel Framework. The package consists on a LaravelEnumHelper

A simple package for idempotent requests in Laravel.

📽 Replay A simple package for handling idempotent requests in Laravel. Any routes using the Replay middleware will check for whether an incoming requ

Sslurp is a simple library which aims to make properly dealing with SSL in PHP suck less.

Sslurp v1.0 by Evan Coury Introduction Dealing with SSL properly in PHP is a pain in the ass and completely insecure by default. Sslurp aims to make i

Currency is a simple PHP library for current and historical currency exchange rates & crypto exchange rates. based on the free API exchangerate.host

Currency Currency is a simple PHP library for current and historical currency exchange rates & crypto exchange rates. based on the free API exchangera

Simple IT Documentation Solution for MSPs

SimpleMSPDoc RC 1.0 I wasn't happy with what other IT documention software had. I felt they over complicated things and required so much clicky clicky

Simple customizable captcha script for bot prevention in php language.

phpCaptcha Simple customizable captcha script for bot prevention in php language. Usage ?php session_start(); $status = ""; if ($_SESSION['captcha']

Releases(0.4.0)
Owner
Marvin Rabe
Laravel Developer
Marvin Rabe
Silverstripe-searchable - Adds to the default Silverstripe search by adding a custom results controller and allowing properly adding custom data objects and custom fields for searching

SilverStripe Searchable Module UPDATE - Full Text Search This module now uses Full Text Support for MySQL/MariaDB databases in version 3.* Adds more c

ilateral 13 Apr 14, 2022
Actions: controller + auth + validation in one class

Actions: controller + auth + validation in one class This package provides only one class: an Action class that extends the FormRequest class we all k

edatta 2 Dec 15, 2022
Simple library that abstracts different metrics collectors. I find this necessary to have a consistent and simple metrics (functional) API that doesn't cause vendor lock-in.

Metrics Simple library that abstracts different metrics collectors. I find this necessary to have a consistent and simple metrics API that doesn't cau

Benjamin Eberlei 311 Nov 20, 2022
Configure Magento 2 to send email using Google App, Gmail, Amazon Simple Email Service (SES), Microsoft Office365 and many other SMTP (Simple Mail Transfer Protocol) servers

Magento 2 SMTP Extension - Gmail, G Suite, Amazon SES, Office 365, Mailgun, SendGrid, Mandrill and other SMTP servers. For Magento 2.0.x, 2.1.x, 2.2.x

MagePal :: Magento Extensions 303 Oct 7, 2022
Simple PHP Pages - A simple puristic PHP Website Boilerplate

Simple PHP Pages - A simple puristic PHP Website Boilerplate ?? Hey! This project provides simple and basic concepts for PHP pages. It includes ideas

SteamPixel 8 Sep 22, 2022
A Simple Linode SDK built for Laravel with @JustSteveKing laravel-transporter package

linode client A Simple Linode client built for Laravel with @JustSteveKing laravel-transporter package Installation You can install the package via co

Samuel Mwangi 2 Dec 14, 2022
salah eddine bendyab 18 Aug 17, 2021
A simple laravel package for wallet implementation

wallet A simple laravel package for wallet implementation. This package can basically be plugged into a laravel project and it will handle wallet impl

Ademuyiwa Adetunji 8 Dec 1, 2022
Simple repository pattern for laravel, with services!

With repository and service you can separate business logic and query logic, slim controller and DRY. Simple generate repository and service with artisan command, automatically bind interface with repository

Yaz3 27 Jan 1, 2023
Simple laravel package for 2C2P Payment Gateway.

Laravel 2C2P Payment Gateway Simple laravel package for 2C2P Payment Gateway. Installation You can install the package via composer: composer require

null 3 Dec 7, 2021