PHPackages                             formpanel/formpanel-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. formpanel/formpanel-laravel

ActiveLibrary[API Development](/categories/api)

formpanel/formpanel-laravel
===========================

Laravel integration for the FormPanel PHP client library

1.0.0(5mo ago)036↓50%MITPHPPHP ^8.2

Since Nov 26Pushed 5mo agoCompare

[ Source](https://github.com/mihai-adam/formpanel-laravel)[ Packagist](https://packagist.org/packages/formpanel/formpanel-laravel)[ RSS](/packages/formpanel-formpanel-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

FormPanel Laravel
=================

[](#formpanel-laravel)

Laravel integration for the FormPanel PHP client library. This package provides a seamless way to submit forms to FormPanel API from your Laravel applications with configuration, facades, and artisan commands.

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Laravel 11.x or 12.x
- Composer

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require formpanel/formpanel-laravel
```

The service provider will be automatically registered via Laravel's package auto-discovery.

Configuration
-------------

[](#configuration)

### Publish Configuration

[](#publish-configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=formpanel-config
```

This will create a `config/formpanel.php` file in your application.

### Environment Variables

[](#environment-variables)

Add the following to your `.env` file:

```
FORMPANEL_API_KEY=your-api-key-here
FORMPANEL_FORM_SLUG=contact-form
```

**Required:**

- `FORMPANEL_API_KEY` - Your FormPanel API key

**Optional:**

- `FORMPANEL_FORM_SLUG` - Default form slug
- `FORMPANEL_BASE_URL` - Base URL (default: )
- `FORMPANEL_TIMEOUT` - Request timeout in seconds (default: 30)
- `FORMPANEL_MAX_RETRIES` - Maximum retry attempts (default: 3)
- `FORMPANEL_LOGGING` - Enable debug logging (default: false)

Usage
-----

[](#usage)

### Using the Facade

[](#using-the-facade)

The package provides a convenient facade for accessing the FormPanel client:

```
use Formpanel\Laravel\Facades\Formpanel;

// Submit form data using the default form slug from config
$result = Formpanel::submit([
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'message' => 'Hello from Laravel!',
]);

echo "Submission ID: " . $result->id;
```

### Using a Specific Form

[](#using-a-specific-form)

Create a client for a specific form using the `form()` method:

```
use Formpanel\Laravel\Facades\Formpanel;

// Get a client for a specific form
$client = Formpanel::form('contact-form');

// Submit data
$result = $client->submit([
    'name' => 'Jane Doe',
    'email' => 'jane@example.com',
    'message' => 'Hello!',
]);

// Get form information
$form = $client->get();
echo "Form: {$form->name}";
echo "Fields: " . count($form->fields);
```

### Using Dependency Injection

[](#using-dependency-injection)

Inject the client into your controllers, jobs, or services:

```
use Formpanel\FormClient;

class ContactController extends Controller
{
    public function __construct(protected FormClient $formpanel)
    {
    }

    public function store(Request $request)
    {
        $validated = $request->validate([
            'name' => 'required|string',
            'email' => 'required|email',
            'message' => 'required|string',
        ]);

        try {
            $result = $this->formpanel->submit($validated);

            return redirect()->back()->with('success', 'Form submitted successfully!');
        } catch (\Formpanel\Exceptions\ValidationException $e) {
            return redirect()->back()->withErrors($e->getErrors());
        }
    }
}
```

### Using the Factory for Multiple Forms

[](#using-the-factory-for-multiple-forms)

Use the factory to create clients for different forms:

```
use Formpanel\Laravel\FormpanelFactory;

class FormController extends Controller
{
    public function __construct(protected FormpanelFactory $formpanel)
    {
    }

    public function submitContact(Request $request)
    {
        $client = $this->formpanel->make('contact-form');
        $result = $client->submit($request->validated());

        return redirect()->back()->with('success', 'Contact form submitted!');
    }

    public function submitNewsletter(Request $request)
    {
        $client = $this->formpanel->make('newsletter-signup');
        $result = $client->submit(['email' => $request->email]);

        return redirect()->back()->with('success', 'Subscribed to newsletter!');
    }
}
```

### Getting Form Information

[](#getting-form-information)

Retrieve form details including field definitions:

```
use Formpanel\Laravel\Facades\Formpanel;

$form = Formpanel::get();

echo "Form: {$form->name}\n";
echo "Status: {$form->status}\n";
echo "Description: {$form->description}\n";

foreach ($form->fields as $field) {
    echo "- {$field->name} ({$field->type})";
    echo $field->required ? " [required]" : "";
    echo "\n";
}
```

### Controller Example

[](#controller-example)

Complete controller example with error handling:

```
