Laravel Metabox : Easy creation of custom fields for Laravel

If you have worked with WordPress, WordPress has a feature called custom metabox. The work of metabox in WordPress is that you create fields, you don’t need to create a database table related to its field. So the metabox itself has a special table that…


This content originally appeared on DEV Community and was authored by Raymond Baghumian

If you have worked with WordPress, WordPress has a feature called custom metabox. The work of metabox in WordPress is that you create fields, you don’t need to create a database table related to its field. So the metabox itself has a special table that stores the received field data in key and value.

Well, we brought this feature of WordPress metabox to Laravel.

Installs

Install Package:

composer require rayiumir/laravel-metabox

After Publish Files:

php artisan vendor:publish --provider="Rayiumir\\LaravelMetabox\\ServiceProvider\\MetaboxServiceProvider"

And Migration Database:

php artisan migrate

How to use

Calling HasMetaboxes in Models Post.php:

use Rayiumir\LaravelMetabox\Traits\HasMetaboxes;

use HasMetaboxes;

To delete post metabox data, place the following function in Post.php:

protected static function boot(): void
{
    parent::boot();

    static::deleting(function ($post) {
        $post->metaboxes()->delete();
    });
}

Read the following documentation to work with fields:

Text Field

Image Upload Field

GitHub


This content originally appeared on DEV Community and was authored by Raymond Baghumian


Print Share Comment Cite Upload Translate Updates
APA

Raymond Baghumian | Sciencx (2025-03-22T23:16:50+00:00) Laravel Metabox : Easy creation of custom fields for Laravel. Retrieved from https://www.scien.cx/2025/03/22/laravel-metabox-easy-creation-of-custom-fields-for-laravel/

MLA
" » Laravel Metabox : Easy creation of custom fields for Laravel." Raymond Baghumian | Sciencx - Saturday March 22, 2025, https://www.scien.cx/2025/03/22/laravel-metabox-easy-creation-of-custom-fields-for-laravel/
HARVARD
Raymond Baghumian | Sciencx Saturday March 22, 2025 » Laravel Metabox : Easy creation of custom fields for Laravel., viewed ,<https://www.scien.cx/2025/03/22/laravel-metabox-easy-creation-of-custom-fields-for-laravel/>
VANCOUVER
Raymond Baghumian | Sciencx - » Laravel Metabox : Easy creation of custom fields for Laravel. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/03/22/laravel-metabox-easy-creation-of-custom-fields-for-laravel/
CHICAGO
" » Laravel Metabox : Easy creation of custom fields for Laravel." Raymond Baghumian | Sciencx - Accessed . https://www.scien.cx/2025/03/22/laravel-metabox-easy-creation-of-custom-fields-for-laravel/
IEEE
" » Laravel Metabox : Easy creation of custom fields for Laravel." Raymond Baghumian | Sciencx [Online]. Available: https://www.scien.cx/2025/03/22/laravel-metabox-easy-creation-of-custom-fields-for-laravel/. [Accessed: ]
rf:citation
» Laravel Metabox : Easy creation of custom fields for Laravel | Raymond Baghumian | Sciencx | https://www.scien.cx/2025/03/22/laravel-metabox-easy-creation-of-custom-fields-for-laravel/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.