From c5c17f0d584fb7190f483827334df280508b4ebc Mon Sep 17 00:00:00 2001 From: aslan Date: Thu, 2 May 2024 16:54:51 +0300 Subject: [PATCH] work with databases --- app/Http/Controllers/LabelController.php | 3 +- database/factories/DepartmentFactory.php | 10 +------ database/factories/LabelFactory.php | 11 ++------ database/factories/NoteFactory.php | 13 +++------ database/factories/TaskFactory.php | 16 +++++------ database/factories/TaskStatusesFactory.php | 10 +------ database/factories/UserFactory.php | 14 ---------- .../0001_01_01_000000_create_users_table.php | 6 ---- .../0001_01_01_000001_create_cache_table.php | 6 ---- .../0001_01_01_000002_create_jobs_table.php | 6 ---- ...4_27_115330_create_task_statuses_table.php | 6 ---- .../2024_04_27_115604_create_labels_table.php | 6 ---- ..._04_27_121400_create_departments_table.php | 7 ----- .../2024_04_27_121447_create_tasks_table.php | 12 ++------ ...4_04_27_121448_create_label_task_table.php | 7 +---- ... 2024_04_27_121448_create_notes_table.php} | 8 ++---- ...24_04_27_121448_create_user_task_table.php | 22 +++++++++++++++ database/seeders/DatabaseSeeder.php | 2 ++ database/seeders/DepartmentSeeder.php | 24 +++++++++++++--- database/seeders/LabelSeeder.php | 24 +++++++++++++--- database/seeders/NoteSeeder.php | 27 +++++++++++++++--- resources/views/admin/labels/index.blade.php | 5 ++++ resources/views/admin/tasks/index.blade.php | 24 ++++++++++++++-- resources/views/layouts/layout.blade.php | 28 ++++++++++++++++++- routes/web.php | 10 +++++++ vite.config.js | 1 + 26 files changed, 175 insertions(+), 133 deletions(-) rename database/migrations/{2024_04_27_121446_create_notes_table.php => 2024_04_27_121448_create_notes_table.php} (81%) create mode 100644 database/migrations/2024_04_27_121448_create_user_task_table.php create mode 100644 resources/views/admin/labels/index.blade.php diff --git a/app/Http/Controllers/LabelController.php b/app/Http/Controllers/LabelController.php index 47b2c1c..9043ccf 100644 --- a/app/Http/Controllers/LabelController.php +++ b/app/Http/Controllers/LabelController.php @@ -13,7 +13,8 @@ class LabelController extends Controller */ public function index() { - // + $labels = Label::all(); + return view('admin.labels.index', compact('labels')); } /** diff --git a/database/factories/DepartmentFactory.php b/database/factories/DepartmentFactory.php index 78b3686..0a0347a 100644 --- a/database/factories/DepartmentFactory.php +++ b/database/factories/DepartmentFactory.php @@ -4,20 +4,12 @@ namespace Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; -/** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Department> - */ class DepartmentFactory extends Factory { - /** - * Define the model's default state. - * - * @return array - */ public function definition(): array { return [ - // + 'name' => fake()->name(), ]; } } diff --git a/database/factories/LabelFactory.php b/database/factories/LabelFactory.php index 7795e54..e4ddc35 100644 --- a/database/factories/LabelFactory.php +++ b/database/factories/LabelFactory.php @@ -4,20 +4,13 @@ namespace Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; -/** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Label> - */ class LabelFactory extends Factory { - /** - * Define the model's default state. - * - * @return array - */ public function definition(): array { return [ - // + 'name' => fake()->name(), + 'description' => fake()->text(), ]; } } diff --git a/database/factories/NoteFactory.php b/database/factories/NoteFactory.php index 7253862..0d74a48 100644 --- a/database/factories/NoteFactory.php +++ b/database/factories/NoteFactory.php @@ -4,20 +4,15 @@ namespace Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; -/** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Note> - */ class NoteFactory extends Factory { - /** - * Define the model's default state. - * - * @return array - */ public function definition(): array { return [ - // + 'name' => fake()->name(), + 'file' => fake()->name(), + 'description' => fake()->text(), + 'task_id' => 1, ]; } } diff --git a/database/factories/TaskFactory.php b/database/factories/TaskFactory.php index e463279..1ff1943 100644 --- a/database/factories/TaskFactory.php +++ b/database/factories/TaskFactory.php @@ -4,20 +4,18 @@ namespace Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; -/** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Task> - */ class TaskFactory extends Factory { - /** - * Define the model's default state. - * - * @return array - */ public function definition(): array { return [ - // + 'name' => fake()->name(), + 'file' => fake()->name(), + 'description' => fake()->text(), + 'parent_id' => 0, + 'status_id' => 1, + 'department_id' => 1, + 'created_by_id' => 1, ]; } } diff --git a/database/factories/TaskStatusesFactory.php b/database/factories/TaskStatusesFactory.php index d1b68e4..7dfcb8b 100644 --- a/database/factories/TaskStatusesFactory.php +++ b/database/factories/TaskStatusesFactory.php @@ -4,20 +4,12 @@ namespace Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; -/** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\TaskStatuses> - */ class TaskStatusesFactory extends Factory { - /** - * Define the model's default state. - * - * @return array - */ public function definition(): array { return [ - // + 'name' => fake()->name(), ]; } } diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 584104c..45a37d4 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -6,21 +6,10 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; -/** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User> - */ class UserFactory extends Factory { - /** - * The current password being used by the factory. - */ protected static ?string $password; - /** - * Define the model's default state. - * - * @return array - */ public function definition(): array { return [ @@ -32,9 +21,6 @@ class UserFactory extends Factory ]; } - /** - * Indicate that the model's email address should be unverified. - */ public function unverified(): static { return $this->state(fn (array $attributes) => [ diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/0001_01_01_000000_create_users_table.php index 05fb5d9..c987f53 100644 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ b/database/migrations/0001_01_01_000000_create_users_table.php @@ -6,9 +6,6 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - /** - * Run the migrations. - */ public function up(): void { Schema::create('users', function (Blueprint $table) { @@ -37,9 +34,6 @@ return new class extends Migration }); } - /** - * Reverse the migrations. - */ public function down(): void { Schema::dropIfExists('users'); diff --git a/database/migrations/0001_01_01_000001_create_cache_table.php b/database/migrations/0001_01_01_000001_create_cache_table.php index b9c106b..b8cabb3 100644 --- a/database/migrations/0001_01_01_000001_create_cache_table.php +++ b/database/migrations/0001_01_01_000001_create_cache_table.php @@ -6,9 +6,6 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - /** - * Run the migrations. - */ public function up(): void { Schema::create('cache', function (Blueprint $table) { @@ -24,9 +21,6 @@ return new class extends Migration }); } - /** - * Reverse the migrations. - */ public function down(): void { Schema::dropIfExists('cache'); diff --git a/database/migrations/0001_01_01_000002_create_jobs_table.php b/database/migrations/0001_01_01_000002_create_jobs_table.php index 425e705..a892371 100644 --- a/database/migrations/0001_01_01_000002_create_jobs_table.php +++ b/database/migrations/0001_01_01_000002_create_jobs_table.php @@ -6,9 +6,6 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - /** - * Run the migrations. - */ public function up(): void { Schema::create('jobs', function (Blueprint $table) { @@ -45,9 +42,6 @@ return new class extends Migration }); } - /** - * Reverse the migrations. - */ public function down(): void { Schema::dropIfExists('jobs'); diff --git a/database/migrations/2024_04_27_115330_create_task_statuses_table.php b/database/migrations/2024_04_27_115330_create_task_statuses_table.php index dd207e9..c1277a7 100644 --- a/database/migrations/2024_04_27_115330_create_task_statuses_table.php +++ b/database/migrations/2024_04_27_115330_create_task_statuses_table.php @@ -6,9 +6,6 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - /** - * Run the migrations. - */ public function up(): void { Schema::create('task_statuses', function (Blueprint $table) { @@ -18,9 +15,6 @@ return new class extends Migration }); } - /** - * Reverse the migrations. - */ public function down(): void { Schema::dropIfExists('task_statuses'); diff --git a/database/migrations/2024_04_27_115604_create_labels_table.php b/database/migrations/2024_04_27_115604_create_labels_table.php index b4a94f6..0f1eb32 100644 --- a/database/migrations/2024_04_27_115604_create_labels_table.php +++ b/database/migrations/2024_04_27_115604_create_labels_table.php @@ -6,9 +6,6 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - /** - * Run the migrations. - */ public function up(): void { Schema::create('labels', function (Blueprint $table) { @@ -19,9 +16,6 @@ return new class extends Migration }); } - /** - * Reverse the migrations. - */ public function down(): void { Schema::dropIfExists('labels'); diff --git a/database/migrations/2024_04_27_121400_create_departments_table.php b/database/migrations/2024_04_27_121400_create_departments_table.php index 5e6d61c..6f6c3e4 100644 --- a/database/migrations/2024_04_27_121400_create_departments_table.php +++ b/database/migrations/2024_04_27_121400_create_departments_table.php @@ -6,9 +6,6 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - /** - * Run the migrations. - */ public function up(): void { Schema::create('departments', function (Blueprint $table) { @@ -17,10 +14,6 @@ return new class extends Migration $table->timestamps(); }); } - - /** - * Reverse the migrations. - */ public function down(): void { Schema::dropIfExists('departments'); diff --git a/database/migrations/2024_04_27_121447_create_tasks_table.php b/database/migrations/2024_04_27_121447_create_tasks_table.php index 8f4f88d..13149e0 100644 --- a/database/migrations/2024_04_27_121447_create_tasks_table.php +++ b/database/migrations/2024_04_27_121447_create_tasks_table.php @@ -6,27 +6,21 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - /** - * Run the migrations. - */ public function up(): void { Schema::create('tasks', function (Blueprint $table) { $table->id(); $table->string('name', 255); + $table->bigInteger('parent_id'); $table->text('description')->nullable(); - $table->string('url', 255)->nullable(); + $table->string('file', 255)->nullable(); $table->foreignId('status_id')->constrained('task_statuses'); + $table->foreignId('department_id')->constrained('departments'); $table->foreignId('created_by_id')->constrained('users'); - $table->bigInteger('assigned_to_id')->nullable(); - $table->foreign('assigned_to_id')->references('id')->on('users'); $table->timestamps(); }); } - /** - * Reverse the migrations. - */ public function down(): void { Schema::dropIfExists('tasks'); diff --git a/database/migrations/2024_04_27_121448_create_label_task_table.php b/database/migrations/2024_04_27_121448_create_label_task_table.php index 9b5f0a6..2c659b3 100644 --- a/database/migrations/2024_04_27_121448_create_label_task_table.php +++ b/database/migrations/2024_04_27_121448_create_label_task_table.php @@ -6,9 +6,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - /** - * Run the migrations. - */ + public function up(): void { Schema::create('label_task', function (Blueprint $table) { @@ -18,9 +16,6 @@ return new class extends Migration }); } - /** - * Reverse the migrations. - */ public function down(): void { Schema::dropIfExists('label_task'); diff --git a/database/migrations/2024_04_27_121446_create_notes_table.php b/database/migrations/2024_04_27_121448_create_notes_table.php similarity index 81% rename from database/migrations/2024_04_27_121446_create_notes_table.php rename to database/migrations/2024_04_27_121448_create_notes_table.php index ed37f4e..e020393 100644 --- a/database/migrations/2024_04_27_121446_create_notes_table.php +++ b/database/migrations/2024_04_27_121448_create_notes_table.php @@ -6,22 +6,18 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - /** - * Run the migrations. - */ public function up(): void { Schema::create('notes', function (Blueprint $table) { $table->id(); $table->string('name', 255); $table->text('description')->nullable(); + $table->string('file', 255)->nullable(); + $table->foreignId('task_id')->constrained('tasks'); $table->timestamps(); }); } - /** - * Reverse the migrations. - */ public function down(): void { Schema::dropIfExists('notes'); diff --git a/database/migrations/2024_04_27_121448_create_user_task_table.php b/database/migrations/2024_04_27_121448_create_user_task_table.php new file mode 100644 index 0000000..e15dcec --- /dev/null +++ b/database/migrations/2024_04_27_121448_create_user_task_table.php @@ -0,0 +1,22 @@ +foreignId('task_id')->constrained('tasks'); + $table->foreignId('user_id')->constrained('users'); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('label_task'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index d01a0ef..4867042 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -5,6 +5,7 @@ namespace Database\Seeders; use App\Models\User; // use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\Hash; class DatabaseSeeder extends Seeder { @@ -18,6 +19,7 @@ class DatabaseSeeder extends Seeder User::factory()->create([ 'name' => 'Test User', 'email' => 'test@example.com', + 'password' => Hash::make('password'), ]); } } diff --git a/database/seeders/DepartmentSeeder.php b/database/seeders/DepartmentSeeder.php index 9828de1..2e806f4 100644 --- a/database/seeders/DepartmentSeeder.php +++ b/database/seeders/DepartmentSeeder.php @@ -2,16 +2,32 @@ namespace Database\Seeders; +use Carbon\Carbon; use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\DB; class DepartmentSeeder extends Seeder { - /** - * Run the database seeds. - */ public function run(): void { - // + DB::table('departments')->insert([ + [ + 'name' => 'отдел Разработки', + 'created_at' => Carbon::now(), + ], + [ + 'name' => 'отдел Технического обеспечения', + 'created_at' => Carbon::now(), + ], + [ + 'name' => 'отдел Кадров', + 'created_at' => Carbon::now(), + ], + [ + 'name' => 'Зарплатный отдел', + 'created_at' => Carbon::now(), + ], + ]); } } diff --git a/database/seeders/LabelSeeder.php b/database/seeders/LabelSeeder.php index 173f884..ff5ccef 100644 --- a/database/seeders/LabelSeeder.php +++ b/database/seeders/LabelSeeder.php @@ -2,16 +2,32 @@ namespace Database\Seeders; +use Carbon\Carbon; use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\DB; class LabelSeeder extends Seeder { - /** - * Run the database seeds. - */ public function run(): void { - // + DB::table('labels')->insert([ + [ + 'name' => 'разработка', + 'created_at' => Carbon::now(), + ], + [ + 'name' => 'приказ № 1000', + 'created_at' => Carbon::now(), + ], + [ + 'name' => 'Срочно', + 'created_at' => Carbon::now(), + ], + [ + 'name' => 'повышенный приоритет', + 'created_at' => Carbon::now(), + ], + ]); } } diff --git a/database/seeders/NoteSeeder.php b/database/seeders/NoteSeeder.php index d8dd85d..cb6d581 100644 --- a/database/seeders/NoteSeeder.php +++ b/database/seeders/NoteSeeder.php @@ -2,16 +2,35 @@ namespace Database\Seeders; +use Carbon\Carbon; use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\DB; class NoteSeeder extends Seeder { - /** - * Run the database seeds. - */ public function run(): void { - // + DB::table('notes')->insert([ + [ + 'name' => 'добавлен приказ', + 'description' => 'разработка', + 'file' => 'file1.pdf', + 'task_id' => 1, + 'created_at' => Carbon::now(), + ], + [ + 'name' => 'приказ № 1000', + 'created_at' => Carbon::now(), + ], + [ + 'name' => 'Срочно', + 'created_at' => Carbon::now(), + ], + [ + 'name' => 'повышенный приоритет', + 'created_at' => Carbon::now(), + ], + ]); } } diff --git a/resources/views/admin/labels/index.blade.php b/resources/views/admin/labels/index.blade.php new file mode 100644 index 0000000..106b50a --- /dev/null +++ b/resources/views/admin/labels/index.blade.php @@ -0,0 +1,5 @@ +@extends('layouts.layout') +@section('content') + +asdasdasd +@endsection diff --git a/resources/views/admin/tasks/index.blade.php b/resources/views/admin/tasks/index.blade.php index 0af1071..258065b 100644 --- a/resources/views/admin/tasks/index.blade.php +++ b/resources/views/admin/tasks/index.blade.php @@ -1,5 +1,25 @@ -@extends('layouts.app') +@extends('layouts.layout') @section('content') -asdasdasd + + + + + + + + + + + + + + + + + + + +
#отделЗадачаСтатусНазначилИсполнители
1MarkOtto@mdo
+ @endsection diff --git a/resources/views/layouts/layout.blade.php b/resources/views/layouts/layout.blade.php index 2f39ca7..47457c2 100644 --- a/resources/views/layouts/layout.blade.php +++ b/resources/views/layouts/layout.blade.php @@ -6,8 +6,34 @@ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> ToDo + @vite(['resources/sass/app.scss', 'resources/js/app.js']) -@yield('content') +
+ +
+
+ @yield('content') +
diff --git a/routes/web.php b/routes/web.php index 74bb7ca..f73fd30 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,9 @@ group(function () { Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy'); }); +Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () { + Route::resources([ + '/tasks' => TaskController::class, + '/labels' => LabelController::class, + '/task_statuses' => TaskStatusesController::class, + ]); +}); require __DIR__.'/auth.php'; diff --git a/vite.config.js b/vite.config.js index 89f26f5..06f0efb 100644 --- a/vite.config.js +++ b/vite.config.js @@ -5,6 +5,7 @@ export default defineConfig({ plugins: [ laravel({ input: [ + 'resources/sass/app.scss', 'resources/css/app.css', 'resources/js/app.js', ],