https://github.com/infinitypaul/laravel-multistep-forms
https://github.com/infinitypaul/laravel-multistep-forms
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/infinitypaul/laravel-multistep-forms
- Owner: infinitypaul
- License: mit
- Created: 2020-06-20T19:43:39.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-27T14:21:40.000Z (almost 6 years ago)
- Last Synced: 2025-02-11T09:50:03.154Z (over 1 year ago)
- Language: PHP
- Size: 34.2 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Multi-step Form
[](https://packagist.org/packages/infinitypaul/laravel-multistep-forms)
[](https://travis-ci.org/infinitypaul/laravel-multistep-forms)
[](https://scrutinizer-ci.com/g/infinitypaul/laravel-multistep-forms)
[](https://packagist.org/packages/infinitypaul/laravel-multistep-forms)
Hi Fellas! So you know how you would like to create a dynamic registration form but then you can't because you feel this is impossible with PHP.
Well, I have good news for ya, this is so POSSIBLE with this package. Yeah that's right, I mean it. Let's get down on the "how":
So we will be working with a 3 step form:
## Installation
You can install the package via composer:
```bash
composer require infinitypaul/laravel-multistep-forms
```
## Usage
After installing the package, I will be creating 3 blades for the different steps of the form:
#### Step 1: Create the blades for the form.
1.blade.php
``` php
@extends('layouts.app')
@section('content')
{{ __('Register') }}
@csrf
{{ __('Name') }}
@error('name')
{{ $message }}
@enderror
{{ __('Middle Name') }}
@error('middle')
{{ $message }}
@enderror
{{ __('Next') }}
@endsection
```
2.blade.php
``` php
@extends('layouts.app')
@section('content')
{{ __('Register') }}
@csrf
{{ __('E-Mail Address') }}
@error('email')
{{ $message }}
@enderror
{{ __('Next') }}
@endsection
```
3.blade.php
``` php
@extends('layouts.app')
@section('content')
{{ __('Register') }}
@csrf
{{ __('Password') }}
@error('password')
{{ $message }}
@enderror
{{ __('Finish') }}
@endsection
```
#### Step 2: Create the controller for the each form.
After creating the blade views for each of the forms, p.s: I created them in a folder "register". We'll be heading to the controller, so in app\Http\Controllers\Auth, we would be creating a folder "Register" i.e our path will be "app\Http\Controllers\Auth\Register". In the Register folder, we would be creating 3 controllers for the three steps:
RegisterControllerStep1.php
``` php
store(['name' => $request->name, 'middle' => $request->middle])->complete();
return redirect()->route('auth.register.2.index');
}
}
```
RegisterControllerStep2.php
``` php
store($request->only('email'))->complete();
return redirect()->route('auth.register.3.index');
}
}
```
RegisterControllerStep3.php
``` php
notCompleted(1)){
return redirect()->route('auth.register.1.index');
}
return view('auth.register.3');
}
public function store(MultiStep $multiStep, Request $request){
MultiStep::step('auth.register', 3)->store($request->only('password'))->complete();
MultiStep::clearAll();
}
}
```
#### Step 3: Routing!
Let's move on to the route, in our web.php, we will include this:
``` php
Route::multistep('auth/register', 'Auth\Register\RegisterController')
->steps('3')
->name('auth.register')
->only(['index', 'store']);
```
We're done guys!!!
So if I head to {URL}/auth/register/1, I would see this:

When I click on next, it takes me to {URL}/auth/register/2 and this will display:
.png)
On clicking on next, we get {URL}/auth/register/3:
.png)
Its a wrap! Well done guys!!!
### Testing
``` bash
composer test
```
### Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Bugs & Fixtures
If you have spotted any bugs, or would like to request additional features from the library, please file an issue via the Issue Tracker on the project's Github page: https://github.com/infinitypaul/laravel-multistep-forms/issues.
### Security
If you discover any security related issues, please email infinitypaul@live.com instead of using the issue tracker.
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.