Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
masters editing
Browse files Browse the repository at this point in the history
  • Loading branch information
i-jurij committed Jun 11, 2023
1 parent e2bf397 commit 3862013
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 48 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ As view - resources/other/service_page.blade.php
After creating service page you can add categories and services to page.
Also admin panel has items for creating and editing categories and services.

After creating the page - open files in your edoitor or IDE and edit.
After creating the page - open files in your editor or IDE and edit.
Also put route in routes/web.php.

table master_service:
master_id
service_id
4 changes: 2 additions & 2 deletions app/Http/Controllers/Client/AboutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public function index($content, $page_data = '', $method_and_params = '')
} else {
$masters = [];
/*
Masters::factory()
Master::factory()
->count(6)
->state(new Sequence(
['data_uvoln' => null],
['data_uvoln' => date('Y-m-d H:i:s', time())],
))
->create();
$masters = Masters::all()->toArray();
$masters = Master::all()->toArray();
*/
}

Expand Down
69 changes: 64 additions & 5 deletions app/Http/Controllers/Moder/MastersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Http\Controllers\Controller;
use App\Models\Master;
use App\Models\Page;
use App\Models\Service;
use Illuminate\Http\Request;

class MastersController extends Controller
Expand Down Expand Up @@ -34,7 +36,32 @@ public function index(Master $masters)
*/
public function create()
{
return view('admin_manikur.moder_pages.masters_create_form');
// get data from table services (id, page_id, categories_id, name)
// and from service-categories and pages (with service_page === 'yes')
// than in view we can display list of pages -> categories-> services and choose what you need
$services = [];
$services = Page::select('id', 'title')->where('service_page', 'yes')
->with('categories')
->with('services')
->get()
->toArray();

foreach ($services as $page) {
foreach ($page['categories'] as $cat) {
foreach ($page['services'] as $cat_serv) {
if ($cat_serv['category_id'] === $cat['id']) {
$data[$page['id'].'#'.$page['title']][$cat['id'].'#'.$cat['name']][$cat_serv['id']] = $cat_serv['name'];
}
}
}
foreach ($page['services'] as $serv) {
if (empty($serv['category_id'])) {
$data[$page['id'].'#'.$page['title']][$page['id'].'#page_serv'][$serv['id']] = $serv['name'];
}
}
}

return view('admin_manikur.moder_pages.masters_create_form', ['services' => $data]);
}

/**
Expand Down Expand Up @@ -63,16 +90,21 @@ public function store(Request $request, Master $masters)
'sec_name' => (!empty($request->sec_name)) ? $request->sec_name : null,
'master_fam' => $request->master_fam,
'master_phone_number' => $request->master_phone_number,
'spec' => $request->spec,
'spec' => '',
'data_priema' => (!empty($request->hired)) ? $request->hired : null,
'data_uvoln' => (!empty($request->data_uvoln)) ? $request->dismissed : null,
];

if (!empty($insert) && is_array($insert)) {
$masters->create($insert);
$master_create = $masters->create($insert);
$res['db'] = 'The data of master "'.$request->master_fam.'" has been stored in db.';
}

if (!empty($request->serv)) {
$serv = Service::find($request->serv);
$master_create->services()->attach($serv);
}

return view('admin_manikur.moder_pages.masters', ['res' => $res]);
}

Expand All @@ -89,9 +121,36 @@ public function show(Master $masters)
public function edit(Request $request, Master $masters)
{
// $res = $masters->where('id', $request->id)->get()->toArray();
$res = $masters->where('id', $request->id)->first()->toArray();
// $res = $masters->where('id', $request->id)->first()->toArray();
$master = $masters->find($request->id);
$data['master'] = $master->toArray();
$services = $master->services;
$page_serv = $services->each(function ($serv) {
if (isset($serv->category)) {
$serv->category->page;
} else {
$serv->page;
}
})->toArray();

foreach ($page_serv as $serv) {
if (!empty($serv['category']['page']['id'])) {
$page_id = $serv['category']['page']['id'];
}
if (!empty($serv['page']['id'])) {
$page_id = $serv['page']['id'];
}

$page_title = (!empty($serv['page']['title'])) ? $serv['page']['title'] : $serv['category']['page']['title'];

$category_id = (!empty($serv['category']['id'])) ? $serv['category']['id'] : $page_id;

$category_name = (!empty($serv['category']['name'])) ? $serv['category']['name'] : 'page_serv';

$data['services'][$page_id.'#'.$page_title][$category_id.'#'.$category_name][$serv['id']] = $serv['name'];
}

return view('admin_manikur.moder_pages.masters_edit', ['res' => $res]);
return view('admin_manikur.moder_pages.masters_edit', ['res' => $data]);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Master.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ class Master extends Model
'data_priema',
'data_uvoln',
];

public function services()
{
return $this->belongsToMany(Service::class);
}
}
5 changes: 5 additions & 0 deletions app/Models/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ public function page(): BelongsTo
{
return $this->belongsTo(Page::class);
}

public function masters()
{
return $this->belongsToMany(Master::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Masters>
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Master>
*/
class MastersFactory extends Factory
class MasterFactory extends Factory
{
/**
* Define the model's default state.
Expand All @@ -17,11 +17,11 @@ class MastersFactory extends Factory
public function definition(): array
{
return [
'master_name' => $this->faker->text(20),
'sec_name' => $this->faker->text(20),
'master_fam' => $this->faker->text(20),
'master_name' => $this->faker->word(),
'sec_name' => $this->faker->word(),
'master_fam' => $this->faker->word(),
'master_phone_number' => $this->faker->phoneNumber(),
'spec' => $this->faker->text(20),
// 'spec' => $this->faker->text(20),
'data_priema' => $this->faker->dateTime(),
];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
public $timestamps = false;

/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('master_service', function (Blueprint $table) {
$table->foreignId('master_id')->constrained();
$table->foreignId('service_id')->constrained();
$table->primary(['master_id', 'service_id']);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('master_service');
}
};
9 changes: 7 additions & 2 deletions resources/css/manikur.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
:root {
--bgcolor: #9F091F;
--bgcolor-content: #282C34;
--input_bgcolor: #3c4555;
--input_bgcolor: black;
--bgcolor-button-active: black;

--fontcolor-light: #E5B5BE;
Expand Down Expand Up @@ -147,6 +147,8 @@ textarea:valid {
border-bottom: 2px solid green;
}

.ankor:target {scroll-margin-top:6rem;}

.but_back {
background-color: #C3C3C3;
}
Expand Down Expand Up @@ -220,6 +222,9 @@ textarea:valid {
border: 2px solid var(--bgcolor);
}

.borderc {
border: 2px solid var(--bgcolor-content);
}
.selected_shad{
box-shadow: rgba(255, 0, 0, 0.9) 0px 0px 4px 4px;
}
Expand Down Expand Up @@ -632,7 +637,7 @@ a.gallery_a:hover img{
text-align: left;
}

.form-recall-main input,
.form-recall-main input:not(input[type=checkbox], input[type=button]),
.form-recall-main textarea {
margin: 0.3rem 0;
padding: 0.7rem;
Expand Down
Loading

0 comments on commit 3862013

Please sign in to comment.