-
Is there a way to generate layouts dynamycally ? I need to generate X layouts based on amount of days in months. I tried do do
But got I managed to generate everything inside a custom blade template with query object, loops and all, but my form can't send a POST request, got an error saying Absolutly no idea what to try :/ @tabuna, any ideas to help please ? Thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @sylzys, classes for layers are not intended for construction, but you can move the logic to any other place and pass a list of classes to display, like this: public function layout(): array
{
$tabs = collect([
Tab1::class,
Tab2::class,
Tab3::class,
])
->filter(function (string $class) {
return $class !== Tab1::class;
})
->toArray();
return [
Layout::tabs($tabs)
];
} A slightly more complex example of construction, not for your case. But I must mention: Personally, I try to avoid this definition, as I want to open the screen and see all of its definitions, not conditions. php artisan orchid:rows ConditionShowExample And in it, define the <?php
namespace App\Orchid\Layouts;
use Orchid\Screen\Field;
use Orchid\Screen\Layouts\Rows;
class ConditionShowExample extends Rows
{
/**
* Used to create the title of a group of form elements.
*
* @var string|null
*/
protected $title;
/**
* Get the fields elements to be displayed.
*
* @return Field[]
*/
protected function fields(): array
{
return [];
}
/**
* @return bool
*/
public function isSee(): bool
{
// Any conditions for display
// Screen data can be accessed via $this->query
// https://orchid.software/en/recipes/how-to-access-screen-data-from-a-layer/
return true;
}
} Ultimately, this allows you to keep the screen clean and easy to read, leaving different definitions: public function layout(): array
{
return [
Layout::tabs([
ConditionShowExample::class, // Each of them can have its own `isSee` condition
ConditionShowExample::class, // Each of them can have its own `isSee` condition
ConditionShowExample::class, // Each of them can have its own `isSee` condition
]),
];
} It doesn't matter which method you choose, but I hope my answer was helpful and suggested how to use it. |
Beta Was this translation helpful? Give feedback.
Hi @sylzys, classes for layers are not intended for construction, but you can move the logic to any other place and pass a list of classes to display, like this:
A slightly more complex example of construction, not for your case. But I must mention:
Personally, I try to avoid this definition, as I want to open the screen and see all of its definitions, not conditions.
For this, I prefer to defi…