-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from Oneami/master
160. Add product attribute: country of origin
- Loading branch information
Showing
8 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/app/Admin/Controllers/ProductAttributes/CountryOfOriginController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace App\Admin\Controllers\ProductAttributes; | ||
|
||
use App\Models\ProductAttributes\CountryOfOrigin; | ||
use Encore\Admin\Controllers\AdminController; | ||
use Encore\Admin\Form; | ||
use Encore\Admin\Grid; | ||
use Encore\Admin\Show; | ||
|
||
class CountryOfOriginController extends AdminController | ||
{ | ||
/** | ||
* Title for current resource. | ||
* | ||
* @var string | ||
*/ | ||
protected $title = 'Страна производитель'; | ||
|
||
/** | ||
* Make a grid builder. | ||
* | ||
* @return Grid | ||
*/ | ||
protected function grid() | ||
{ | ||
$grid = new Grid(new CountryOfOrigin()); | ||
|
||
$grid->column('id', 'Id'); | ||
$grid->column('name', 'Название'); | ||
$grid->column('slug', 'Slug'); | ||
$grid->column('seo', 'Seo'); | ||
$grid->column('created_at', 'Дата создания')->display(fn () => date('d.m.Y H:i:s', strtotime($this->created_at))); | ||
$grid->column('updated_at', 'Дата обновления')->display(fn () => date('d.m.Y H:i:s', strtotime($this->updated_at))); | ||
|
||
$grid->disableFilter(); | ||
$grid->disableColumnSelector(); | ||
$grid->disableExport(); | ||
$grid->disableRowSelector(); | ||
|
||
return $grid; | ||
} | ||
|
||
/** | ||
* Make a show builder. | ||
* | ||
* @param mixed $id | ||
* @return Show | ||
*/ | ||
protected function detail($id) | ||
{ | ||
$show = new Show(CountryOfOrigin::findOrFail($id)); | ||
|
||
$show->field('id', 'Id'); | ||
$show->field('name', 'Название'); | ||
$show->field('slug', 'Slug'); | ||
$show->field('seo', 'Seo'); | ||
$show->field('created_at', 'Дата создания'); | ||
$show->field('updated_at', 'Дата обновления'); | ||
|
||
return $show; | ||
} | ||
|
||
/** | ||
* Make a form builder. | ||
* | ||
* @return Form | ||
*/ | ||
protected function form() | ||
{ | ||
$form = new Form(new CountryOfOrigin()); | ||
|
||
$form->text('name', 'Название'); | ||
$form->text('slug', 'Slug'); | ||
$form->textarea('seo', 'Seo'); | ||
|
||
$form->disableCreatingCheck(); | ||
$form->disableEditingCheck(); | ||
$form->disableViewCheck(); | ||
|
||
return $form; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Models\ProductAttributes; | ||
|
||
use App\Traits\AttributeFilterTrait; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\Str; | ||
|
||
/** | ||
* @property int $id | ||
* @property string $name | ||
* @property string $slug | ||
* @property string $seo | ||
*/ | ||
class CountryOfOrigin extends Model | ||
{ | ||
use AttributeFilterTrait, HasFactory; | ||
|
||
protected $guarded = ['id']; | ||
|
||
protected static function boot(): void | ||
{ | ||
parent::boot(); | ||
static::creating(function ($model) { | ||
$model->slug = $model->slug ? $model->slug : Str::slug($model->name); | ||
}); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/database/migrations/2023_11_23_232244_create_country_of_origins_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?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('country_of_origins', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('name'); | ||
$table->string('slug'); | ||
$table->text('seo')->nullable(); | ||
$table->timestamps(); | ||
}); | ||
|
||
Schema::table('products', function (Blueprint $table) { | ||
$table->foreignId('country_of_origin_id')->nullable()->constrained('country_of_origins')->nullOnDelete(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('products', function (Blueprint $table) { | ||
$table->dropForeign(['country_of_origin_id']); | ||
$table->dropColumn(['country_of_origin_id']); | ||
}); | ||
Schema::dropIfExists('country_of_origins'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters