Siberfx / backpack-leafletjs
Laravel Backpack 的 Leafletjs ^5.x
6.1.2
2024-03-19 20:16 UTC
Requires
- php: ^8.1|^8.2
- backpack/crud: ^6.0
- illuminate/support: ^9.0|^10.0|^11.0
README
安装
您可以通过 composer 安装此包
composer require siberfx/backpack-leafletjs
使用
// config/leaflet.php file content, you can modify it by your own settings.
return [
'model_name' => App\Models\Setting::class,
'table_name' => 'settings',
'lat_field' => 'lat',
'lng_field' => 'lng',
'mapbox' => [
'access_token' => env('MAPS_MAPBOX_ACCESS_TOKEN', 'xxxxxxxxxxxxxxxxxxxxx'),
],
];
发布文件
php artisan vendor:publish --provider="Backpack\Leafletjs\LeafLetServiceProvider" --tag="migrations" #publish the migration file
php artisan vendor:publish --provider="Backpack\Leafletjs\LeafLetServiceProvider" --tag="config" #publish the config file
php artisan vendor:publish --provider="Backpack\Leafletjs\LeafLetServiceProvider" --tag="lang" #publish the lang files
php artisan vendor:publish --provider="Backpack\Leafletjs\LeafLetServiceProvider" --tag="view_components" #publish the lang files
或
php artisan vendor:publish --provider="Backpack\Leafletjs\LeafLetServiceProvider" --tag="all"
将 Leaflet 字段添加到您的模型中
您可以通过 config/backpack/leaflet.php
文件和 table_name
字段来覆盖您的 "lat, lng" 字段所在的表以及您想要创建字段的模型,如果已设置
$fillable = [
'lat',
'lng',
...
];
或
config('backpack.leaflet.lat_field'), // or 'lat'
config('backpack.leaflet.lng_field') // or 'lng'
在您的控制器中调用它,如下所示,或者
// Add LeafletFields trait to your Crud Controller
use Backpack\Leafletjs\Http\Controllers\Admin\Traits\LeafletCrud;
// and call if your using App\Model\Settings model as your instance:
$this->setLeafletFields();
// to add default fields
或者在您希望显示它的 Crud 控制器中手动添加,如下所示。
$this->crud->addField([
'name' => 'leafletMapId', // this is not a name of field in database.
'type' => 'leaflet',
'model' => config('backpack.leaflet.model_name'), // you can modify under config folder or override by your own for each model
'options' => [
'provider' => 'mapbox', // default algolia map provider
'marker_image' => null // optional
],
'hint' => '<em>You can also drag and adjust your mark by clicking</em>'
]);
$this->crud->addField([
'name' => 'lat',
'type' => 'hidden',
'attributes' => ['id' => 'leafletMapId-lat'],
'tab' => 'General'
]);
$this->crud->addField([
'name' => 'lng',
'type' => 'hidden',
'attributes' => ['id' => 'leafletMapId-lng'],
'tab' => 'General'
]);
或
$this->crud->addField([
'name' => 'leafletMapId', // this is not a name of field in database.
'type' => 'leaflet',
'model' => config('backpack.leaflet.model_name'), // you can modify under config folder or override by your own for each model
'options' => [
'provider' => 'mapbox', // default algolia map provider
'marker_image' => null // optional
],
'autogenerate' => true, // if you dont want to create the fields in crud controller for lat and lng you specified, it generates himself.
' hint' => '<em>You can also drag and adjust your mark by clicking</em>'
]);
安全性
如果您发现任何与安全性相关的问题,请通过 info@siberfx.com 发送电子邮件,而不是使用问题跟踪器。