Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gvharper's avatar

Implementing custom create

Hi all, this is a broad question but I'm hoping the collective might nudge me in the right direction.

I'd like to implement another "mode" for creating resource records in Filament - a "Record" mode that implements a timer, custom page title, limits fields, etc. All layered on top of standard Create resource functionality. All while keeping the standard Create form.

Does a custom resource page sound like the right path? Any best practices you can share?

Thanks!

0 likes
1 reply
LaryAI's avatar
Level 58

It sounds like you're working with a framework that uses the concept of "resources" for CRUD operations, such as Laravel. If that's the case, you can indeed create a custom resource page to handle your "Record" mode. Here's a general approach you can take:

  1. Define a new route: Create a new route in your web.php file that points to a new method in your controller. This route will be used to display your custom create page.
Route::get('/your-resource/record-create', 'YourResourceController@recordCreate')->name('your-resource.record-create');
  1. Create a new controller method: In your YourResourceController, add a new method called recordCreate that will render your custom create view.
public function recordCreate()
{
    // You can pass any additional data you need for your custom create page
    return view('your-resource.record-create');
}
  1. Create a custom view: Make a new Blade template for your custom create page. You can extend your standard create form and add the additional features like a timer, custom page title, and limited fields.
{{-- resources/views/your-resource/record-create.blade.php --}}
@extends('layouts.app')

@section('title', 'Custom Record Creation')

@section('content')
    <h1>Custom Record Creation</h1>
    {{-- Include your standard create form --}}
    @include('your-resource.partials.create-form')

    {{-- Add your custom timer and other elements here --}}
    <script>
        // Initialize your timer here
    </script>
@endsection
  1. Include the standard create form: If you want to reuse the standard create form, you can extract it into a partial and include it in both the standard create view and your custom record create view.
{{-- resources/views/your-resource/partials/create-form.blade.php --}}
<form method="POST" action="{{ route('your-resource.store') }}">
    @csrf
    {{-- Your standard fields here --}}
    <div>
        <label for="name">Name:</label>
        <input type="text" name="name" id="name" required>
    </div>
    {{-- Add any additional fields for the record mode here --}}
    {{-- ... --}}
    <button type="submit">Create</button>
</form>
  1. Limit fields: To limit fields in your custom create form, you can conditionally render them based on a variable passed to the view, or simply not include them in the custom create form partial.

  2. Implement a timer: For the timer functionality, you can use JavaScript to implement a countdown or stopwatch timer. You can start the timer when the page loads or on a specific user action.

// Example of a simple countdown timer in JavaScript
window.onload = function() {
    var timeLeft = 60 * 5; // 5 minutes in seconds
    var timerElement = document.getElementById('timer');

    var timer = setInterval(function() {
        var minutes = parseInt(timeLeft / 60, 10);
        var seconds = parseInt(timeLeft % 60, 10);

        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        timerElement.textContent = minutes + ":" + seconds;

        if (--timeLeft < 0) {
            clearInterval(timer);
            // Handle timeout, e.g., submit the form, show a message, etc.
        }
    }, 1000);
};

Remember to include the timer element in your custom create view.

{{-- Add this to your record-create.blade.php --}}
<div id="timer">05:00</div>

By following these steps, you should be able to implement a custom "Record" mode for creating resource records while keeping the standard create form functionality intact. Make sure to test your new functionality thoroughly to ensure it works as expected.

Please or to participate in this conversation.