Orchid Helper has class and traits that will help you a lot in development
The manual assumes that you already have a copy of Laravel with Orchid
You can install the package using the Сomposer. Run this at the command line:
composer require islamdb/orchid-helper
This will update composer.json
and install the package into the vendor/
directory.
This trait will make the $allowedSorts
and $allowedFilters
filled. Depand on $fillable
in your Model
use IslamDB\OrchidHelper\Resource\Traits\ResourceDefaultAllowedSortsAndFilters;
class YourModel extends Model
{
use ResourceDefaultAllowedSortsAndFilters;
...
}
This trait will make default sorted in your resource
use IslamDB\OrchidHelper\Resource\Traits\ResourceDefaultFilter;
class YourResource extends Resource
{
use ResourceDefaultFilter;
...
}
You can change $defaultSortedColumn
and $defaultSortedOrder
in construct
This trait will change the default label of your Resource name
use IslamDB\OrchidHelper\Resource\Traits\ResourceDefaultLabel;
class YourResource extends Resource
{
use ResourceDefaultLabel;
...
}
This will change from "Your Resource" to "Your". But you can change static $labelToReplace
value in construct
This trait will sort your resources by filename
use IslamDB\OrchidHelper\Resource\Traits\ResourceDefaultSortingByFilename;
class YourResource extends Resource
{
use ResourceDefaultSortingByFilename;
...
}
This trait will give default delete action
use IslamDB\OrchidHelper\Resource\Traits\ResourceDeleteAction;
class YourResource extends Resource
{
use ResourceDeleteAction;
...
}
This trait will help you to save your attachment and sluggable in resource
use IslamDB\OrchidHelper\Resource\Traits\ResourceOnSave;
class PostResource extends Resource
{
use ResourceOnSave;
public function onSave(ResourceRequest $request, Model $model)
{
$this->sluggable($request);
$this->saveWithAttachment($request, $model);
}
...
}
All traits before are in this trait
use IslamDB\OrchidHelper\Resource\Traits\ResourceDefault;
class YourResource extends Resource
{
use ResourceDefault;
...
}
This class is used by Orchid Setting package. You can visit islamdb/orchid-setting
Field::INPUT_EMAIL // 'email'
Field::INPUT_FILE // 'file'
Field::INPUT_HIDDEN // 'hidden'
Field::INPUT_MONTH // 'month'
Field::INPUT_NUMBER // 'number'
Field::INPUT_PASSWORD // 'password'
Field::INPUT_RADIO // 'radio'
Field::INPUT_RANGE // 'range'
Field::INPUT_SEARCH // 'search'
Field::INPUT_TEL // 'tel'
Field::INPUT_TEXT // 'text'
Field::INPUT_TIME // 'time'
Field::INPUT_URL // 'url'
Field::INPUT_WEEK // 'week'
\IslamDB\OrchidHelper\Field::REQUIRED_METHODS
[
RadioButtons::class => [
'options' => "['one' => 'One', 'two' => 'Two', 'three' => 'Three']"
], Range::class => [
'min' => "1",
'max' => "100",
'step' => "1"
], Select::class => [
'options' => "['one' => 'One', 'two' => 'Two', 'three' => 'Three']"
], Picture::class => [
'targetId' => ''
]
]
Returne meta fields with Field params
// function
public static function withMeta(array $fields)
// usage
\IslamDB\OrchidHelper\Field::withMeta([
View::make('group'),
View::make('slug'),
Input::make('title'),
View::make('body'),
View::dateTime('published_at'),
View::dateTime('expired_at')
])
Check wether type is file field or not
// function
public static function isFileField($type)
// usage
\IslamDB\OrchidHelper\Field::isFileField(\Orchid\Screen\Fields\Input::class) // false
Get all available orchid fields
// function
public static function all(bool $withMethods = true, $typeClass = null)
// usage
\IslamDB\OrchidHelper\Field::all()
Find field by class name and return methods etc
// function
public static function find($type, bool $withMethods = true)
// usage
\IslamDB\OrchidHelper\Field::find(\Orchid\Screen\Fields\Matrix::class)
Generate field by class name with options (Orchid Setting)
public static function make($type, string $name = 'value', array $options = [])
use IslamDB\OrchidHelper\Column;
This function will help you to make column with default title, sorting and filter
public static function make($name, $title = null, bool $sorting = true, $filter = TD::FILTER_TEXT)
Column::make('full_name')
(column with "Full Name" column name and filter)
Use this function to generate url table column
public static function url(string $name, string $title = null, $target = '_blank')
Column::url('social_media_url', null, null)
Column::url('social_media_url', null, '_blank')
1. (clickable and go to address in current tab)
2. (clickable and go to address in new tab)
This function will help you to print html
public static function html(string $name, string $title = null)
Column::html('body')
Bold Text
<b><i>Bold Text</i></b>
This function will help you to print out the relation fields
public static function relation(string $name, string $title = null, $columns = 'name', string $glue = ', ', string $glueColumn = ' ')
Assume that you want to get users with their roles and roles are (super admin and administrator)
Column::relation('roles', null, ['name', 'slug'], ', ', ' - ')
Super Admin - super-admin, Administrator - administrator
This function will help you to print out the boolean value
public static function boolean($name, $title = null, array $labels = null)
Column::boolean('enabled', 'Is Active', [true => 'Yes', false => 'No'])
Yes/No (depand on your value)
This function will help you to print out datetime/timestamp
public static function dateTime($name, $title = null, string $locale = 'id', $withTime = true, $withDayName = true)
Column::dateTime('updated_at', 'Last Edit', 'en', true, true)
Tuesday, August 31st 2021, 09:05:38 (depand on your value)
This function will help you to print numeric/money value
public static function money($name, $title = null, $decimals = 2, $zeroTrail = true, $decimalSeparator = '.', $thousandSeparator = ',')
1. Column::make('total', null, 4, true)
2. Column::make('total', null, 4, false)
1. 250,000.23
2. 250,000.2300
This function will help you to view/edit resource
public static function shortcut($name, $title = null, string $route = 'platform.resource.view', int $deep = 2)
1. Column::shortcut('name', null, 'platform.resource.view')
2. Column::shortcut('name', null, 'platform.resource.edit')
1. (clickable, and go to view page)
2. (clickable, and go to edit page)
use IslamDB\OrchidHelper\View;
This function will help you to make sight with default title
public static function make(string $name, string $title = null)
View::make('full_name')
(view with "Full Name")
Use this function to generate url in view page
public static function url(string $name, string $title = null, string $target = '_blank')
1. View::url('social_media_url', null, null)
2. View::url('social_media_url', null, '_blank')
1. (clickable and go to address in current tab)
2. (clickable and go to address in new tab)
This function will help you to print html
public static function html(string $name, string $title = null)
View::html('body')
Bold Text
<b><i>Bold Text</i></b>
This function will help you to print out the relation fields
public static function relation(string $name, string $title = null, $columns = 'name', string $glue = ', ', string $glueColumn = ' ')
View::relation('roles', null, ['name', 'slug'], ', ', ' - ')
Super Admin - super-admin, Administrator - administrator
This function will help you to print out the boolean value
public static function boolean($name, $title = null, array $labels = null)
View::boolean('enabled', 'Is Active', [true => 'Yes', false => 'No'])
Yes/No (depand on your value)
This function will help you to print out datetime/timestamp
public static function dateTime($name, $title = null, string $locale = 'id', $withTime = true, $withDayName = true)
View::dateTime('updated_at', 'Last Edit', 'en', true, true)
Tuesday, August 31st 2021, 09:05:38 (depand on your value)
This function will help you to print numeric/money value
public static function money($name, $title = null, int $decimals = 2, bool $zeroTrail = true, string $decimalSeparator = '.', string $thousandSeparator = ',')
Assume total = 250000.23
1. View::make('total', null, 4, true)
2. View::make('total', null, 4, false)
1. 250,000.23
2. 250,000.2300
Return meta sights
public static function meta(): array
{
return [
static::make('meta_title'),
static::make('meta_keywords'),
static::make('meta_description')
];
}
Return timestamp sights
public static function timestamps(): array
{
return [
static::dateTime('created_at'),
static::dateTime('updated_at')
];
}
Return meta sights with array sight params
public static function withMeta(array $views): array
{
return array_merge($views, static::meta());
}
Return timestamp sights with array sight params
public static function withTimestamps(array $views): array
{
return array_merge($views, static::timestamps());
}
Return meta timestamp sights with array sight params
public static function withMetaAndTimestamps(array $view): array
{
return array_merge($view, static::meta(), static::timestamps());
}