Support the ongoing development of Laravel.io →
Views Blade Forms
Last updated 2 years ago.
0

You can create a class to hold the fields, and validation, then call a function to render it with a single template. You can write this as a library so can be reused. Here is an idea of what you can do.

class TableInterface 
{
    public function getFields();
}

abstract class TableAbstract
{

    private $model;
    private $attribute;

    public function render()
    {
        $attribute = $this->attribute;

        return view('universal.table.template', [
                   'fields' => $this->getFields(),
                   'data' => $this->model->$attribute
              ]);
    }

    public static function create($model, $attribute)
    {
          $table = new self();
          $table->model = $model;
          $table->attribute = $attribute;

          return $table;
    }
}

class AddressTable extends TableAbstract implments TableInterface 
{
    public function getFields()
    {
        return [
            'street'  => [
                'label' => 'Street'
                'validation' => [
                  // may be rules
                ]
            ]
        ];
    }

}


You can call this as follows:

echo AddressTable::create(User::find(1), 'addresses')->render();
Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.