menus & translations ready

This commit is contained in:
merdan 2022-09-03 16:48:04 +05:00
parent 6d4bee4e14
commit 3c9bbbb392
8 changed files with 148 additions and 0 deletions

View File

@ -0,0 +1,60 @@
<?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('menus', function (Blueprint $table) {
$table->increments('id');
$table->integer('position')->default(0);
$table->boolean('status')->default(0);
$table->timestamps();
});
Schema::create('menu_brands',function (Blueprint $table) {
$table->integer('menu_id')->unsigned();
$table->integer('brand_id')->unsigned();
$table->foreign('menu_id')->references('id')->on('menus');
$table->foreign('brand_id')->references('id')->on('brands');
});
Schema::create('menu_categories',function (Blueprint $table) {
$table->integer('menu_id')->unsigned();
$table->integer('category_id')->unsigned();
$table->foreign('menu_id')->references('id')->on('menus');
$table->foreign('category_id')->references('id')->on('categories');
});
Schema::create('menu_translations',function (Blueprint $table) {
$table->increments('id');
$table->text('name');
$table->text('description')->nullable();
$table->integer('menu_id')->unsigned();
$table->string('locale');
$table->unique(['menu_id', 'locale']);
$table->foreign('menu_id')->references('id')->on('menus')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('menu_brands');
Schema::dropIfExists('menu_categories');
Schema::dropIfExists('menus_translations');
Schema::dropIfExists('menus');
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace Sarga\Shop\Contracts;
interface Menu
{
}

View File

@ -0,0 +1,8 @@
<?php
namespace Sarga\Shop\Contracts;
interface MenuTranslation
{
}

View File

@ -0,0 +1,34 @@
<?php
namespace Sarga\Shop\Models;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Sarga\Brand\Models\BrandProxy;
use Webkul\Category\Models\CategoryProxy;
use Webkul\Core\Eloquent\TranslatableModel;
use Sarga\Shop\Contracts\Menu as MenuContract;
class Menu extends TranslatableModel implements MenuContract
{
protected $fillable = [
'position',
'status',
'filter',
];
/**
* Eager loading.
*
* @var array
*/
protected $with = ['translations'];
public function brands() :BelongsToMany{
return $this->belongsToMany(BrandProxy::modelClass(),'menu_brands');
}
public function categories():BelongsToMany
{
return $this->belongsToMany(CategoryProxy::modelClass(), 'menu_categories');
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace Sarga\Shop\Models;
class MenuProxy extends \Konekt\Concord\Proxies\ModelProxy
{
}

View File

@ -0,0 +1,16 @@
<?php
namespace Sarga\Shop\Models;
use Illuminate\Database\Eloquent\Model;
use Sarga\Shop\Contracts\MenuTranslation as MenuTranslationContract;
class MenuTranslation extends Model implements MenuTranslationContract
{
public $timestamps = false;
protected $fillable = [
'name',
'description',
'locale_id',
];
}

View File

@ -8,5 +8,8 @@ class ModuleServiceProvider extends CoreModuleServiceProvider
{
protected $models = [
\Sarga\Shop\Models\Recipient::class,
\Sarga\Shop\Models\Menu::class,
\Sarga\Shop\Models\MenuTranslation::class,
];
}

View File

@ -0,0 +1,11 @@
<?php
namespace Sarga\Shop\Repositories;
use Webkul\Core\Eloquent\Repository;
class MenuRepository extends Repository
{
public function model(): string
{
return 'Sarga\Shop\Contracts\Menu';
}
}