generated from liutk/owl-admin-base
添加友情链接管理
parent
1fb02f9479
commit
57568e93ca
|
|
@ -17,7 +17,7 @@ DB_PASSWORD=
|
||||||
|
|
||||||
BROADCAST_DRIVER=log
|
BROADCAST_DRIVER=log
|
||||||
CACHE_DRIVER=file
|
CACHE_DRIVER=file
|
||||||
FILESYSTEM_DISK=local
|
FILESYSTEM_DISK=public
|
||||||
QUEUE_CONNECTION=sync
|
QUEUE_CONNECTION=sync
|
||||||
SESSION_DRIVER=file
|
SESSION_DRIVER=file
|
||||||
SESSION_LIFETIME=120
|
SESSION_LIFETIME=120
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
|
use Slowlyo\OwlAdmin\Admin;
|
||||||
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||||
|
use Slowlyo\OwlAdmin\Renderers\Form;
|
||||||
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||||
|
use App\Services\Admin\FriendLinkService;
|
||||||
|
use App\Admin\Components;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class FriendLinkController extends AdminController
|
||||||
|
{
|
||||||
|
protected string $serviceName = FriendLinkService::class;
|
||||||
|
|
||||||
|
public function list(): Page
|
||||||
|
{
|
||||||
|
$crud = $this->baseCRUD()
|
||||||
|
->headerToolbar([
|
||||||
|
$this->createButton(true, 'md'),
|
||||||
|
amis('reload')->align('right'),
|
||||||
|
amis('filter-toggler')->align('right'),
|
||||||
|
])
|
||||||
|
->filter($this->baseFilter()->body([
|
||||||
|
|
||||||
|
]
|
||||||
|
))
|
||||||
|
->columns([
|
||||||
|
amis()->TableColumn()->make()->name('id')->label('ID')->width('50px')->sortable(true),
|
||||||
|
amis()->TableColumn('name', __('admin.friend_links.name')),
|
||||||
|
amis()->TableColumn('uri', __('admin.friend_links.uri')),
|
||||||
|
amis()->TableColumn('cover', __('admin.friend_links.cover'))->type('image')->height('50px')->width('150px')->enlargeAble(true),
|
||||||
|
amis()->TableColumn('sort', __('admin.friend_links.sort')),
|
||||||
|
amis()->TableColumn('is_enable', __('admin.friend_links.is_enable'))->type('switch'),
|
||||||
|
amis()->TableColumn('created_at', __('admin.created_at'))->type('datetime')->sortable(true),
|
||||||
|
amisMake()->Operation()->label(__('admin.actions'))->buttons([
|
||||||
|
$this->rowEditButton(true, 'md'),
|
||||||
|
$this->rowDeleteButton(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->baseList($crud);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function form(): Form
|
||||||
|
{
|
||||||
|
return $this->baseForm()->body([
|
||||||
|
amis()->TextControl('name', __('admin.friend_links.name'))->required(true),
|
||||||
|
amis()->TextControl('uri', __('admin.friend_links.uri')),
|
||||||
|
Components::make()->cropImageControl('cover', __('admin.friend_links.cover')),
|
||||||
|
amis()->SwitchControl('is_enable', __('admin.friend_links.is_enable'))->value(true),
|
||||||
|
Components::make()->sortControl('sort', __('admin.friend_links.sort')),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -33,6 +33,8 @@ Route::group([
|
||||||
|
|
||||||
$router->resource('ads', \App\Admin\Controllers\AdController::class);
|
$router->resource('ads', \App\Admin\Controllers\AdController::class);
|
||||||
|
|
||||||
|
$router->resource('friend_links', \App\Admin\Controllers\FriendLinkController::class);
|
||||||
|
|
||||||
|
|
||||||
//数据管理
|
//数据管理
|
||||||
$router->resource('financial_cate', \App\Admin\Controllers\KeywordController::class);
|
$router->resource('financial_cate', \App\Admin\Controllers\KeywordController::class);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Filters;
|
||||||
|
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
use EloquentFilter\ModelFilter;
|
||||||
|
|
||||||
|
class FriendLinkFilter extends ModelFilter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
public function id($id)
|
||||||
|
{
|
||||||
|
return $this->where('id', $id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use EloquentFilter\Filterable;
|
||||||
|
|
||||||
|
class FriendLink extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
use Filterable;
|
||||||
|
|
||||||
|
protected function serializeDate(\DateTimeInterface $date)
|
||||||
|
{
|
||||||
|
return $date->format('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'name', 'uri', 'cover', 'is_enable', 'sort'
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Admin;
|
||||||
|
|
||||||
|
use App\Models\FriendLink;
|
||||||
|
use App\Models\Filters\FriendLinkFilter;
|
||||||
|
use App\Traits\UploadTrait;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method FriendLink getModel()
|
||||||
|
* @method FriendLink|\Illuminate\Database\Query\Builder query()
|
||||||
|
*/
|
||||||
|
class FriendLinkService extends BaseService
|
||||||
|
{
|
||||||
|
use UploadTrait;
|
||||||
|
|
||||||
|
protected string $modelName = FriendLink::class;
|
||||||
|
|
||||||
|
protected string $modelFilterName = FriendLinkFilter::class;
|
||||||
|
|
||||||
|
// protected bool $modelSortAble = true;
|
||||||
|
|
||||||
|
public function store($data): bool
|
||||||
|
{
|
||||||
|
$columns = $this->getTableColumns();
|
||||||
|
$model = $this->getModel();
|
||||||
|
|
||||||
|
$isEnable = Arr::get($data, 'is_enabled');
|
||||||
|
$publishedAt = Arr::get($data, 'published_at');
|
||||||
|
|
||||||
|
if(isset($data['cover'])){
|
||||||
|
$data['cover'] = $this->saveImage('cover', 'friend_links/cover')[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($data as $k => $v) {
|
||||||
|
if (!in_array($k, $columns)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$model->setAttribute($k, $v);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $model->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($primaryKey, $data): bool
|
||||||
|
{
|
||||||
|
$columns = $this->getTableColumns();
|
||||||
|
$model = $this->query()->whereKey($primaryKey)->first();
|
||||||
|
|
||||||
|
if(isset($data['cover'])){
|
||||||
|
$data['cover'] = $this->saveImage('cover', 'friend_links/cover')[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($data as $k => $v) {
|
||||||
|
if (!in_array($k, $columns)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$model->setAttribute($k, $v);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $model->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('friend_links', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name')->comment('名称');
|
||||||
|
$table->string('uri')->comment('链接地址');
|
||||||
|
|
||||||
|
$table->string('cover')->nullable()->comment('图片');
|
||||||
|
$table->unsignedTinyInteger('is_enable')->default(1)->comment('显示开关');
|
||||||
|
$table->unsignedInteger('sort')->default(0)->comment('排序');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('friend_links');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -34,7 +34,7 @@ class AdminMenuSeeder extends Seeder
|
||||||
['title' => 'web_content', 'icon' => 'ph:codesandbox-logo-light', 'url' => '/web_content', 'order'=>2,//网站管理
|
['title' => 'web_content', 'icon' => 'ph:codesandbox-logo-light', 'url' => '/web_content', 'order'=>2,//网站管理
|
||||||
'children' => [
|
'children' => [
|
||||||
['title'=>'ads', 'icon'=>'lets-icons:img-box','url'=>'/ads', 'order'=>0],
|
['title'=>'ads', 'icon'=>'lets-icons:img-box','url'=>'/ads', 'order'=>0],
|
||||||
|
['title'=>'friend_links', 'icon'=>'mdi:link-variant','url'=>'/friend_links', 'order'=>1],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
['title' => 'data_content', 'icon' => 'ph:codesandbox-logo-light', 'url' => '/data_content', 'order'=>3, //数据管理
|
['title' => 'data_content', 'icon' => 'ph:codesandbox-logo-light', 'url' => '/data_content', 'order'=>3, //数据管理
|
||||||
|
|
|
||||||
|
|
@ -319,5 +319,12 @@ return [
|
||||||
'person' => '负责人',
|
'person' => '负责人',
|
||||||
'person_id' => '负责人',
|
'person_id' => '负责人',
|
||||||
'sort' => '排序',
|
'sort' => '排序',
|
||||||
|
],
|
||||||
|
'friend_links' => [
|
||||||
|
'name' => '名称',
|
||||||
|
'uri' => '链接地址',
|
||||||
|
'cover'=> '图片',
|
||||||
|
'sort' => '排序',
|
||||||
|
'is_enable'=>'显示',
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -33,4 +33,5 @@ return [
|
||||||
'money_cate' => '收支类型',
|
'money_cate' => '收支类型',
|
||||||
'welfare_cate' => '福利类型',
|
'welfare_cate' => '福利类型',
|
||||||
'job_cate' => '工种管理',
|
'job_cate' => '工种管理',
|
||||||
|
'friend_links' => '友情链接',
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue