1. Go to this page and download the library: Download metalogico/laravel-formello library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
metalogico / laravel-formello example snippets
// Before (v1.x)
protected function fields(): array
{
return [
'name' => [
'label' => 'Name',
'widget' => 'text',
],
];
}
// After (v2.x)
use Metalogico\Formello\FormelloField;
protected function fields(): array
{
return [
FormelloField::make('name')->label('Name')->widget('text'),
];
}
namespace App\Forms;
use App\Models\Category;
use Metalogico\Formello\Formello;
use Metalogico\Formello\FormelloField;
class ProductForm extends Formello
{
protected function create(): array
{
return [
'method' => 'POST',
'action' => route('products.store'),
];
}
protected function edit(): array
{
return [
'method' => 'PATCH',
'action' => route('products.update', $this->model->id),
];
}
protected function fields(): array
{
return [
FormelloField::make('name')
->label(__('Product Name'))
->help('Enter the name of the product')
->
class Product extends Model
{
protected $fillable = [
'name',
'category_id',
'description',
'price',
'in_stock',
];
}
public function create()
{
$formello = new ProductForm(Product::class);
return view('products.create', [
'formello' => $formello,
]);
}
public function edit(Product $product)
{
$formello = new ProductForm($product);
return view('products.edit', [
'formello' => $formello,
]);
}
protected function fields(): array
{
$password_field = FormelloField::make('password')
->label(__('Password'))
->type('password');
if ($this->isCreating()) {
$password_field-> ->help('Enter the name of the user'),
$password_field,
];
}
$formello = new ProductForm($product);
$formello->setCssFramework('tailwindcss4');