first upload all files
This commit is contained in:
22
Modules/Tag/Config/assets.php
Normal file
22
Modules/Tag/Config/assets.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Define which assets will be available through the asset manager
|
||||
|--------------------------------------------------------------------------
|
||||
| These assets are registered on the asset manager
|
||||
*/
|
||||
'all_assets' => [
|
||||
'admin.tag.css' => ['module' => 'tag:admin/css/tag.css'],
|
||||
'admin.tag.js' => ['module' => 'tag:admin/js/tag.js'],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Define which default assets will always be included in your pages
|
||||
| through the asset pipeline
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'required_assets' => [],
|
||||
];
|
||||
10
Modules/Tag/Config/permissions.php
Normal file
10
Modules/Tag/Config/permissions.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'admin.tags' => [
|
||||
'index' => 'tag::permissions.index',
|
||||
'create' => 'tag::permissions.create',
|
||||
'edit' => 'tag::permissions.edit',
|
||||
'destroy' => 'tag::permissions.destroy',
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateTagsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('tags', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('slug')->unique();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('tags');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateTagTranslationsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('tag_translations', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('tag_id')->unsigned();
|
||||
$table->string('locale');
|
||||
$table->string('name');
|
||||
|
||||
$table->unique(['tag_id', 'locale']);
|
||||
$table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('tag_translations');
|
||||
}
|
||||
}
|
||||
96
Modules/Tag/Entities/Tag.php
Normal file
96
Modules/Tag/Entities/Tag.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Tag\Entities;
|
||||
|
||||
use Modules\Admin\Ui\AdminTable;
|
||||
use Modules\Support\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Modules\Product\Entities\Product;
|
||||
use Modules\Support\Eloquent\Sluggable;
|
||||
use Modules\Support\Eloquent\Translatable;
|
||||
|
||||
class Tag extends Model
|
||||
{
|
||||
use Translatable, Sluggable;
|
||||
|
||||
/**
|
||||
* The relations to eager load on every query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $with = ['translations'];
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* The attributes that are translatable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $translatedAttributes = ['name'];
|
||||
|
||||
/**
|
||||
* The attribute that will be slugged.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $slugAttribute = 'name';
|
||||
|
||||
/**
|
||||
* Get tag list.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function list()
|
||||
{
|
||||
return Cache::tags('tags')->rememberForever(md5('tags.list:' . locale()), function () {
|
||||
return self::all()->sortBy('name')->pluck('name', 'id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a tag by the given slug.
|
||||
*
|
||||
* @param string $slug
|
||||
* @return self
|
||||
*/
|
||||
public static function findBySlug($slug)
|
||||
{
|
||||
return self::where('slug', $slug)->firstOrNew([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get public url for tag products.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function url()
|
||||
{
|
||||
return route('tags.products.index', ['tag' => $this->slug]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get related products.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(Product::class, 'product_tags');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get table data for the resource
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function table()
|
||||
{
|
||||
return new AdminTable($this->query());
|
||||
}
|
||||
}
|
||||
15
Modules/Tag/Entities/TagTranslation.php
Normal file
15
Modules/Tag/Entities/TagTranslation.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Tag\Entities;
|
||||
|
||||
use Modules\Support\Eloquent\TranslationModel;
|
||||
|
||||
class TagTranslation extends TranslationModel
|
||||
{
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['name'];
|
||||
}
|
||||
40
Modules/Tag/Http/Controllers/Admin/TagController.php
Normal file
40
Modules/Tag/Http/Controllers/Admin/TagController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Tag\Http\Controllers\Admin;
|
||||
|
||||
use Modules\Tag\Entities\Tag;
|
||||
use Modules\Admin\Traits\HasCrudActions;
|
||||
use Modules\Tag\Http\Requests\SaveTagRequest;
|
||||
|
||||
class TagController
|
||||
{
|
||||
use HasCrudActions;
|
||||
|
||||
/**
|
||||
* Model for the resource.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Tag::class;
|
||||
|
||||
/**
|
||||
* Label of the resource.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'tag::tags.tag';
|
||||
|
||||
/**
|
||||
* View path of the resource.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewPath = 'tag::admin.tags';
|
||||
|
||||
/**
|
||||
* Form requests for the resource.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $validation = SaveTagRequest::class;
|
||||
}
|
||||
31
Modules/Tag/Http/Controllers/TagProductController.php
Normal file
31
Modules/Tag/Http/Controllers/TagProductController.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Tag\Http\Controllers;
|
||||
|
||||
use Modules\Tag\Entities\Tag;
|
||||
use Modules\Product\Entities\Product;
|
||||
use Modules\Product\Filters\ProductFilter;
|
||||
use Modules\Product\Http\Controllers\ProductSearch;
|
||||
|
||||
class TagProductController
|
||||
{
|
||||
use ProductSearch;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index($slug, Product $model, ProductFilter $productFilter)
|
||||
{
|
||||
request()->merge(['tag' => $slug]);
|
||||
|
||||
if (request()->expectsJson()) {
|
||||
return $this->searchProducts($model, $productFilter);
|
||||
}
|
||||
|
||||
return view('public.products.index', [
|
||||
'tagName' => Tag::findBySlug($slug)->name,
|
||||
]);
|
||||
}
|
||||
}
|
||||
25
Modules/Tag/Http/Requests/SaveTagRequest.php
Normal file
25
Modules/Tag/Http/Requests/SaveTagRequest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Tag\Http\Requests;
|
||||
|
||||
use Modules\Core\Http\Requests\Request;
|
||||
|
||||
class SaveTagRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Available attributes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $availableAttributes = 'tag::attributes';
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
23
Modules/Tag/Providers/TagServiceProvider.php
Normal file
23
Modules/Tag/Providers/TagServiceProvider.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Tag\Providers;
|
||||
|
||||
use Modules\Tag\Table\TagTabs;
|
||||
use Modules\Support\Traits\AddsAsset;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Modules\Admin\Ui\Facades\TabManager;
|
||||
|
||||
class TagServiceProvider extends ServiceProvider
|
||||
{
|
||||
use AddsAsset;
|
||||
|
||||
/**
|
||||
* Bootstrap the application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
TabManager::register('tags', TagTabs::class);
|
||||
}
|
||||
}
|
||||
6
Modules/Tag/Resources/lang/en/attributes.php
Normal file
6
Modules/Tag/Resources/lang/en/attributes.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => 'Name',
|
||||
'slug' => 'URL',
|
||||
];
|
||||
8
Modules/Tag/Resources/lang/en/permissions.php
Normal file
8
Modules/Tag/Resources/lang/en/permissions.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'index' => 'Index Tag',
|
||||
'create' => 'Create Tag',
|
||||
'edit' => 'Edit Tag',
|
||||
'destroy' => 'Delete Tag',
|
||||
];
|
||||
15
Modules/Tag/Resources/lang/en/tags.php
Normal file
15
Modules/Tag/Resources/lang/en/tags.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'tag' => 'Tag',
|
||||
'tags' => 'Tags',
|
||||
'table' => [
|
||||
'name' => 'Name',
|
||||
],
|
||||
'tabs' => [
|
||||
'group' => [
|
||||
'tag_information' => 'Tag Information',
|
||||
],
|
||||
'general' => 'General',
|
||||
],
|
||||
];
|
||||
18
Modules/Tag/Resources/views/admin/tags/create.blade.php
Normal file
18
Modules/Tag/Resources/views/admin/tags/create.blade.php
Normal file
@@ -0,0 +1,18 @@
|
||||
@extends('admin::layout')
|
||||
|
||||
@component('admin::components.page.header')
|
||||
@slot('title', trans('admin::resource.create', ['resource' => trans('tag::tags.tag')]))
|
||||
|
||||
<li><a href="{{ route('admin.tags.index') }}">{{ trans('tag::tags.tags') }}</a></li>
|
||||
<li class="active">{{ trans('admin::resource.create', ['resource' => trans('tag::tags.tag')]) }}</li>
|
||||
@endcomponent
|
||||
|
||||
@section('content')
|
||||
<form method="POST" action="{{ route('admin.tags.store') }}" class="form-horizontal" id="tag-create-form" novalidate>
|
||||
{{ csrf_field() }}
|
||||
|
||||
{!! $tabs->render(compact('tag')) !!}
|
||||
</form>
|
||||
@endsection
|
||||
|
||||
@include('tag::admin.tags.partials.shortcuts')
|
||||
20
Modules/Tag/Resources/views/admin/tags/edit.blade.php
Normal file
20
Modules/Tag/Resources/views/admin/tags/edit.blade.php
Normal file
@@ -0,0 +1,20 @@
|
||||
@extends('admin::layout')
|
||||
|
||||
@component('admin::components.page.header')
|
||||
@slot('title', trans('admin::resource.edit', ['resource' => trans('tag::tags.tag')]))
|
||||
@slot('subtitle', $tag->name)
|
||||
|
||||
<li><a href="{{ route('admin.tags.index') }}">{{ trans('tag::tags.tags') }}</a></li>
|
||||
<li class="active">{{ trans('admin::resource.edit', ['resource' => trans('tag::tags.tag')]) }}</li>
|
||||
@endcomponent
|
||||
|
||||
@section('content')
|
||||
<form method="POST" action="{{ route('admin.tags.update', $tag) }}" class="form-horizontal" id="tag-edit-form" novalidate>
|
||||
{{ csrf_field() }}
|
||||
{{ method_field('put') }}
|
||||
|
||||
{!! $tabs->render(compact('tag')) !!}
|
||||
</form>
|
||||
@endsection
|
||||
|
||||
@include('tag::admin.tags.partials.shortcuts')
|
||||
38
Modules/Tag/Resources/views/admin/tags/index.blade.php
Normal file
38
Modules/Tag/Resources/views/admin/tags/index.blade.php
Normal file
@@ -0,0 +1,38 @@
|
||||
@extends('admin::layout')
|
||||
|
||||
@component('admin::components.page.header')
|
||||
@slot('title', trans('tag::tags.tags'))
|
||||
|
||||
<li class="active">{{ trans('tag::tags.tags') }}</li>
|
||||
@endcomponent
|
||||
|
||||
@component('admin::components.page.index_table')
|
||||
@slot('buttons', ['create'])
|
||||
@slot('resource', 'tags')
|
||||
@slot('name', trans('tag::tags.tag'))
|
||||
|
||||
@component('admin::components.table')
|
||||
@slot('thead')
|
||||
<tr>
|
||||
@include('admin::partials.table.select_all')
|
||||
|
||||
<th>{{ trans('admin::admin.table.id') }}</th>
|
||||
<th>{{ trans('tag::tags.table.name') }}</th>
|
||||
<th data-sort>{{ trans('admin::admin.table.created') }}</th>
|
||||
</tr>
|
||||
@endslot
|
||||
@endcomponent
|
||||
@endcomponent
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
new DataTable('#tags-table .table', {
|
||||
columns: [
|
||||
{ data: 'checkbox', orderable: false, searchable: false, width: '3%' },
|
||||
{ data: 'id', width: '5%' },
|
||||
{ data: 'name', name: 'translations.name', orderable: false, defaultContent: '' },
|
||||
{ data: 'created', name: 'created_at', width: '30%' },
|
||||
],
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
@@ -0,0 +1,14 @@
|
||||
@push('shortcuts')
|
||||
<dl class="dl-horizontal">
|
||||
<dt><code>b</code></dt>
|
||||
<dd>{{ trans('admin::admin.shortcuts.back_to_index', ['name' => trans('tag::tags.tag')]) }}</dd>
|
||||
</dl>
|
||||
@endpush
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
keypressAction([
|
||||
{ key: 'b', route: "{{ route('admin.tags.index') }}" }
|
||||
]);
|
||||
</script>
|
||||
@endpush
|
||||
@@ -0,0 +1,9 @@
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
{{ Form::text('name', trans('tag::attributes.name'), $errors, $tag, ['required' => true]) }}
|
||||
|
||||
@if ($tag->exists)
|
||||
{{ Form::text('slug', trans('tag::attributes.slug'), $errors, $tag, ['required' => true]) }}
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
42
Modules/Tag/Routes/admin.php
Normal file
42
Modules/Tag/Routes/admin.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('tags', [
|
||||
'as' => 'admin.tags.index',
|
||||
'uses' => 'TagController@index',
|
||||
'middleware' => 'can:admin.tags.index',
|
||||
]);
|
||||
|
||||
Route::get('tags/create', [
|
||||
'as' => 'admin.tags.create',
|
||||
'uses' => 'TagController@create',
|
||||
'middleware' => 'can:admin.tags.create',
|
||||
]);
|
||||
|
||||
Route::post('tags', [
|
||||
'as' => 'admin.tags.store',
|
||||
'uses' => 'TagController@store',
|
||||
'middleware' => 'can:admin.tags.create',
|
||||
]);
|
||||
|
||||
Route::get('tags/{id}/edit', [
|
||||
'as' => 'admin.tags.edit',
|
||||
'uses' => 'TagController@edit',
|
||||
'middleware' => 'can:admin.tags.edit',
|
||||
]);
|
||||
|
||||
Route::put('tags/{id}', [
|
||||
'as' => 'admin.tags.update',
|
||||
'uses' => 'TagController@update',
|
||||
'middleware' => 'can:admin.tags.edit',
|
||||
]);
|
||||
|
||||
Route::delete('tags/{ids?}', [
|
||||
'as' => 'admin.tags.destroy',
|
||||
'uses' => 'TagController@destroy',
|
||||
'middleware' => 'can:admin.tags.destroy',
|
||||
]);
|
||||
|
||||
// append
|
||||
|
||||
5
Modules/Tag/Routes/public.php
Normal file
5
Modules/Tag/Routes/public.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('tags/{tag}/products', 'TagProductController@index')->name('tags.products.index');
|
||||
27
Modules/Tag/Sidebar/SidebarExtender.php
Normal file
27
Modules/Tag/Sidebar/SidebarExtender.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Tag\Sidebar;
|
||||
|
||||
use Maatwebsite\Sidebar\Item;
|
||||
use Maatwebsite\Sidebar\Menu;
|
||||
use Maatwebsite\Sidebar\Group;
|
||||
use Modules\Admin\Sidebar\BaseSidebarExtender;
|
||||
|
||||
class SidebarExtender extends BaseSidebarExtender
|
||||
{
|
||||
public function extend(Menu $menu)
|
||||
{
|
||||
$menu->group(trans('admin::sidebar.content'), function (Group $group) {
|
||||
$group->item(trans('product::sidebar.products'), function (Item $item) {
|
||||
$item->item(trans('tag::tags.tags'), function (Item $item) {
|
||||
$item->icon('fa fa-tag');
|
||||
$item->weight(27);
|
||||
$item->route('admin.tags.index');
|
||||
$item->authorize(
|
||||
$this->auth->hasAccess('admin.tags.index')
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
26
Modules/Tag/Table/TagTabs.php
Normal file
26
Modules/Tag/Table/TagTabs.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Tag\Table;
|
||||
|
||||
use Modules\Admin\Ui\Tab;
|
||||
use Modules\Admin\Ui\Tabs;
|
||||
|
||||
class TagTabs extends Tabs
|
||||
{
|
||||
public function make()
|
||||
{
|
||||
$this->group('tag_information', trans('tag::tags.tabs.group.tag_information'))
|
||||
->active()
|
||||
->add($this->general());
|
||||
}
|
||||
|
||||
private function general()
|
||||
{
|
||||
return tap(new Tab('general', trans('tag::tags.tabs.general')), function (Tab $tab) {
|
||||
$tab->active();
|
||||
$tab->weight(5);
|
||||
$tab->fields(['name']);
|
||||
$tab->view('tag::admin.tags.tabs.general');
|
||||
});
|
||||
}
|
||||
}
|
||||
27
Modules/Tag/composer.json
Normal file
27
Modules/Tag/composer.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "fleetcart/tag",
|
||||
"description": "The FleetCart Tag Module.",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Envay Soft",
|
||||
"email": "envaysoft@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^8.0.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\Tag\\": ""
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
9
Modules/Tag/module.json
Normal file
9
Modules/Tag/module.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "Tag",
|
||||
"alias": "tag",
|
||||
"description": "The FleetCart Tag Module.",
|
||||
"priority": 100,
|
||||
"providers": [
|
||||
"Modules\\Tag\\Providers\\TagServiceProvider"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user