Overview of the Geolocation form field
Code16\Sharp\Form\Fields\SharpFormGeolocationField class.website·Indexed 33 days ago
https://sharp.code16.fr/docs/10.x/guide/An administration panel for Laravel 11+ and PHP 8.3+ that allows developers to manage entities through Entity Lists, Forms, Show Pages, and Dashboards. It includes a variety of form fields (text, editor, upload, geolocation, etc.) and show fields, as well as tools for state management, filtering, and reordering instances.
Code16\Sharp\Form\Fields\SharpFormGeolocationField class.Code16\Sharp\Form\Fields\SharpFormNumberField class to create a numeric text field in a form. This field is designed specifically for handling numeric input and supports constraints on minimum and maximum values, as well as step increments for UI controls.Code16\Sharp\Form\Fields\SharpFormHtmlField is a read-only field used to display dynamic information within a form. It does not accept user input (fromFront returns null).Sharp is designed around the concept of entities. An entity is a data structure with meaning in an application context (e.g., a Person, Post, or Order). While optimized for Eloquent Models, a Sharp entity can represent a single Model, a portion of a Model, or multiple Models. An individual occurrence of an entity is called an instance.
Entities are typically managed through three primary UI components:
commands (actions applied to a single instance or the entire list) and state changers (e.g., toggling a 'published' status).Code16\Sharp\Show\SharpSingleShow. You must implement buildShowFields(FieldsContainer $showFields) and buildShowLayout(ShowLayout $showLayout). Unlike standard shows, you must implement findSingle(): array without parameters, as the logic to determine the instance (e.g., based on the authenticated user) is handled internally.class ProfileSingleShow extends SharpSingleShow
{
public function findSingle(): array
{
return $this->transform(auth()->user());
}
}currentSharpRequest() helper is deprecated and will be removed in a future version. Use the sharp()->context() helper instead.sharpList(string $entityKey) method initiates a fluent interaction with an Entity List. You can verify the list data, apply filters using withFilter(), execute Entity Commands via entityCommand(), execute Instance Commands via instanceCommand(), or delete an instance.// Test list data and filtering
$this->sharpList(Post::class)
->withFilter(CategoryFilter::class, 1)
->get()
->assertOk()
->assertListData(fn (AssertableJson $data) => $data
->count(3)
->has('0.title', 'My first post')
);
// Test an Entity Command with a form
$this->sharpList(Post::class)
->entityCommand(ExportPosts::class)
->getForm()
->post(['format' => 'csv'])
->assertOk();
// Test an Instance Command
$this->sharpList(Post::class)
->instanceCommand(PublishPost::class, 1)
->post()
->assertOk();
// Delete an instance
$this->sharpList(Post::class)
->delete(1)
->assertOk();$instance parameter in setCustomTransformer now refers to the related model instead of the main model. This ensures the instance is the correct entity being transformed.// Sharp 9.x rewrite
$this
->setCustomTransformer('customer:name', function ($value, $instance, $attribute) {
// $instance is now the Customer instance, not the Order instance
return $instance->name;
})
->transform(Order::find(1));getDataLocalizations() method and mark the desired fields as localized using setLocalized().class BookShow extends SharpShow
{
protected function buildShowFields(FieldsContainer $showFields): void
{
$showFields->addField(
SharpShowTextField::make('title')
->setLabel('Title')
->setLocalized()
);
}
public function getDataLocalizations(): array
{
return ['en', 'fr'];
}
}morphOne relationship. For Laravel 12+, use withAttributes to define the model_key. For versions prior to Laravel 12, use a where clause.// Laravel 12+
class Book extends Model
{
public function cover()
{
return $this->morphOne(Media::class, 'model')
->withAttributes(['model_key' => 'cover']);
}
}
// Before Laravel 12
class Book extends Model
{
public function cover()
{
return $this->morphOne(Media::class, 'model')
->where('model_key', 'cover');
}
}Code16\Sharp\Http\Context\SharpContext class and Code16\Sharp\Http\WithSharpContext trait have been removed. Use Code16\Sharp\Http\Context\CurrentSharpRequest to access the current context.