nanuc/tall-resources

There is no license information available for the latest version (dev-master) of this package.

dev-master 2023-11-30 15:13 UTC

This package is not auto-updated.

Last update: 2024-04-19 02:02:43 UTC


README

Define resources for your models that can then be used in forms and tables. Currently it uses the great packages tanthammar/tall-forms for forms and MedicOneSystems/livewire-datatables for datatables.

Installation

composer require nanuc/tall-resources@dev-master

Usage

Define a resource

namespace Domain\User\Resources;

use Nanuc\TallResources\Resources\Fields\Email;
use Nanuc\TallResources\Resources\Fields\TextString;
use Nanuc\TallResources\Resources\TallResource;

class UserResource extends TallResource
{
    protected function fields()
    {
        return [
            TextString::make('Name'),
            Email::make('Email'),
        ];
    }
}

Use in form

public function fields()
{
    return UserResource::asForm();
}

Optionally you can define which fields you want to display:

public function fields()
{
    return UserResource::asForm(['name', 'created_at']);
}

Use in table

public function columns()
{
    return UserResource::asTable();
}

Table configuration

Actions

You can define actions that will show up as last column of the table. If there is a route with the action parameter, it will be used - otherwise a Livewire method with the action parameter will be called.

public function columns()
{
    $tableConfiguration = new TallTableConfiguration(
        viewAction: 'users.view',
        editAction: 'edit',
        deleteAction: 'users.delete',
        actionKey: 'id'  // optional; defaults to 'id'
    );
    return UserResource::asTable($tableConfiguration);
}

Available fields

TextString

Email

Date

Boolean