first upload all files

This commit is contained in:
NW
2023-06-11 13:14:03 +01:00
parent f14dbc52b5
commit c08b36d1b6
1705 changed files with 106852 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
<?php
namespace Modules\Brand\Admin;
use Modules\Admin\Ui\AdminTable;
use Modules\Brand\Entities\Brand;
class BrandTable extends AdminTable
{
/**
* Make table response for the resource.
*
* @return \Illuminate\Http\JsonResponse
*/
public function make()
{
return $this->newTable()
->addColumn('logo', function (Brand $brand) {
return view('admin::partials.table.image', [
'file' => $brand->logo,
]);
});
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Modules\Brand\Admin;
use Modules\Admin\Ui\Tab;
use Modules\Admin\Ui\Tabs;
class BrandTabs extends Tabs
{
public function make()
{
$this->group('brand_information', trans('brand::brands.tabs.group.brand_information'))
->active()
->add($this->general())
->add($this->images())
->add($this->seo());
}
private function general()
{
return tap(new Tab('general', trans('brand::brands.tabs.general')), function (Tab $tab) {
$tab->active();
$tab->weight(5);
$tab->fields(['name']);
$tab->view('brand::admin.brands.tabs.general');
});
}
private function images()
{
if (! auth()->user()->hasAccess('admin.media.index')) {
return;
}
return tap(new Tab('images', trans('brand::brands.tabs.images')), function (Tab $tab) {
$tab->weight(10);
$tab->view('brand::admin.brands.tabs.images');
});
}
private function seo()
{
return tap(new Tab('seo', trans('brand::brands.tabs.seo')), function (Tab $tab) {
$tab->weight(15);
$tab->fields(['slug']);
$tab->view('brand::admin.brands.tabs.seo');
});
}
}

View File

@@ -0,0 +1,21 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Define which assets will be available through the asset manager
|--------------------------------------------------------------------------
| These assets are registered on the asset manager
*/
'all_assets' => [
'admin.brand.js' => ['module' => 'brand:admin/js/brand.js'],
],
/*
|--------------------------------------------------------------------------
| Define which default assets will always be included in your pages
| through the asset pipeline
|--------------------------------------------------------------------------
*/
'required_assets' => [],
];

View File

@@ -0,0 +1,10 @@
<?php
return [
'admin.brands' => [
'index' => 'brand::permissions.index',
'create' => 'brand::permissions.create',
'edit' => 'brand::permissions.edit',
'destroy' => 'brand::permissions.destroy',
],
];

View File

@@ -0,0 +1,33 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBrandsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('brands', function (Blueprint $table) {
$table->increments('id');
$table->string('slug')->unique();
$table->boolean('is_active');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('brands');
}
}

View File

@@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBrandTranslationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('brand_translations', function (Blueprint $table) {
$table->increments('id');
$table->integer('brand_id');
$table->string('locale');
$table->string('name');
$table->unique(['brand_id', 'locale']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('brand_translations');
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Modules\Brand\Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class BrandDatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
// $this->call("OthersTableSeeder");
}
}

View File

@@ -0,0 +1,138 @@
<?php
namespace Modules\Brand\Entities;
use Modules\Media\Entities\File;
use Modules\Brand\Admin\BrandTable;
use Modules\Support\Eloquent\Model;
use Modules\Media\Eloquent\HasMedia;
use Illuminate\Support\Facades\Cache;
use Modules\Product\Entities\Product;
use Modules\Meta\Eloquent\HasMetaData;
use Modules\Support\Eloquent\Sluggable;
use Modules\Support\Eloquent\Translatable;
class Brand extends Model
{
use Translatable, Sluggable, HasMedia, HasMetaData;
/**
* The relations to eager load on every query.
*
* @var array
*/
protected $with = ['translations'];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['slug', 'is_active'];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'is_active' => 'boolean',
];
/**
* The attributes that are translatable.
*
* @var array
*/
public $translatedAttributes = ['name'];
/**
* The attribute that will be slugged.
*
* @var string
*/
protected $slugAttribute = 'name';
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted()
{
static::addActiveGlobalScope();
}
/**
* Get public url for the brand.
*
* @return string
*/
public function url()
{
return route('brands.products.index', $this->slug);
}
/**
* Find a specific brand by the given slug.
*
* @param string $slug
* @return self
*/
public static function findBySlug($slug)
{
return self::where('slug', $slug)->firstOrNew([]);
}
/**
* Get brand list.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public static function list()
{
return Cache::tags('brands')->rememberForever(md5('brands.list:' . locale()), function () {
return self::all()->sortBy('name')->pluck('name', 'id');
});
}
/**
* Get the brand's logo.
*
* @return \Modules\Media\Entities\File
*/
public function getLogoAttribute()
{
return $this->files->where('pivot.zone', 'logo')->first() ?: new File;
}
/**
* Get the brand's banner.
*
* @return \Modules\Media\Entities\File
*/
public function getBannerAttribute()
{
return $this->files->where('pivot.zone', 'banner')->first() ?: new File;
}
/**
* Get related products.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function products()
{
return $this->hasMany(Product::class);
}
/**
* Get table data for the resource
*
* @return \Illuminate\Http\JsonResponse
*/
public function table()
{
return new BrandTable($this->newQuery()->withoutGlobalScope('active'));
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Modules\Brand\Entities;
use Modules\Support\Eloquent\TranslationModel;
class BrandTranslation extends TranslationModel
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name'];
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Modules\Brand\Http\Controllers\Admin;
use Modules\Brand\Entities\Brand;
use Modules\Admin\Traits\HasCrudActions;
use Modules\Brand\Http\Requests\SaveBrandRequest;
class BrandController
{
use HasCrudActions;
/**
* Model for the resource.
*
* @var string
*/
protected $model = Brand::class;
/**
* Label of the resource.
*
* @var string
*/
protected $label = 'brand::brands.brand';
/**
* View path of the resource.
*
* @var string
*/
protected $viewPath = 'brand::admin.brands';
/**
* Form requests for the resource.
*
* @var array
*/
protected $validation = SaveBrandRequest::class;
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Modules\Brand\Http\Controllers;
use Modules\Brand\Entities\Brand;
class BrandController
{
/**
* Display a listing of the resource.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('public.brands.index', [
'brands' => Brand::with('files')->get(),
]);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Modules\Brand\Http\Controllers;
use Modules\Brand\Entities\Brand;
use Modules\Product\Entities\Product;
use Modules\Product\Filters\ProductFilter;
use Modules\Product\Http\Controllers\ProductSearch;
class BrandProductController
{
use ProductSearch;
/**
* Display a listing of the resource.
*
* @param string $slug
* @param \Modules\Product\Entities\Product $model
* @param \Modules\Product\Filters\ProductFilter $productFilter
* @return \Illuminate\Http\Response
*/
public function index($slug, Product $model, ProductFilter $productFilter)
{
request()->merge(['brand' => $slug]);
if (request()->expectsJson()) {
return $this->searchProducts($model, $productFilter);
}
$brand = Brand::findBySlug($slug);
return view('public.products.index', [
'brandName' => $brand->name,
'brandBanner' => $brand->banner->path,
]);
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Modules\Brand\Http\Requests;
use Illuminate\Validation\Rule;
use Modules\Brand\Entities\Brand;
use Modules\Core\Http\Requests\Request;
class SaveBrandRequest extends Request
{
/**
* Available attributes.
*
* @var string
*/
protected $availableAttributes = 'brand::attributes';
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => ['required'],
'slug' => $this->getSlugRules(),
];
}
private function getSlugRules()
{
$rules = $this->route()->getName() === 'admin.brands.update'
? ['required']
: ['sometimes'];
$slug = Brand::withoutGlobalScope('active')->where('id', $this->id)->value('slug');
$rules[] = Rule::unique('brands', 'slug')->ignore($slug, 'slug');
return $rules;
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Modules\Brand\Providers;
use Modules\Brand\Admin\BrandTabs;
use Modules\Support\Traits\AddsAsset;
use Illuminate\Support\ServiceProvider;
use Modules\Admin\Ui\Facades\TabManager;
class BrandServiceProvider extends ServiceProvider
{
use AddsAsset;
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
TabManager::register('brands', BrandTabs::class);
$this->addAdminAssets('admin.brands.(create|edit)', [
'admin.media.css', 'admin.media.js', 'admin.brand.js',
]);
}
}

View File

@@ -0,0 +1 @@
window.admin.removeSubmitButtonOffsetOn('#images');

View File

@@ -0,0 +1,7 @@
<?php
return [
'name' => 'Name',
'slug' => 'URL',
'is_active' => 'Status',
];

View File

@@ -0,0 +1,23 @@
<?php
return [
'brand' => 'Brand',
'brands' => 'Brands',
'table' => [
'logo' => 'Logo',
'name' => 'Name',
],
'tabs' => [
'group' => [
'brand_information' => 'Brand Information',
],
'general' => 'General',
'seo' => 'SEO',
'images' => 'Images',
],
'form' => [
'enable_the_brand' => 'Enable the brand',
'logo' => 'Logo',
'banner' => 'Banner',
],
];

View File

@@ -0,0 +1,8 @@
<?php
return [
'index' => 'Index Brand',
'create' => 'Create Brand',
'edit' => 'Edit Brand',
'destroy' => 'Delete Brand',
];

View File

@@ -0,0 +1,18 @@
@extends('admin::layout')
@component('admin::components.page.header')
@slot('title', trans('admin::resource.create', ['resource' => trans('brand::brands.brand')]))
<li><a href="{{ route('admin.brands.index') }}">{{ trans('brand::brands.brands') }}</a></li>
<li class="active">{{ trans('admin::resource.create', ['resource' => trans('brand::brands.brand')]) }}</li>
@endcomponent
@section('content')
<form method="POST" action="{{ route('admin.brands.store') }}" class="form-horizontal" id="brand-create-form" novalidate>
{{ csrf_field() }}
{!! $tabs->render(compact('brand')) !!}
</form>
@endsection
@include('brand::admin.brands.partials.shortcuts')

View File

@@ -0,0 +1,20 @@
@extends('admin::layout')
@component('admin::components.page.header')
@slot('title', trans('admin::resource.edit', ['resource' => trans('brand::brands.brand')]))
@slot('subtitle', $brand->name)
<li><a href="{{ route('admin.brands.index') }}">{{ trans('brand::brands.brands') }}</a></li>
<li class="active">{{ trans('admin::resource.edit', ['resource' => trans('brand::brands.brand')]) }}</li>
@endcomponent
@section('content')
<form method="POST" action="{{ route('admin.brands.update', $brand) }}" class="form-horizontal" id="brand-edit-form" novalidate>
{{ csrf_field() }}
{{ method_field('put') }}
{!! $tabs->render(compact('brand')) !!}
</form>
@endsection
@include('brand::admin.brands.partials.shortcuts')

View File

@@ -0,0 +1,42 @@
@extends('admin::layout')
@component('admin::components.page.header')
@slot('title', trans('brand::brands.brands'))
<li class="active">{{ trans('brand::brands.brands') }}</li>
@endcomponent
@component('admin::components.page.index_table')
@slot('buttons', ['create'])
@slot('resource', 'brands')
@slot('name', trans('brand::brands.brand'))
@component('admin::components.table')
@slot('thead')
<tr>
@include('admin::partials.table.select_all')
<th>{{ trans('admin::admin.table.id') }}</th>
<th>{{ trans('brand::brands.table.logo') }}</th>
<th>{{ trans('brand::brands.table.name') }}</th>
<th>{{ trans('admin::admin.table.status') }}</th>
<th data-sort>{{ trans('admin::admin.table.created') }}</th>
</tr>
@endslot
@endcomponent
@endcomponent
@push('scripts')
<script>
new DataTable('#brands-table .table', {
columns: [
{ data: 'checkbox', orderable: false, searchable: false, width: '3%' },
{ data: 'id', width: '5%' },
{ data: 'logo', orderable: false, searchable: false, width: '10%' },
{ data: 'name', name: 'translations.name', orderable: false, defaultContent: '' },
{ data: 'status', name: 'is_active', searchable: false },
{ data: 'created', name: 'created_at' },
],
});
</script>
@endpush

View File

@@ -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('brand::brands.brand')]) }}</dd>
</dl>
@endpush
@push('scripts')
<script>
keypressAction([
{ key: 'b', route: "{{ route('admin.brands.index') }}" }
]);
</script>
@endpush

View File

@@ -0,0 +1,6 @@
<div class="row">
<div class="col-md-8">
{{ Form::text('name', trans('brand::attributes.name'), $errors, $brand, ['required' => true]) }}
{{ Form::checkbox('is_active', trans('brand::attributes.is_active'), trans('brand::brands.form.enable_the_brand'), $errors, $brand) }}
</div>
</div>

View File

@@ -0,0 +1,13 @@
@include('media::admin.image_picker.single', [
'title' => trans('brand::brands.form.logo'),
'inputName' => 'files[logo]',
'file' => $brand->logo,
])
<div class="media-picker-divider"></div>
@include('media::admin.image_picker.single', [
'title' => trans('brand::brands.form.banner'),
'inputName' => 'files[banner]',
'file' => $brand->banner,
])

View File

@@ -0,0 +1,5 @@
<div class="row">
<div class="col-md-8">
@include('meta::admin.meta_fields', ['entity' => $brand])
</div>
</div>

View File

@@ -0,0 +1,41 @@
<?php
use Illuminate\Support\Facades\Route;
Route::get('brands', [
'as' => 'admin.brands.index',
'uses' => 'BrandController@index',
'middleware' => 'can:admin.brands.index',
]);
Route::get('brands/create', [
'as' => 'admin.brands.create',
'uses' => 'BrandController@create',
'middleware' => 'can:admin.brands.create',
]);
Route::post('brands', [
'as' => 'admin.brands.store',
'uses' => 'BrandController@store',
'middleware' => 'can:admin.brands.create',
]);
Route::get('brands/{id}/edit', [
'as' => 'admin.brands.edit',
'uses' => 'BrandController@edit',
'middleware' => 'can:admin.brands.edit',
]);
Route::put('brands/{id}', [
'as' => 'admin.brands.update',
'uses' => 'BrandController@update',
'middleware' => 'can:admin.brands.edit',
]);
Route::delete('brands/{ids?}', [
'as' => 'admin.brands.destroy',
'uses' => 'BrandController@destroy',
'middleware' => 'can:admin.brands.destroy',
]);
// append

View File

@@ -0,0 +1,7 @@
<?php
use Illuminate\Support\Facades\Route;
Route::get('brands', 'BrandController@index')->name('brands.index');
Route::get('brands/{brand}/products', 'BrandProductController@index')->name('brands.products.index');

View File

@@ -0,0 +1,26 @@
<?php
namespace Modules\Brand\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('brand::brands.brands'), function (Item $item) {
$item->weight(12);
$item->route('admin.brands.index');
$item->authorize(
$this->auth->hasAccess('admin.brands.index')
);
});
});
});
}
}

View File

@@ -0,0 +1,27 @@
{
"name": "fleetcart/brand",
"description": "The FleetCart Brand Module.",
"authors": [
{
"name": "Envay Soft",
"email": "envaysoft@gmail.com"
}
],
"require": {
"php": "^8.0.2"
},
"autoload": {
"psr-4": {
"Modules\\Brand\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev"
}

View File

@@ -0,0 +1,9 @@
{
"name": "Brand",
"alias": "brand",
"description": "The FleetCart Brand Module.",
"priority": 100,
"providers": [
"Modules\\Brand\\Providers\\BrandServiceProvider"
]
}

View File

@@ -0,0 +1,3 @@
let mix = require('laravel-mix');
mix.js(`${__dirname}/Resources/assets/admin/js/main.js`, `${__dirname}/Assets/admin/js/brand.js`);