diff --git a/app/Http/Controllers/ReceptionScreenController.php b/app/Http/Controllers/ReceptionScreenController.php index c994785..2190d67 100644 --- a/app/Http/Controllers/ReceptionScreenController.php +++ b/app/Http/Controllers/ReceptionScreenController.php @@ -14,7 +14,7 @@ class ReceptionScreenController extends Controller { public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application { - $onlineDocuments = ReceptionScreen::all(); + $onlineDocuments = ReceptionScreen::all()->sortBy('position'); return view('admin-reception-screen.index', compact('onlineDocuments')); } diff --git a/app/Models/File.php b/app/Models/File.php new file mode 100644 index 0000000..9d1074d --- /dev/null +++ b/app/Models/File.php @@ -0,0 +1,24 @@ +belongsTo(ReceptionScreen::class); + } +} diff --git a/app/Models/ReceptionScreen.php b/app/Models/ReceptionScreen.php index f0d0a90..ae66db4 100644 --- a/app/Models/ReceptionScreen.php +++ b/app/Models/ReceptionScreen.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; class ReceptionScreen extends Model { @@ -12,8 +13,11 @@ class ReceptionScreen extends Model protected $fillable = [ 'id', 'name', - 'url', - 'parent', - 'children' + 'position' ]; + + public function files(): HasMany + { + return $this->hasMany('App\Models\File', 'reception_screen_id'); + } } diff --git a/database/migrations/2024_01_18_082251_create_reception_screens_table.php b/database/migrations/2024_01_18_082251_create_reception_screens_table.php index 5127218..0c25a1b 100644 --- a/database/migrations/2024_01_18_082251_create_reception_screens_table.php +++ b/database/migrations/2024_01_18_082251_create_reception_screens_table.php @@ -14,6 +14,7 @@ return new class extends Migration Schema::create('reception_screens', function (Blueprint $table) { $table->id(); $table->string('name'); + $table->integer('position'); $table->timestamps(); }); } diff --git a/database/migrations/2024_01_22_074748_create_file_table.php b/database/migrations/2024_01_22_074748_create_files_table.php similarity index 64% rename from database/migrations/2024_01_22_074748_create_file_table.php rename to database/migrations/2024_01_22_074748_create_files_table.php index 1e08781..40c2052 100644 --- a/database/migrations/2024_01_22_074748_create_file_table.php +++ b/database/migrations/2024_01_22_074748_create_files_table.php @@ -11,10 +11,13 @@ return new class extends Migration */ public function up(): void { - Schema::create('file', function (Blueprint $table) { + Schema::create('files', function (Blueprint $table) { $table->id(); $table->string('name'); + $table->string('description'); $table->string('url'); + $table->integer('position'); + $table->foreignId('reception_screen_id')->constrained('reception_screens'); $table->timestamps(); }); } @@ -24,6 +27,6 @@ return new class extends Migration */ public function down(): void { - Schema::dropIfExists('file'); + Schema::dropIfExists('files'); } }; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index e35b20d..c7ffdf3 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -21,7 +21,8 @@ class DatabaseSeeder extends Seeder 'password' => 123456 ]); $this->call([ - ReceptionScreenSeeder::class + ReceptionScreenSeeder::class, + FileSeeder::class ]); } } diff --git a/database/seeders/FileSeeder.php b/database/seeders/FileSeeder.php new file mode 100644 index 0000000..e09bf9a --- /dev/null +++ b/database/seeders/FileSeeder.php @@ -0,0 +1,44 @@ +insert([ + [ + 'name' => 'файл 1', + 'description' => 'description1', + 'url' => 'url/url1', + 'position' => 2, + 'reception_screen_id' => 1, + 'created_at' => Carbon::now(), + ], + [ + 'name' => 'файл 2', + 'description' => 'description2', + 'url' => 'url/url2', + 'position' => 3, + 'reception_screen_id' => 1, + 'created_at' => Carbon::now(), + ], + [ + 'name' => 'файл 3', + 'description' => 'description3', + 'url' => 'url/url3', + 'reception_screen_id' => 1, + 'position' => 1, + 'created_at' => Carbon::now(), + ] + ]); + } +} diff --git a/database/seeders/ReceptionScreenSeeder.php b/database/seeders/ReceptionScreenSeeder.php index cca647b..7d5d213 100644 --- a/database/seeders/ReceptionScreenSeeder.php +++ b/database/seeders/ReceptionScreenSeeder.php @@ -17,14 +17,17 @@ class ReceptionScreenSeeder extends Seeder DB::table('reception_screens')->insert([ [ 'name' => 'Пункт 1 с файлами', + 'position' => 2, 'created_at' => Carbon::now(), ], [ 'name' => 'Пункт 2 с файлами', + 'position' => 3, 'created_at' => Carbon::now(), ], [ 'name' => 'Пункт 3 с файлами', + 'position' => 1, 'created_at' => Carbon::now(), ] ]); diff --git a/resources/views/admin-reception-screen/index.blade.php b/resources/views/admin-reception-screen/index.blade.php index 523adda..2be2521 100644 --- a/resources/views/admin-reception-screen/index.blade.php +++ b/resources/views/admin-reception-screen/index.blade.php @@ -3,9 +3,21 @@ @foreach($onlineDocuments as $onlineDocument)