From bc974632eb04482e931c57ec806c2a8b3b22e53d Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Tue, 12 Apr 2016 20:22:32 +0100 Subject: [PATCH 01/34] lva-4: Removed the extra Id column from the views --- .../views/admin/data-management/clubs/create.blade.php | 7 ------- resources/views/admin/data-management/clubs/edit.blade.php | 7 ------- .../views/admin/data-management/clubs/index.blade.php | 3 +-- resources/views/admin/data-management/clubs/show.blade.php | 4 ++-- 4 files changed, 3 insertions(+), 18 deletions(-) diff --git a/resources/views/admin/data-management/clubs/create.blade.php b/resources/views/admin/data-management/clubs/create.blade.php index 16f90442..5a7b7597 100644 --- a/resources/views/admin/data-management/clubs/create.blade.php +++ b/resources/views/admin/data-management/clubs/create.blade.php @@ -8,13 +8,6 @@ {!! Form::open(['url' => 'admin/data-management/clubs', 'class' => 'form-horizontal']) !!} -
- {!! Form::label('id', 'Id: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::number('id', null, ['class' => 'form-control']) !!} - {!! $errors->first('id', '

:message

') !!} -
-
{!! Form::label('club', 'Club: ', ['class' => 'col-sm-3 control-label']) !!}
diff --git a/resources/views/admin/data-management/clubs/edit.blade.php b/resources/views/admin/data-management/clubs/edit.blade.php index 62126607..6327d663 100644 --- a/resources/views/admin/data-management/clubs/edit.blade.php +++ b/resources/views/admin/data-management/clubs/edit.blade.php @@ -12,13 +12,6 @@ 'class' => 'form-horizontal' ]) !!} -
- {!! Form::label('id', 'Id: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::number('id', null, ['class' => 'form-control']) !!} - {!! $errors->first('id', '

:message

') !!} -
-
{!! Form::label('club', 'Club: ', ['class' => 'col-sm-3 control-label']) !!}
diff --git a/resources/views/admin/data-management/clubs/index.blade.php b/resources/views/admin/data-management/clubs/index.blade.php index 509facd5..4dcf0253 100644 --- a/resources/views/admin/data-management/clubs/index.blade.php +++ b/resources/views/admin/data-management/clubs/index.blade.php @@ -8,7 +8,7 @@ - + @@ -17,7 +17,6 @@ {{-- */$x++;/* --}} - + + + @endforeach + +
S.NoIdClubActionsS.NoClubActions
{{ $x }}{{ $item->id }}{{ $item->club }} diff --git a/resources/views/admin/data-management/clubs/show.blade.php b/resources/views/admin/data-management/clubs/show.blade.php index d56c3137..03abee70 100644 --- a/resources/views/admin/data-management/clubs/show.blade.php +++ b/resources/views/admin/data-management/clubs/show.blade.php @@ -8,12 +8,12 @@ - + - +
ID. IdClubID.Club
{{ $club->id }} {{ $club->id }} {{ $club->club }} {{ $club->id }} {{ $club->club }}
From f92182e8f6202258334cb061b9d6e9e5cad07f12 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Tue, 12 Apr 2016 20:25:25 +0100 Subject: [PATCH 02/34] Fixed the header for the Id column in the crud generator views and the existing views for Seasons, Clubs and Venues --- resources/crud-generator/index.blade.stub | 2 +- resources/crud-generator/show.blade.stub | 2 +- resources/views/admin/data-management/clubs/index.blade.php | 2 +- resources/views/admin/data-management/clubs/show.blade.php | 2 +- resources/views/admin/data-management/seasons/index.blade.php | 2 +- resources/views/admin/data-management/seasons/show.blade.php | 2 +- resources/views/admin/data-management/venues/index.blade.php | 2 +- resources/views/admin/data-management/venues/show.blade.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/resources/crud-generator/index.blade.stub b/resources/crud-generator/index.blade.stub index 3cec958c..a789d7ff 100644 --- a/resources/crud-generator/index.blade.stub +++ b/resources/crud-generator/index.blade.stub @@ -8,7 +8,7 @@ - %%formHeadingHtml%% + %%formHeadingHtml%% diff --git a/resources/crud-generator/show.blade.stub b/resources/crud-generator/show.blade.stub index 2e64cdf6..4541f79f 100644 --- a/resources/crud-generator/show.blade.stub +++ b/resources/crud-generator/show.blade.stub @@ -8,7 +8,7 @@
S.NoActionsIdActions
- %%formHeadingHtml%% + %%formHeadingHtml%% diff --git a/resources/views/admin/data-management/clubs/index.blade.php b/resources/views/admin/data-management/clubs/index.blade.php index 4dcf0253..82f66744 100644 --- a/resources/views/admin/data-management/clubs/index.blade.php +++ b/resources/views/admin/data-management/clubs/index.blade.php @@ -8,7 +8,7 @@
ID.Id
- + diff --git a/resources/views/admin/data-management/clubs/show.blade.php b/resources/views/admin/data-management/clubs/show.blade.php index 03abee70..5b24b5db 100644 --- a/resources/views/admin/data-management/clubs/show.blade.php +++ b/resources/views/admin/data-management/clubs/show.blade.php @@ -8,7 +8,7 @@
S.NoClubActionsIdClubActions
- + diff --git a/resources/views/admin/data-management/seasons/index.blade.php b/resources/views/admin/data-management/seasons/index.blade.php index d1effce6..40a9695a 100644 --- a/resources/views/admin/data-management/seasons/index.blade.php +++ b/resources/views/admin/data-management/seasons/index.blade.php @@ -8,7 +8,7 @@
ID.ClubIdClub
- + diff --git a/resources/views/admin/data-management/seasons/show.blade.php b/resources/views/admin/data-management/seasons/show.blade.php index a1ddb52d..a8cecc83 100644 --- a/resources/views/admin/data-management/seasons/show.blade.php +++ b/resources/views/admin/data-management/seasons/show.blade.php @@ -8,7 +8,7 @@
S.NoSeasonActionsIdSeasonActions
- + diff --git a/resources/views/admin/data-management/venues/index.blade.php b/resources/views/admin/data-management/venues/index.blade.php index f6f67c15..e82cdffe 100644 --- a/resources/views/admin/data-management/venues/index.blade.php +++ b/resources/views/admin/data-management/venues/index.blade.php @@ -8,7 +8,7 @@
ID. SeasonId Season
- + diff --git a/resources/views/admin/data-management/venues/show.blade.php b/resources/views/admin/data-management/venues/show.blade.php index 06979660..f3d3c28f 100644 --- a/resources/views/admin/data-management/venues/show.blade.php +++ b/resources/views/admin/data-management/venues/show.blade.php @@ -8,7 +8,7 @@
S.NoVenueActionsIdVenueActions
- + From 66776a9a4197c30e17fa065afc162705069c7c59 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Wed, 13 Apr 2016 19:15:06 +0100 Subject: [PATCH 03/34] lva-6: Added CRUD for the Roles table --- .../Admin/DataManagement/RolesController.php | 117 ++++++++++++++++++ app/Http/breadcrumbs.php | 18 +++ app/Http/routes.php | 1 + app/Models/Role.php | 24 ++++ database/deployment/2016_04_13.sql | 9 ++ .../2016_04_13_190718_create_roles_table.php | 37 ++++++ .../admin/data-management/home.blade.php | 1 + .../data-management/roles/create.blade.php | 36 ++++++ .../data-management/roles/edit.blade.php | 40 ++++++ .../data-management/roles/index.blade.php | 46 +++++++ .../data-management/roles/show.blade.php | 23 ++++ 11 files changed, 352 insertions(+) create mode 100644 app/Http/Controllers/Admin/DataManagement/RolesController.php create mode 100644 app/Models/Role.php create mode 100644 database/deployment/2016_04_13.sql create mode 100644 database/migrations/2016_04_13_190718_create_roles_table.php create mode 100644 resources/views/admin/data-management/roles/create.blade.php create mode 100644 resources/views/admin/data-management/roles/edit.blade.php create mode 100644 resources/views/admin/data-management/roles/index.blade.php create mode 100644 resources/views/admin/data-management/roles/show.blade.php diff --git a/app/Http/Controllers/Admin/DataManagement/RolesController.php b/app/Http/Controllers/Admin/DataManagement/RolesController.php new file mode 100644 index 00000000..3df8dfec --- /dev/null +++ b/app/Http/Controllers/Admin/DataManagement/RolesController.php @@ -0,0 +1,117 @@ +validate($request, ['role' => 'required', ]); + + Role::create($request->all()); + + Flass::success(''Role added!'); + + return redirect('admin/data-management/roles'); + } + + /** + * Display the specified resource. + * + * @param int $id + * + * @return Response + */ + public function show($id) + { + $role = Role::findOrFail($id); + + return view('admin.data-management.roles.show', compact('role')); + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * + * @return Response + */ + public function edit($id) + { + $role = Role::findOrFail($id); + + return view('admin.data-management.roles.edit', compact('role')); + } + + /** + * Update the specified resource in storage. + * + * @param int $id + * + * @return Response + */ + public function update($id, Request $request) + { + $this->validate($request, ['role' => 'required', ]); + + $role = Role::findOrFail($id); + $role->update($request->all()); + + Flash::success('Role updated!'); + + return redirect('admin/data-management/roles'); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * + * @return Response + */ + public function destroy($id) + { + Role::destroy($id); + + Flash::success('Role deleted!'); + + return redirect('admin/data-management/roles'); + } + +} diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index db66c022..01f00bc6 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -85,4 +85,22 @@ Breadcrumbs::register('admin.data-management.venues.show', function($b) { $b->parent('admin.data-management.venues.index'); $b->push('View'); +}); + +// Data Management - Roles +Breadcrumbs::register('admin.data-management.roles.index', function($b) { + $b->parent('admin::dataManagement'); + $b->push('Roles', route('admin.data-management.roles.index')); +}); +Breadcrumbs::register('admin.data-management.roles.create', function($b) { + $b->parent('admin.data-management.roles.index'); + $b->push('Add', route('admin.data-management.roles.create')); +}); +Breadcrumbs::register('admin.data-management.roles.edit', function($b) { + $b->parent('admin.data-management.roles.index'); + $b->push('Edit'); +}); +Breadcrumbs::register('admin.data-management.roles.show', function($b) { + $b->parent('admin.data-management.roles.index'); + $b->push('View'); }); \ No newline at end of file diff --git a/app/Http/routes.php b/app/Http/routes.php index b7a4e792..62a68ef4 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -60,6 +60,7 @@ Route::resource('seasons', 'SeasonsController'); Route::resource('clubs', 'ClubsController'); Route::resource('venues', 'VenuesController'); + Route::resource('roles', 'RolesController'); }); }); }); diff --git a/app/Models/Role.php b/app/Models/Role.php new file mode 100644 index 00000000..ce5d1993 --- /dev/null +++ b/app/Models/Role.php @@ -0,0 +1,24 @@ +engine = 'InnoDB'; + + $table->increments('id'); + $table->string('role'); + + $table->timestamps(); + }); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('roles'); + } + +} diff --git a/resources/views/admin/data-management/home.blade.php b/resources/views/admin/data-management/home.blade.php index e2352ddc..42150d64 100644 --- a/resources/views/admin/data-management/home.blade.php +++ b/resources/views/admin/data-management/home.blade.php @@ -7,6 +7,7 @@ Seasons Clubs Venues + Roles diff --git a/resources/views/admin/data-management/roles/create.blade.php b/resources/views/admin/data-management/roles/create.blade.php new file mode 100644 index 00000000..c47ccddb --- /dev/null +++ b/resources/views/admin/data-management/roles/create.blade.php @@ -0,0 +1,36 @@ +@extends('layouts.app') + +@section('content') + +
+

Create New Role

+
+ + {!! Form::open(['url' => 'admin/data-management/roles', 'class' => 'form-horizontal']) !!} + +
+ {!! Form::label('role', 'Role: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('role', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('role', '

:message

') !!} +
+
+ + +
+
+ {!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::close() !!} + + @if ($errors->any()) +
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+ @endif +
+ +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/roles/edit.blade.php b/resources/views/admin/data-management/roles/edit.blade.php new file mode 100644 index 00000000..b711a6fa --- /dev/null +++ b/resources/views/admin/data-management/roles/edit.blade.php @@ -0,0 +1,40 @@ +@extends('layouts.app') + +@section('content') + +
+

Edit Role

+
+ + {!! Form::model($role, [ + 'method' => 'PATCH', + 'url' => ['admin/data-management/roles', $role->id], + 'class' => 'form-horizontal' + ]) !!} + +
+ {!! Form::label('role', 'Role: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('role', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('role', '

:message

') !!} +
+
+ + +
+
+ {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::close() !!} + + @if ($errors->any()) +
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+ @endif +
+ +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/roles/index.blade.php b/resources/views/admin/data-management/roles/index.blade.php new file mode 100644 index 00000000..6502ddf8 --- /dev/null +++ b/resources/views/admin/data-management/roles/index.blade.php @@ -0,0 +1,46 @@ +@extends('layouts.app') + +@section('content') + +
+

Roles Add New Role

+
+
ID. VenueId Venue
+ + + + + + + {{-- */$x=0;/* --}} + @foreach($roles as $item) + {{-- */$x++;/* --}} + + + + + + @endforeach + +
IdRoleActions
{{ $x }}{{ $item->role }} + + + / + {!! Form::open([ + 'method'=>'DELETE', + 'url' => ['admin/data-management/roles', $item->id], + 'style' => 'display:inline' + ]) !!} + {!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs', 'data-toggle' => 'confirmation']) !!} + {!! Form::close() !!} +
+ + + + +@endsection + +@section('javascript') + + +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/roles/show.blade.php b/resources/views/admin/data-management/roles/show.blade.php new file mode 100644 index 00000000..e24294fd --- /dev/null +++ b/resources/views/admin/data-management/roles/show.blade.php @@ -0,0 +1,23 @@ +@extends('layouts.app') + +@section('content') + +
+

Role

+
+ + + + + + + + + + + +
Id Role
{{ $role->id }} {{ $role->role }}
+
+
+ +@endsection \ No newline at end of file From 03bd3dc2539131f0ea3ee0d3da2359300cfa8359 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Wed, 13 Apr 2016 19:16:30 +0100 Subject: [PATCH 04/34] Reformatting the first two SQL deployment scripts --- database/deployment/2016_02_13.sql | 34 +++++++++++++++++++++++++----- database/deployment/2016_04_03.sql | 10 ++++++++- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/database/deployment/2016_02_13.sql b/database/deployment/2016_02_13.sql index 871e02c7..a22fff25 100644 --- a/database/deployment/2016_02_13.sql +++ b/database/deployment/2016_02_13.sql @@ -1,5 +1,29 @@ -create table `users` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) not null, `email` varchar(255) not null, `password` varchar(60) not null, `remember_token` varchar(100) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8 collate utf8_unicode_ci engine = InnoDB; -alter table `users` add unique `users_email_unique`(`email`); -create table `password_resets` (`email` varchar(255) not null, `token` varchar(255) not null, `created_at` timestamp not null) default character set utf8 collate utf8_unicode_ci engine = InnoDB; -alter table `password_resets` add index `password_resets_email_index`(`email`); -alter table `password_resets` add index `password_resets_token_index`(`token`); +CREATE TABLE `users` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(255) NOT NULL, + `email` VARCHAR(255) NOT NULL, + `password` VARCHAR(60) NOT NULL, + `remember_token` VARCHAR(100) NULL, + `created_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL +) + DEFAULT CHARACTER SET utf8 + COLLATE utf8_unicode_ci + ENGINE = InnoDB; + +ALTER TABLE `users` + ADD UNIQUE `users_email_unique`(`email`); + +CREATE TABLE `password_resets` ( + `email` VARCHAR(255) NOT NULL, + `token` VARCHAR(255) NOT NULL, + `created_at` TIMESTAMP NOT NULL +) + DEFAULT CHARACTER SET utf8 + COLLATE utf8_unicode_ci + ENGINE = InnoDB; + +ALTER TABLE `password_resets` + ADD INDEX `password_resets_email_index`(`email`); +ALTER TABLE `password_resets` + ADD INDEX `password_resets_token_index`(`token`); diff --git a/database/deployment/2016_04_03.sql b/database/deployment/2016_04_03.sql index 9b84b95e..482dba4f 100644 --- a/database/deployment/2016_04_03.sql +++ b/database/deployment/2016_04_03.sql @@ -1 +1,9 @@ -create table `seasons` (`id` int unsigned not null auto_increment primary key, `season` varchar(255) not null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8 collate utf8_unicode_ci engine = InnoDB; \ No newline at end of file +CREATE TABLE `seasons` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `season` VARCHAR(255) NOT NULL, + `created_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL +) + DEFAULT CHARACTER SET utf8 + COLLATE utf8_unicode_ci + ENGINE = InnoDB; \ No newline at end of file From 5fe5bb704b731c0927bdf6a03976d81859738c9d Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Wed, 13 Apr 2016 20:05:37 +0100 Subject: [PATCH 05/34] lva-7 Added initial CRUD from the Divisions table --- .../DataManagement/DivisionsController.php | 117 ++++++++++++++++++ app/Http/breadcrumbs.php | 18 +++ app/Http/routes.php | 1 + app/Models/Division.php | 24 ++++ ...16_04_13_193513_create_divisions_table.sql | 13 ++ ...16_04_13_193513_create_divisions_table.php | 42 +++++++ .../divisions/create.blade.php | 43 +++++++ .../data-management/divisions/edit.blade.php | 47 +++++++ .../data-management/divisions/index.blade.php | 46 +++++++ .../data-management/divisions/show.blade.php | 23 ++++ .../admin/data-management/home.blade.php | 1 + 11 files changed, 375 insertions(+) create mode 100644 app/Http/Controllers/Admin/DataManagement/DivisionsController.php create mode 100644 app/Models/Division.php create mode 100644 database/deployment/2016_04_13_193513_create_divisions_table.sql create mode 100644 database/migrations/2016_04_13_193513_create_divisions_table.php create mode 100644 resources/views/admin/data-management/divisions/create.blade.php create mode 100644 resources/views/admin/data-management/divisions/edit.blade.php create mode 100644 resources/views/admin/data-management/divisions/index.blade.php create mode 100644 resources/views/admin/data-management/divisions/show.blade.php diff --git a/app/Http/Controllers/Admin/DataManagement/DivisionsController.php b/app/Http/Controllers/Admin/DataManagement/DivisionsController.php new file mode 100644 index 00000000..34e9f683 --- /dev/null +++ b/app/Http/Controllers/Admin/DataManagement/DivisionsController.php @@ -0,0 +1,117 @@ +validate($request, ['division' => 'required', ]); + + Division::create($request->all()); + + Flash::success('Division added!'); + + return redirect('admin/data-management/divisions'); + } + + /** + * Display the specified resource. + * + * @param int $id + * + * @return Response + */ + public function show($id) + { + $division = Division::findOrFail($id); + + return view('admin.data-management.divisions.show', compact('division')); + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * + * @return Response + */ + public function edit($id) + { + $division = Division::findOrFail($id); + + return view('admin.data-management.divisions.edit', compact('division')); + } + + /** + * Update the specified resource in storage. + * + * @param int $id + * + * @return Response + */ + public function update($id, Request $request) + { + $this->validate($request, ['division' => 'required', ]); + + $division = Division::findOrFail($id); + $division->update($request->all()); + + Flash::success('Division updated!'); + + return redirect('admin/data-management/divisions'); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * + * @return Response + */ + public function destroy($id) + { + Division::destroy($id); + + Flash::success('Division deleted!'); + + return redirect('admin/data-management/divisions'); + } + +} diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index 01f00bc6..57d36379 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -103,4 +103,22 @@ Breadcrumbs::register('admin.data-management.roles.show', function($b) { $b->parent('admin.data-management.roles.index'); $b->push('View'); +}); + +// Data Management - Divisions +Breadcrumbs::register('admin.data-management.divisions.index', function($b) { + $b->parent('admin::dataManagement'); + $b->push('Divisions', route('admin.data-management.divisions.index')); +}); +Breadcrumbs::register('admin.data-management.divisions.create', function($b) { + $b->parent('admin.data-management.divisions.index'); + $b->push('Add', route('admin.data-management.divisions.create')); +}); +Breadcrumbs::register('admin.data-management.divisions.edit', function($b) { + $b->parent('admin.data-management.divisions.index'); + $b->push('Edit'); +}); +Breadcrumbs::register('admin.data-management.divisions.show', function($b) { + $b->parent('admin.data-management.divisions.index'); + $b->push('View'); }); \ No newline at end of file diff --git a/app/Http/routes.php b/app/Http/routes.php index 62a68ef4..80e087a7 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -61,6 +61,7 @@ Route::resource('clubs', 'ClubsController'); Route::resource('venues', 'VenuesController'); Route::resource('roles', 'RolesController'); + Route::resource('divisions', 'DivisionsController'); }); }); }); diff --git a/app/Models/Division.php b/app/Models/Division.php new file mode 100644 index 00000000..bf4da78d --- /dev/null +++ b/app/Models/Division.php @@ -0,0 +1,24 @@ +engine = 'InnoDB'; + + $table->increments('id'); + $table->integer('season_id')->unsigned(); + $table->string('division'); + $table->timestamps(); + + $table->foreign('season_id')->references('id')->on('seasons'); + }); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('divisions', function (Blueprint $table) { + $table->dropForeign(['season_id']); + }); + Schema::drop('divisions'); + } + +} diff --git a/resources/views/admin/data-management/divisions/create.blade.php b/resources/views/admin/data-management/divisions/create.blade.php new file mode 100644 index 00000000..b9e734f7 --- /dev/null +++ b/resources/views/admin/data-management/divisions/create.blade.php @@ -0,0 +1,43 @@ +@extends('layouts.app') + +@section('content') + +
+

Create New Division

+
+ + {!! Form::open(['url' => 'admin/data-management/divisions', 'class' => 'form-horizontal']) !!} + +
+ {!! Form::label('season_id', 'Season Id: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::number('season_id', null, ['class' => 'form-control']) !!} + {!! $errors->first('season_id', '

:message

') !!} +
+
+
+ {!! Form::label('division', 'Division: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('division', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('division', '

:message

') !!} +
+
+ + +
+
+ {!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::close() !!} + + @if ($errors->any()) +
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+ @endif +
+ +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/divisions/edit.blade.php b/resources/views/admin/data-management/divisions/edit.blade.php new file mode 100644 index 00000000..c8a92c70 --- /dev/null +++ b/resources/views/admin/data-management/divisions/edit.blade.php @@ -0,0 +1,47 @@ +@extends('layouts.app') + +@section('content') + +
+

Edit Division

+
+ + {!! Form::model($division, [ + 'method' => 'PATCH', + 'url' => ['admin/data-management/divisions', $division->id], + 'class' => 'form-horizontal' + ]) !!} + +
+ {!! Form::label('season_id', 'Season Id: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::number('season_id', null, ['class' => 'form-control']) !!} + {!! $errors->first('season_id', '

:message

') !!} +
+
+
+ {!! Form::label('division', 'Division: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('division', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('division', '

:message

') !!} +
+
+ + +
+
+ {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::close() !!} + + @if ($errors->any()) +
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+ @endif +
+ +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/divisions/index.blade.php b/resources/views/admin/data-management/divisions/index.blade.php new file mode 100644 index 00000000..e5cd07ac --- /dev/null +++ b/resources/views/admin/data-management/divisions/index.blade.php @@ -0,0 +1,46 @@ +@extends('layouts.app') + +@section('content') + +
+

Divisions Add New Division

+
+ + + + + + + + {{-- */$x=0;/* --}} + @foreach($divisions as $item) + {{-- */$x++;/* --}} + + + + + + @endforeach + +
IdSeason IdDivisionActions
{{ $x }}{{ $item->season_id }}{{ $item->division }} + + + / + {!! Form::open([ + 'method'=>'DELETE', + 'url' => ['admin/data-management/divisions', $item->id], + 'style' => 'display:inline' + ]) !!} + {!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs', 'data-toggle' => 'confirmation']) !!} + {!! Form::close() !!} +
+ +
+
+ +@endsection + +@section('javascript') + + +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/divisions/show.blade.php b/resources/views/admin/data-management/divisions/show.blade.php new file mode 100644 index 00000000..0c6556c2 --- /dev/null +++ b/resources/views/admin/data-management/divisions/show.blade.php @@ -0,0 +1,23 @@ +@extends('layouts.app') + +@section('content') + +
+

Division

+
+ + + + + + + + + + + +
Id Season IdDivision
{{ $division->id }} {{ $division->season_id }} {{ $division->division }}
+
+
+ +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/home.blade.php b/resources/views/admin/data-management/home.blade.php index 42150d64..e9f96328 100644 --- a/resources/views/admin/data-management/home.blade.php +++ b/resources/views/admin/data-management/home.blade.php @@ -8,6 +8,7 @@ Clubs Venues Roles + Divisions From b347bc6c6b9c63dcefcab9d82651f75fa35c826f Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Wed, 13 Apr 2016 20:06:25 +0100 Subject: [PATCH 06/34] dev: Fixed (again) the crud generator template for the controller --- resources/crud-generator/controller.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/crud-generator/controller.stub b/resources/crud-generator/controller.stub index 97263d14..11de270b 100644 --- a/resources/crud-generator/controller.stub +++ b/resources/crud-generator/controller.stub @@ -45,7 +45,7 @@ class DummyClass extends Controller {{validationRules}} {{modelName}}::create($request->all()); - Flass::success(''{{modelName}} added!'); + Flash::success('{{modelName}} added!'); return redirect('{{routeGroup}}{{crudName}}'); } From f3ddbd49ff840cb8a763324db2f7d2c4109f794f Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Wed, 13 Apr 2016 21:10:23 +0100 Subject: [PATCH 07/34] dev: Various fixes to the CRUD --- app/Http/Controllers/Admin/DataManagement/ClubsController.php | 3 ++- app/Http/Controllers/Admin/DataManagement/RolesController.php | 3 ++- app/Http/Controllers/Admin/DataManagement/VenuesController.php | 3 ++- resources/crud-generator/controller.stub | 1 + resources/views/admin/data-management/clubs/index.blade.php | 1 + 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Admin/DataManagement/ClubsController.php b/app/Http/Controllers/Admin/DataManagement/ClubsController.php index b3692c07..4cd80b2f 100644 --- a/app/Http/Controllers/Admin/DataManagement/ClubsController.php +++ b/app/Http/Controllers/Admin/DataManagement/ClubsController.php @@ -9,6 +9,7 @@ use Illuminate\Http\Request; use Carbon\Carbon; use Session; +use Laracasts\Flash\Flash; class ClubsController extends Controller { @@ -45,7 +46,7 @@ public function store(Request $request) Club::create($request->all()); - Flass::success('Club added!'); + Flash::success('Club added!'); return redirect('admin/data-management/clubs'); } diff --git a/app/Http/Controllers/Admin/DataManagement/RolesController.php b/app/Http/Controllers/Admin/DataManagement/RolesController.php index 3df8dfec..cebc4b3b 100644 --- a/app/Http/Controllers/Admin/DataManagement/RolesController.php +++ b/app/Http/Controllers/Admin/DataManagement/RolesController.php @@ -9,6 +9,7 @@ use Illuminate\Http\Request; use Carbon\Carbon; use Session; +use Laracasts\Flash\Flash; class RolesController extends Controller { @@ -46,7 +47,7 @@ public function store(Request $request) Role::create($request->all()); - Flass::success(''Role added!'); + Flash::success('Role added!'); return redirect('admin/data-management/roles'); } diff --git a/app/Http/Controllers/Admin/DataManagement/VenuesController.php b/app/Http/Controllers/Admin/DataManagement/VenuesController.php index 246b7cd0..dc3ac228 100644 --- a/app/Http/Controllers/Admin/DataManagement/VenuesController.php +++ b/app/Http/Controllers/Admin/DataManagement/VenuesController.php @@ -9,6 +9,7 @@ use Illuminate\Http\Request; use Carbon\Carbon; use Session; +use Laracasts\Flash\Flash; class VenuesController extends Controller { @@ -45,7 +46,7 @@ public function store(Request $request) Venue::create($request->all()); - Flass::success('Venue added!'); + Flash::success('Venue added!'); return redirect('admin/data-management/venues'); } diff --git a/resources/crud-generator/controller.stub b/resources/crud-generator/controller.stub index 11de270b..467c8e06 100644 --- a/resources/crud-generator/controller.stub +++ b/resources/crud-generator/controller.stub @@ -9,6 +9,7 @@ use DummyRootNamespaceModels\{{modelName}}; use Illuminate\Http\Request; use Carbon\Carbon; use Session; +use Laracasts\Flash\Flash; class DummyClass extends Controller { diff --git a/resources/views/admin/data-management/clubs/index.blade.php b/resources/views/admin/data-management/clubs/index.blade.php index 82f66744..0a8cf4f2 100644 --- a/resources/views/admin/data-management/clubs/index.blade.php +++ b/resources/views/admin/data-management/clubs/index.blade.php @@ -17,6 +17,7 @@ {{-- */$x++;/* --}}
{{ $x }}{{ $item->club }} From 73fed5f9ad60e4799f73e077f411592a9cb25481 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Thu, 14 Apr 2016 18:33:11 +0100 Subject: [PATCH 08/34] lva-7 Fixed use of foreign key for hte CRUD of Divisions --- .../Admin/DataManagement/DivisionsController.php | 10 +++++++--- app/Models/Division.php | 4 ++++ app/Models/Season.php | 4 ++++ .../admin/data-management/divisions/create.blade.php | 4 ++-- .../admin/data-management/divisions/edit.blade.php | 4 ++-- .../admin/data-management/divisions/index.blade.php | 5 +++-- .../admin/data-management/divisions/show.blade.php | 4 ++-- 7 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Admin/DataManagement/DivisionsController.php b/app/Http/Controllers/Admin/DataManagement/DivisionsController.php index 34e9f683..43bfdb69 100644 --- a/app/Http/Controllers/Admin/DataManagement/DivisionsController.php +++ b/app/Http/Controllers/Admin/DataManagement/DivisionsController.php @@ -9,6 +9,9 @@ use Illuminate\Http\Request; use Carbon\Carbon; use Session; +use Laracasts\Flash\Flash; + +use App\Models\Season; class DivisionsController extends Controller { @@ -32,7 +35,7 @@ public function index() */ public function create() { - return view('admin.data-management.divisions.create'); + return view('admin.data-management.divisions.create', ['seasons' => Season::all()]); } /** @@ -42,7 +45,7 @@ public function create() */ public function store(Request $request) { - $this->validate($request, ['division' => 'required', ]); + $this->validate($request, ['season_id' => 'required', 'division' => 'required']); Division::create($request->all()); @@ -75,8 +78,9 @@ public function show($id) public function edit($id) { $division = Division::findOrFail($id); + $seasons = Season::all(); - return view('admin.data-management.divisions.edit', compact('division')); + return view('admin.data-management.divisions.edit', compact('division', 'seasons')); } /** diff --git a/app/Models/Division.php b/app/Models/Division.php index bf4da78d..0847ede9 100644 --- a/app/Models/Division.php +++ b/app/Models/Division.php @@ -21,4 +21,8 @@ class Division extends Model */ protected $fillable = ['season_id', 'division']; + public function season() + { + return $this->belongsTo('App\Models\Season'); + } } diff --git a/app/Models/Season.php b/app/Models/Season.php index 50704285..a3c669b4 100644 --- a/app/Models/Season.php +++ b/app/Models/Season.php @@ -21,4 +21,8 @@ class Season extends Model */ protected $fillable = ['season']; + public function divisions() + { + return $this->hasMany('App\Models\Division'); + } } diff --git a/resources/views/admin/data-management/divisions/create.blade.php b/resources/views/admin/data-management/divisions/create.blade.php index b9e734f7..fd413be4 100644 --- a/resources/views/admin/data-management/divisions/create.blade.php +++ b/resources/views/admin/data-management/divisions/create.blade.php @@ -9,9 +9,9 @@ {!! Form::open(['url' => 'admin/data-management/divisions', 'class' => 'form-horizontal']) !!}
- {!! Form::label('season_id', 'Season Id: ', ['class' => 'col-sm-3 control-label']) !!} + {!! Form::label('season_id', 'Season: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::number('season_id', null, ['class' => 'form-control']) !!} + {!! Form::select('season_id', array_column($seasons->toArray(), 'season', 'id'), null, ['class' => 'form-control']) !!} {!! $errors->first('season_id', '

:message

') !!}
diff --git a/resources/views/admin/data-management/divisions/edit.blade.php b/resources/views/admin/data-management/divisions/edit.blade.php index c8a92c70..470abe2e 100644 --- a/resources/views/admin/data-management/divisions/edit.blade.php +++ b/resources/views/admin/data-management/divisions/edit.blade.php @@ -13,9 +13,9 @@ ]) !!}
- {!! Form::label('season_id', 'Season Id: ', ['class' => 'col-sm-3 control-label']) !!} + {!! Form::label('season_id', 'Season: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::number('season_id', null, ['class' => 'form-control']) !!} + {!! Form::select('season_id', array_column($seasons->toArray(), 'season', 'id'), null, ['class' => 'form-control']) !!} {!! $errors->first('season_id', '

:message

') !!}
diff --git a/resources/views/admin/data-management/divisions/index.blade.php b/resources/views/admin/data-management/divisions/index.blade.php index e5cd07ac..72903ace 100644 --- a/resources/views/admin/data-management/divisions/index.blade.php +++ b/resources/views/admin/data-management/divisions/index.blade.php @@ -8,7 +8,7 @@ - + @@ -17,7 +17,8 @@ {{-- */$x++;/* --}} - + + +
IdSeason IdDivisionActionsIdSeasonDivisionActions
{{ $x }}{{ $item->season_id }}{{ $item->division }}{{ $item->season->season }}{{ $item->division }} diff --git a/resources/views/admin/data-management/divisions/show.blade.php b/resources/views/admin/data-management/divisions/show.blade.php index 0c6556c2..2d856b9c 100644 --- a/resources/views/admin/data-management/divisions/show.blade.php +++ b/resources/views/admin/data-management/divisions/show.blade.php @@ -8,12 +8,12 @@ - + - +
Id Season IdDivisionId SeasonDivision
{{ $division->id }} {{ $division->season_id }} {{ $division->division }} {{ $division->id }} {{ $division->season->season }} {{ $division->division }}
From ee262bbd417a005efb66375e2139c91863b809e5 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Thu, 14 Apr 2016 18:35:45 +0100 Subject: [PATCH 09/34] dev: Removed spurious modal popup for delte confirmation --- .../data-management/seasons/index.blade.php | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/resources/views/admin/data-management/seasons/index.blade.php b/resources/views/admin/data-management/seasons/index.blade.php index 40a9695a..1008fcfd 100644 --- a/resources/views/admin/data-management/seasons/index.blade.php +++ b/resources/views/admin/data-management/seasons/index.blade.php @@ -38,29 +38,6 @@ - - - - @endsection @section('javascript') From 99fd5aac595960d189b3ab64c84a9d7b29be413a Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Thu, 14 Apr 2016 18:38:40 +0100 Subject: [PATCH 10/34] dev: Removed the Id column from the data management index views as it was not the id in the table but just an row counter --- resources/crud-generator/index.blade.stub | 5 +---- .../views/admin/data-management/divisions/index.blade.php | 5 +---- resources/views/admin/data-management/roles/index.blade.php | 5 +---- .../views/admin/data-management/seasons/index.blade.php | 5 +---- resources/views/admin/data-management/venues/index.blade.php | 5 +---- 5 files changed, 5 insertions(+), 20 deletions(-) diff --git a/resources/crud-generator/index.blade.stub b/resources/crud-generator/index.blade.stub index a789d7ff..2263cac3 100644 --- a/resources/crud-generator/index.blade.stub +++ b/resources/crud-generator/index.blade.stub @@ -8,15 +8,12 @@ - %%formHeadingHtml%% + %%formHeadingHtml%% - {{-- */$x=0;/* --}} @foreach($%%crudName%% as $item) - {{-- */$x++;/* --}} - %%formBodyHtml%% +
IdActionsActions
{{ $x }} diff --git a/resources/views/admin/data-management/divisions/index.blade.php b/resources/views/admin/data-management/divisions/index.blade.php index 72903ace..9a93eda8 100644 --- a/resources/views/admin/data-management/divisions/index.blade.php +++ b/resources/views/admin/data-management/divisions/index.blade.php @@ -8,15 +8,12 @@ - + < - {{-- */$x=0;/* --}} @foreach($divisions as $item) - {{-- */$x++;/* --}} - + + @endforeach + +
IdSeasonDivisionActionsSeasonDivisionActions
{{ $x }} {{ $item->season->season }} {{ $item->division }} diff --git a/resources/views/admin/data-management/roles/index.blade.php b/resources/views/admin/data-management/roles/index.blade.php index 6502ddf8..2fb99794 100644 --- a/resources/views/admin/data-management/roles/index.blade.php +++ b/resources/views/admin/data-management/roles/index.blade.php @@ -8,15 +8,12 @@ - + - {{-- */$x=0;/* --}} @foreach($roles as $item) - {{-- */$x++;/* --}} - +
IdRoleActionsRoleActions
{{ $x }} {{ $item->role }} diff --git a/resources/views/admin/data-management/seasons/index.blade.php b/resources/views/admin/data-management/seasons/index.blade.php index 1008fcfd..69e7f96d 100644 --- a/resources/views/admin/data-management/seasons/index.blade.php +++ b/resources/views/admin/data-management/seasons/index.blade.php @@ -8,15 +8,12 @@ - + - {{-- */$x=0;/* --}} @foreach($seasons as $item) - {{-- */$x++;/* --}} - - - - + + + - + - - - + + +
IdSeasonActionsSeasonActions
{{ $x }} {{ $item->season }} diff --git a/resources/views/admin/data-management/venues/index.blade.php b/resources/views/admin/data-management/venues/index.blade.php index e82cdffe..80f1cb46 100644 --- a/resources/views/admin/data-management/venues/index.blade.php +++ b/resources/views/admin/data-management/venues/index.blade.php @@ -8,15 +8,12 @@ - + - {{-- */$x=0;/* --}} @foreach($venues as $item) - {{-- */$x++;/* --}} - - - + + diff --git a/resources/views/admin/data-management/fixtures/show.blade.php b/resources/views/admin/data-management/fixtures/show.blade.php index b25d16a4..e77d9e35 100644 --- a/resources/views/admin/data-management/fixtures/show.blade.php +++ b/resources/views/admin/data-management/fixtures/show.blade.php @@ -25,8 +25,8 @@ - - + + From 0f0eefe13968385322d2dd9a97f330b119847a29 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sat, 23 Apr 2016 13:10:44 +0100 Subject: [PATCH 15/34] lva-9: Fixed the deletion of teams (if fixtures do not exist) --- .../Admin/DataManagement/TeamsController.php | 3 ++- app/Models/Fixture.php | 4 +--- app/Models/Team.php | 11 ++++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Admin/DataManagement/TeamsController.php b/app/Http/Controllers/Admin/DataManagement/TeamsController.php index fa94c0f0..9c2147a5 100644 --- a/app/Http/Controllers/Admin/DataManagement/TeamsController.php +++ b/app/Http/Controllers/Admin/DataManagement/TeamsController.php @@ -110,7 +110,8 @@ public function update($id, Request $request) */ public function destroy($id) { - $canBeDeleted = empty(Team::find($id)->fixtures->toArray()); + $team = Team::find($id); + $canBeDeleted = empty($team->homeFixtures->toArray()) && empty($team->awayFixtures->toArray()); if ($canBeDeleted) { Team::destroy($id); Flash::success('Team deleted!'); diff --git a/app/Models/Fixture.php b/app/Models/Fixture.php index 43001d30..3043cac1 100644 --- a/app/Models/Fixture.php +++ b/app/Models/Fixture.php @@ -30,9 +30,7 @@ class Fixture extends Model 'away_team_id', 'venue_id' ]; - - protected $dates = ['match_date']; - + public function division() { return $this->belongsTo('App\Models\Division'); diff --git a/app/Models/Team.php b/app/Models/Team.php index eafb88c5..7055a80b 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -25,9 +25,14 @@ public function club() { return $this->belongsTo('App\Models\Club'); } - - public function fixtures() + + public function awayFixtures() + { + return $this->hasMany('App\Models\Fixture', 'away_team_id'); + } + + public function homeFixtures() { - return $this->hasMany('App\Models\Fixture'); + return $this->hasMany('App\Models\Fixture', 'home_team_id'); } } From ff055e52e3ba180c9c72832e204b0a185300629c Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Thu, 28 Apr 2016 20:32:50 +0100 Subject: [PATCH 16/34] lva-10 Added CRUD for Available Appointments --- .../AvailableAppointmentsController.php | 123 ++++++++++++++++++ .../Requests/AvailableAppointmentRequest.php | 44 +++++++ app/Http/breadcrumbs.php | 18 +++ app/Http/routes.php | 1 + app/Models/AvailableAppointment.php | 33 +++++ app/Models/Club.php | 5 + app/Models/Division.php | 5 + app/Models/Fixture.php | 14 ++ app/Models/Role.php | 9 ++ app/Models/Season.php | 5 + app/Models/Team.php | 5 + app/Models/Venue.php | 5 + ...53_create_available_appointments_table.sql | 18 +++ ...53_create_available_appointments_table.php | 40 ++++++ .../available-appointments/create.blade.php | 50 +++++++ .../available-appointments/edit.blade.php | 57 ++++++++ .../available-appointments/index.blade.php | 51 ++++++++ .../available-appointments/show.blade.php | 27 ++++ .../data-management/fixtures/create.blade.php | 2 +- .../data-management/fixtures/index.blade.php | 8 +- .../data-management/fixtures/show.blade.php | 8 +- .../admin/data-management/home.blade.php | 3 + 22 files changed, 522 insertions(+), 9 deletions(-) create mode 100644 app/Http/Controllers/Admin/DataManagement/AvailableAppointmentsController.php create mode 100644 app/Http/Requests/AvailableAppointmentRequest.php create mode 100644 app/Models/AvailableAppointment.php create mode 100644 database/deployment/2016_04_23_144453_create_available_appointments_table.sql create mode 100644 database/migrations/2016_04_23_144453_create_available_appointments_table.php create mode 100644 resources/views/admin/data-management/available-appointments/create.blade.php create mode 100644 resources/views/admin/data-management/available-appointments/edit.blade.php create mode 100644 resources/views/admin/data-management/available-appointments/index.blade.php create mode 100644 resources/views/admin/data-management/available-appointments/show.blade.php diff --git a/app/Http/Controllers/Admin/DataManagement/AvailableAppointmentsController.php b/app/Http/Controllers/Admin/DataManagement/AvailableAppointmentsController.php new file mode 100644 index 00000000..e6e0b898 --- /dev/null +++ b/app/Http/Controllers/Admin/DataManagement/AvailableAppointmentsController.php @@ -0,0 +1,123 @@ +all()); + + Flash::success('Appointment added!'); + + return redirect('admin/data-management/available-appointments'); + } + + /** + * Display the specified resource. + * + * @param int $id + * + * @return Response + */ + public function show($id) + { + $availableAppointment = AvailableAppointment::findOrFail($id); + + return view('admin.data-management.available-appointments.show', compact('availableAppointment')); + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * + * @return Response + */ + public function edit($id) + { + $availableAppointment = AvailableAppointment::findOrFail($id); + + $fixtures = Fixture::all(); + $roles = Role::all(); + + return view('admin.data-management.available-appointments.edit', compact('availableAppointment', 'fixtures', 'roles')); + } + + /** + * Update the specified resource in storage. + * + * @param Requests\AvailableAppointmentRequest $request + * @param int $id + * + * @return Response + */ + public function update(Requests\AvailableAppointmentRequest $request, $id) + { + $availableAppointment = AvailableAppointment::findOrFail($id); + $availableAppointment->update($request->all()); + + Flash::success('Appointment updated!'); + + return redirect('admin/data-management/available-appointments'); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * + * @return Response + */ + public function destroy($id) + { + AvailableAppointment::destroy($id); + + Flash::success('Appointment deleted!'); + + return redirect('admin/data-management/available-appointments'); + } + +} diff --git a/app/Http/Requests/AvailableAppointmentRequest.php b/app/Http/Requests/AvailableAppointmentRequest.php new file mode 100644 index 00000000..4503bebe --- /dev/null +++ b/app/Http/Requests/AvailableAppointmentRequest.php @@ -0,0 +1,44 @@ + 'unique:available_appointments,fixture_id,NULL,id,role_id,' . $this->input('role_id'), + 'role_id' => 'unique:available_appointments,role_id,NULL,id,fixture_id,' . $this->input('fixture_id'), + ]; + } + + /** + * {@inheritdoc} + */ + protected function formatErrors(Validator $validator) + { + return [[ + 'Appointment already added.', + ]]; + } + + +} diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index 8147266d..a1e3c356 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -157,4 +157,22 @@ Breadcrumbs::register('admin.data-management.fixtures.show', function($b) { $b->parent('admin.data-management.fixtures.index'); $b->push('View'); +}); + +// Data Management - Available Appointments +Breadcrumbs::register('admin.data-management.available-appointments.index', function ($b) { + $b->parent('admin::dataManagement'); + $b->push('Available appointments', route('admin.data-management.available-appointments.index')); +}); +Breadcrumbs::register('admin.data-management.available-appointments.create', function ($b) { + $b->parent('admin.data-management.available-appointments.index'); + $b->push('Add', route('admin.data-management.available-appointments.create')); +}); +Breadcrumbs::register('admin.data-management.available-appointments.edit', function ($b) { + $b->parent('admin.data-management.available-appointments.index'); + $b->push('Edit'); +}); +Breadcrumbs::register('admin.data-management.available-appointments.show', function ($b) { + $b->parent('admin.data-management.available-appointments.index'); + $b->push('View'); }); \ No newline at end of file diff --git a/app/Http/routes.php b/app/Http/routes.php index fcebd240..eeb330ed 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -64,6 +64,7 @@ Route::resource('divisions', 'DivisionsController'); Route::resource('teams', 'TeamsController'); Route::resource('fixtures', 'FixturesController'); + Route::resource('available-appointments', 'AvailableAppointmentsController'); }); }); }); diff --git a/app/Models/AvailableAppointment.php b/app/Models/AvailableAppointment.php new file mode 100644 index 00000000..c359a1b4 --- /dev/null +++ b/app/Models/AvailableAppointment.php @@ -0,0 +1,33 @@ +belongsTo('App\Models\Fixture'); + } + + public function role() + { + return $this->belongsTo('App\Models\Role'); + } +} diff --git a/app/Models/Club.php b/app/Models/Club.php index cd5b3236..5fa42b1d 100644 --- a/app/Models/Club.php +++ b/app/Models/Club.php @@ -25,4 +25,9 @@ public function teams() { return $this->hasMany('App\Models\Team'); } + + public function __toString() + { + return $this->club; + } } diff --git a/app/Models/Division.php b/app/Models/Division.php index 90f6fba5..9e04ea42 100644 --- a/app/Models/Division.php +++ b/app/Models/Division.php @@ -30,4 +30,9 @@ public function fixtures() { return $this->hasMany('App\Models\Fixture'); } + + public function __toString() + { + return $this->season . ' ' . $this->division; + } } diff --git a/app/Models/Fixture.php b/app/Models/Fixture.php index 3043cac1..ac089ca8 100644 --- a/app/Models/Fixture.php +++ b/app/Models/Fixture.php @@ -51,6 +51,11 @@ public function venue() return $this->belongsTo('App\Models\Venue'); } + public function available_appointments() + { + return $this->hasMany('App\Models\AvailableAppointment'); + } + public function getWarmUpTimeAttribute($time) { return Carbon::createFromFormat('H:i:s', $time); @@ -65,4 +70,13 @@ public function getMatchDateAttribute($date) { return Carbon::createFromFormat('Y-m-d', $date); } + + public function __toString() + { + return + $this->division . ':' . $this->match_number . ' ' . + $this->match_date->format('d/m/y') . ' ' . + $this->start_time->format('H:i') . '(' . $this->warm_up_time->format('H:i') . ') ' . + $this->home_team . ' v ' . $this->away_team; + } } diff --git a/app/Models/Role.php b/app/Models/Role.php index ce5d1993..3b298806 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -21,4 +21,13 @@ class Role extends Model */ protected $fillable = ['role']; + public function available_appointment() + { + return $this->hasMany('App\Models\AvailableAppointment'); + } + + public function __toString() + { + return $this->role; + } } diff --git a/app/Models/Season.php b/app/Models/Season.php index a3c669b4..04b107a3 100644 --- a/app/Models/Season.php +++ b/app/Models/Season.php @@ -25,4 +25,9 @@ public function divisions() { return $this->hasMany('App\Models\Division'); } + + public function __toString() + { + return $this->season; + } } diff --git a/app/Models/Team.php b/app/Models/Team.php index 7055a80b..3a8f5dd3 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -35,4 +35,9 @@ public function homeFixtures() { return $this->hasMany('App\Models\Fixture', 'home_team_id'); } + + public function __toString() + { + return $this->team; + } } diff --git a/app/Models/Venue.php b/app/Models/Venue.php index 9c8c1b91..073fce48 100644 --- a/app/Models/Venue.php +++ b/app/Models/Venue.php @@ -25,4 +25,9 @@ public function fixtures() { return $this->hasMany('App\Models\Fixture'); } + + public function __toString() + { + return $this->venue; + } } diff --git a/database/deployment/2016_04_23_144453_create_available_appointments_table.sql b/database/deployment/2016_04_23_144453_create_available_appointments_table.sql new file mode 100644 index 00000000..3ed84b28 --- /dev/null +++ b/database/deployment/2016_04_23_144453_create_available_appointments_table.sql @@ -0,0 +1,18 @@ +CREATE TABLE `available_appointments` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `fixture_id` INT UNSIGNED NOT NULL, + `role_id` INT UNSIGNED NOT NULL, + `created_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL +) + DEFAULT CHARACTER SET utf8 + COLLATE utf8_unicode_ci + ENGINE = InnoDB; + +ALTER TABLE `available_appointments` + ADD UNIQUE `available_appointments_fixture_id_role_id_unique`(`fixture_id`, `role_id`); + +ALTER TABLE `available_appointments` + ADD CONSTRAINT `available_appointments_fixture_id_foreign` FOREIGN KEY (`fixture_id`) REFERENCES `fixtures` (`id`); +ALTER TABLE `available_appointments` + ADD CONSTRAINT `available_appointments_role_id_foreign` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`); \ No newline at end of file diff --git a/database/migrations/2016_04_23_144453_create_available_appointments_table.php b/database/migrations/2016_04_23_144453_create_available_appointments_table.php new file mode 100644 index 00000000..6dc2486f --- /dev/null +++ b/database/migrations/2016_04_23_144453_create_available_appointments_table.php @@ -0,0 +1,40 @@ +engine = "InnoDB"; + + $table->increments('id'); + $table->integer('fixture_id')->unsigned(); + $table->integer('role_id')->unsigned(); + $table->timestamps(); + + $table->unique(['fixture_id', 'role_id']); + + $table->foreign('fixture_id')->references('id')->on('fixtures'); + $table->foreign('role_id')->references('id')->on('roles'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('available_appointments'); + } + +} diff --git a/resources/views/admin/data-management/available-appointments/create.blade.php b/resources/views/admin/data-management/available-appointments/create.blade.php new file mode 100644 index 00000000..c646e2f9 --- /dev/null +++ b/resources/views/admin/data-management/available-appointments/create.blade.php @@ -0,0 +1,50 @@ +@extends('layouts.app') + +@section('content') + + id] = $fixture; + } + ?> +
+

Create new appointment

+
+ + @if ($errors->any()) +
+ @foreach ($errors->all() as $error) +

{{ $error }}

+ @endforeach +
+ @endif + + {!! Form::open(['url' => 'admin/data-management/available-appointments', 'class' => 'form-horizontal']) !!} + +
+ {!! Form::label('fixture_id', 'Fixture: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('fixture_id', $fixturesSelect, null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('fixture_id', '

:message

') !!} +
+
+
+ {!! Form::label('role_id', 'Role: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('role_id', array_column($roles->toArray(), 'role', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('role_id', '

:message

') !!} +
+
+ +
+
+ {!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::close() !!} + + +
+ +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/available-appointments/edit.blade.php b/resources/views/admin/data-management/available-appointments/edit.blade.php new file mode 100644 index 00000000..ab06e107 --- /dev/null +++ b/resources/views/admin/data-management/available-appointments/edit.blade.php @@ -0,0 +1,57 @@ +@extends('layouts.app') + +@section('content') + + id] = $fixture; + } + ?> + +
+

Edit appointment

+
+ + @if ($errors->any()) +
+ @foreach ($errors->all() as $error) +

{{ $error }}

+ @endforeach +
+ @endif + + {!! Form::model($availableAppointment, [ + 'method' => 'PATCH', + 'url' => ['admin/data-management/available-appointments', $availableAppointment->id], + 'class' => 'form-horizontal' + ]) !!} + + {!! Form::hidden('id', $availableAppointment->id) !!} +
+ {!! Form::label('fixture_id', 'Fixture: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('fixture_id', $fixturesSelect, null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('fixture_id', '

:message

') !!} +
+
+
+ {!! Form::label('role_id', 'Role: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('role_id', array_column($roles->toArray(), 'role', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('role_id', '

:message

') !!} +
+
+ + +
+
+ {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::close() !!} + + +
+ +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/available-appointments/index.blade.php b/resources/views/admin/data-management/available-appointments/index.blade.php new file mode 100644 index 00000000..594b28b7 --- /dev/null +++ b/resources/views/admin/data-management/available-appointments/index.blade.php @@ -0,0 +1,51 @@ +@extends('layouts.app') + +@section('content') + +
+

Available appointments Add New Appointment

+
+
IdVenueActionsVenueActions
{{ $x }} {{ $item->venue }} From 6614ebf0f98e0feaa436e9cf30721e4231d7a8cc Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Thu, 14 Apr 2016 18:44:22 +0100 Subject: [PATCH 11/34] dev: Do not delete season if there are divisions in it --- .../Controllers/Admin/DataManagement/SeasonsController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Admin/DataManagement/SeasonsController.php b/app/Http/Controllers/Admin/DataManagement/SeasonsController.php index 11ff1459..a7c39e59 100644 --- a/app/Http/Controllers/Admin/DataManagement/SeasonsController.php +++ b/app/Http/Controllers/Admin/DataManagement/SeasonsController.php @@ -108,13 +108,12 @@ public function update($id, Request $request) */ public function destroy($id) { - // @todo Check whether the season can be deleted, i.e. there are no divisions ins this season - $canBeDeleted = true; + $canBeDeleted = empty(Season::find($id)->divisions->toArray()); if ($canBeDeleted) { Season::destroy($id); Flash::success('Season deleted!'); } else { - Flash::error('Cannot delete season'); + Flash::error('Cannot delete because they are existing divisions in this season.'); } return redirect('admin/data-management/seasons'); From b79014d0a4fb1cb9aa74855d810499256f21d857 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Thu, 14 Apr 2016 19:07:07 +0100 Subject: [PATCH 12/34] lva-8: Added CRUD for the teams table --- .../Admin/DataManagement/ClubsController.php | 12 +- .../Admin/DataManagement/TeamsController.php | 120 ++++++++++++++++++ app/Http/breadcrumbs.php | 18 +++ app/Http/routes.php | 1 + app/Models/Club.php | 4 + app/Models/Team.php | 28 ++++ .../2016_04_14_184813_create_teams_table.sql | 13 ++ .../2016_04_14_184813_create_teams_table.php | 43 +++++++ .../data-management/divisions/edit.blade.php | 2 +- .../data-management/divisions/index.blade.php | 2 +- .../admin/data-management/home.blade.php | 1 + .../data-management/teams/create.blade.php | 43 +++++++ .../data-management/teams/edit.blade.php | 47 +++++++ .../data-management/teams/index.blade.php | 44 +++++++ .../data-management/teams/show.blade.php | 23 ++++ 15 files changed, 395 insertions(+), 6 deletions(-) create mode 100644 app/Http/Controllers/Admin/DataManagement/TeamsController.php create mode 100644 app/Models/Team.php create mode 100644 database/deployment/2016_04_14_184813_create_teams_table.sql create mode 100644 database/migrations/2016_04_14_184813_create_teams_table.php create mode 100644 resources/views/admin/data-management/teams/create.blade.php create mode 100644 resources/views/admin/data-management/teams/edit.blade.php create mode 100644 resources/views/admin/data-management/teams/index.blade.php create mode 100644 resources/views/admin/data-management/teams/show.blade.php diff --git a/app/Http/Controllers/Admin/DataManagement/ClubsController.php b/app/Http/Controllers/Admin/DataManagement/ClubsController.php index 4cd80b2f..92c99c15 100644 --- a/app/Http/Controllers/Admin/DataManagement/ClubsController.php +++ b/app/Http/Controllers/Admin/DataManagement/ClubsController.php @@ -106,10 +106,14 @@ public function update($id, Request $request) */ public function destroy($id) { - Club::destroy($id); - - Flash::success('Club deleted!'); - + $canBeDeleted = empty(Club::find($id)->teams->toArray()); + if ($canBeDeleted) { + Club::destroy($id); + Flash::success('Club deleted!'); + } else { + Flash::error('Cannot delete because they are existing teams in this club.'); + } + return redirect('admin/data-management/clubs'); } diff --git a/app/Http/Controllers/Admin/DataManagement/TeamsController.php b/app/Http/Controllers/Admin/DataManagement/TeamsController.php new file mode 100644 index 00000000..f216c6e7 --- /dev/null +++ b/app/Http/Controllers/Admin/DataManagement/TeamsController.php @@ -0,0 +1,120 @@ + Club::all()]); + } + + /** + * Store a newly created resource in storage. + * + * @return Response + */ + public function store(Request $request) + { + $this->validate($request, ['club_id' => 'required', 'team' => 'required', ]); + + Team::create($request->all()); + + Flash::success('Team added!'); + + return redirect('admin/data-management/teams'); + } + + /** + * Display the specified resource. + * + * @param int $id + * + * @return Response + */ + public function show($id) + { + $team = Team::findOrFail($id); + + return view('admin.data-management.teams.show', compact('team')); + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * + * @return Response + */ + public function edit($id) + { + $team = Team::findOrFail($id); + $clubs = Club::all(); + + return view('admin.data-management.teams.edit', compact('team', 'clubs')); + } + + /** + * Update the specified resource in storage. + * + * @param int $id + * + * @return Response + */ + public function update($id, Request $request) + { + $this->validate($request, ['club_id' => 'required', 'team' => 'required', ]); + + $team = Team::findOrFail($id); + $team->update($request->all()); + + Flash::success('Team updated!'); + + return redirect('admin/data-management/teams'); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * + * @return Response + */ + public function destroy($id) + { + Team::destroy($id); + + Flash::success('Team deleted!'); + + return redirect('admin/data-management/teams'); + } + +} diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index 57d36379..e70f1dae 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -121,4 +121,22 @@ Breadcrumbs::register('admin.data-management.divisions.show', function($b) { $b->parent('admin.data-management.divisions.index'); $b->push('View'); +}); + +// Data Management - Teams +Breadcrumbs::register('admin.data-management.teams.index', function($b) { + $b->parent('admin::dataManagement'); + $b->push('Teams', route('admin.data-management.teams.index')); +}); +Breadcrumbs::register('admin.data-management.teams.create', function($b) { + $b->parent('admin.data-management.teams.index'); + $b->push('Add', route('admin.data-management.teams.create')); +}); +Breadcrumbs::register('admin.data-management.teams.edit', function($b) { + $b->parent('admin.data-management.teams.index'); + $b->push('Edit'); +}); +Breadcrumbs::register('admin.data-management.teams.show', function($b) { + $b->parent('admin.data-management.teams.index'); + $b->push('View'); }); \ No newline at end of file diff --git a/app/Http/routes.php b/app/Http/routes.php index 80e087a7..417e4340 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -62,6 +62,7 @@ Route::resource('venues', 'VenuesController'); Route::resource('roles', 'RolesController'); Route::resource('divisions', 'DivisionsController'); + Route::resource('teams', 'TeamsController'); }); }); }); diff --git a/app/Models/Club.php b/app/Models/Club.php index a1caf6ad..cd5b3236 100644 --- a/app/Models/Club.php +++ b/app/Models/Club.php @@ -21,4 +21,8 @@ class Club extends Model */ protected $fillable = ['club']; + public function teams() + { + return $this->hasMany('App\Models\Team'); + } } diff --git a/app/Models/Team.php b/app/Models/Team.php new file mode 100644 index 00000000..2592d8da --- /dev/null +++ b/app/Models/Team.php @@ -0,0 +1,28 @@ +belongsTo('App\Models\Club'); + } +} diff --git a/database/deployment/2016_04_14_184813_create_teams_table.sql b/database/deployment/2016_04_14_184813_create_teams_table.sql new file mode 100644 index 00000000..4515e818 --- /dev/null +++ b/database/deployment/2016_04_14_184813_create_teams_table.sql @@ -0,0 +1,13 @@ +CREATE TABLE `teams` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `club_id` INT UNSIGNED NOT NULL, + `team` VARCHAR(255) NOT NULL, + `created_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL +) + DEFAULT CHARACTER SET utf8 + COLLATE utf8_unicode_ci + ENGINE = InnoDB; + +ALTER TABLE `teams` + ADD CONSTRAINT `teams_club_id_foreign` FOREIGN KEY (`club_id`) REFERENCES `clubs` (`id`); \ No newline at end of file diff --git a/database/migrations/2016_04_14_184813_create_teams_table.php b/database/migrations/2016_04_14_184813_create_teams_table.php new file mode 100644 index 00000000..fcb0072b --- /dev/null +++ b/database/migrations/2016_04_14_184813_create_teams_table.php @@ -0,0 +1,43 @@ +engine = 'InnoDB'; + + $table->increments('id'); + $table->integer('club_id')->unsigned(); + $table->string('team'); + + $table->foreign('club_id')->references('id')->on('clubs'); + + $table->timestamps(); + }); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('teams', function (Blueprint $table) { + $table->dropForeign(['club_id']); + }); + Schema::drop('teams'); + } + +} diff --git a/resources/views/admin/data-management/divisions/edit.blade.php b/resources/views/admin/data-management/divisions/edit.blade.php index 470abe2e..f012afae 100644 --- a/resources/views/admin/data-management/divisions/edit.blade.php +++ b/resources/views/admin/data-management/divisions/edit.blade.php @@ -15,7 +15,7 @@
{!! Form::label('season_id', 'Season: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::select('season_id', array_column($seasons->toArray(), 'season', 'id'), null, ['class' => 'form-control']) !!} + {!! Form::select('season_id', array_column($seasons->toArray(), 'season', 'id'), $division->season->id, ['class' => 'form-control']) !!} {!! $errors->first('season_id', '

:message

') !!}
diff --git a/resources/views/admin/data-management/divisions/index.blade.php b/resources/views/admin/data-management/divisions/index.blade.php index 9a93eda8..751dda14 100644 --- a/resources/views/admin/data-management/divisions/index.blade.php +++ b/resources/views/admin/data-management/divisions/index.blade.php @@ -8,7 +8,7 @@ - < + diff --git a/resources/views/admin/data-management/home.blade.php b/resources/views/admin/data-management/home.blade.php index e9f96328..80acb86b 100644 --- a/resources/views/admin/data-management/home.blade.php +++ b/resources/views/admin/data-management/home.blade.php @@ -9,6 +9,7 @@ Venues Roles Divisions + Teams diff --git a/resources/views/admin/data-management/teams/create.blade.php b/resources/views/admin/data-management/teams/create.blade.php new file mode 100644 index 00000000..81d89488 --- /dev/null +++ b/resources/views/admin/data-management/teams/create.blade.php @@ -0,0 +1,43 @@ +@extends('layouts.app') + +@section('content') + +
+

Create New Team

+
+ + {!! Form::open(['url' => 'admin/data-management/teams', 'class' => 'form-horizontal']) !!} + +
+ {!! Form::label('club_id', 'Club: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('club_id', array_column($clubs->toArray(), 'club', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('club_id', '

:message

') !!} +
+
+
+ {!! Form::label('team', 'Team: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('team', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('team', '

:message

') !!} +
+
+ + +
+
+ {!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::close() !!} + + @if ($errors->any()) +
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+ @endif +
+ +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/teams/edit.blade.php b/resources/views/admin/data-management/teams/edit.blade.php new file mode 100644 index 00000000..883643f2 --- /dev/null +++ b/resources/views/admin/data-management/teams/edit.blade.php @@ -0,0 +1,47 @@ +@extends('layouts.app') + +@section('content') + +
+

Edit Team

+
+ + {!! Form::model($team, [ + 'method' => 'PATCH', + 'url' => ['admin/data-management/teams', $team->id], + 'class' => 'form-horizontal' + ]) !!} + +
+ {!! Form::label('club_id', 'Club Id: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('club_id', array_column($clubs->toArray(), 'club', 'id'), $team->club->id, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('club_id', '

:message

') !!} +
+
+
+ {!! Form::label('team', 'Team: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('team', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('team', '

:message

') !!} +
+
+ + +
+
+ {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::close() !!} + + @if ($errors->any()) +
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+ @endif +
+ +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/teams/index.blade.php b/resources/views/admin/data-management/teams/index.blade.php new file mode 100644 index 00000000..492da9f6 --- /dev/null +++ b/resources/views/admin/data-management/teams/index.blade.php @@ -0,0 +1,44 @@ +@extends('layouts.app') + +@section('content') + +
+

Teams Add New Team

+
+
SeasonDivisionActionsSeasonDivisionActions
+ + + + + + + @foreach($teams as $item) + + + + + + @endforeach + +
ClubTeamActions
{{ $item->club->club }}{{ $item->team }} + + + / + {!! Form::open([ + 'method'=>'DELETE', + 'url' => ['admin/data-management/teams', $item->id], + 'style' => 'display:inline' + ]) !!} + {!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs', 'data-toggle' => 'confirmation']) !!} + {!! Form::close() !!} +
+ + + + +@endsection + +@section('javascript') + + +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/teams/show.blade.php b/resources/views/admin/data-management/teams/show.blade.php new file mode 100644 index 00000000..cc7bca6c --- /dev/null +++ b/resources/views/admin/data-management/teams/show.blade.php @@ -0,0 +1,23 @@ +@extends('layouts.app') + +@section('content') + +
+

Team

+
+ + + + + + + + + + + +
IdClubTeam
{{ $team->id }} {{ $team->club->club }} {{ $team->team }}
+
+
+ +@endsection \ No newline at end of file From 9cd953d49ae375feeb10d67761a353e3c8c11aa0 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Fri, 15 Apr 2016 19:46:03 +0100 Subject: [PATCH 13/34] lva-9 Added initial CRUD for Fixtures --- .../DataManagement/FixturesController.php | 146 ++++++++++++++++++ app/Http/breadcrumbs.php | 18 +++ app/Http/routes.php | 1 + app/Models/Division.php | 5 + app/Models/Fixture.php | 54 +++++++ app/Models/Team.php | 5 + app/Models/Venue.php | 4 + ...016_04_15_180829_create_fixtures_table.sql | 25 +++ ...016_04_15_180829_create_fixtures_table.php | 55 +++++++ .../data-management/fixtures/create.blade.php | 85 ++++++++++ .../data-management/fixtures/edit.blade.php | 89 +++++++++++ .../data-management/fixtures/index.blade.php | 61 ++++++++ .../data-management/fixtures/show.blade.php | 39 +++++ .../admin/data-management/home.blade.php | 1 + 14 files changed, 588 insertions(+) create mode 100644 app/Http/Controllers/Admin/DataManagement/FixturesController.php create mode 100644 app/Models/Fixture.php create mode 100644 database/deployment/2016_04_15_180829_create_fixtures_table.sql create mode 100644 database/migrations/2016_04_15_180829_create_fixtures_table.php create mode 100644 resources/views/admin/data-management/fixtures/create.blade.php create mode 100644 resources/views/admin/data-management/fixtures/edit.blade.php create mode 100644 resources/views/admin/data-management/fixtures/index.blade.php create mode 100644 resources/views/admin/data-management/fixtures/show.blade.php diff --git a/app/Http/Controllers/Admin/DataManagement/FixturesController.php b/app/Http/Controllers/Admin/DataManagement/FixturesController.php new file mode 100644 index 00000000..7d5219c7 --- /dev/null +++ b/app/Http/Controllers/Admin/DataManagement/FixturesController.php @@ -0,0 +1,146 @@ +validate($request, [ + 'division_id' => 'required', + 'match_number' => 'required', + 'match_date' => 'required', + 'warm_up_time' => 'required', + 'start_time' => 'required', + 'home_team_id' => 'required', + 'away_team_id' => 'required', + 'venue_id' => 'required', + ]); + + Fixture::create($request->all()); + + Flash::success('Fixture added!'); + + return redirect('admin/data-management/fixtures'); + } + + /** + * Display the specified resource. + * + * @param int $id + * + * @return Response + */ + public function show($id) + { + $fixture = Fixture::findOrFail($id); + + return view('admin.data-management.fixtures.show', compact('fixture')); + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * + * @return Response + */ + public function edit($id) + { + $fixture = Fixture::findOrFail($id); + $divisions = Division::all(); + $teams = Team::all(); + $venues = Venue::all(); + + return view('admin.data-management.fixtures.edit', compact('fixture', 'divisions', 'teams', 'venues')); + } + + /** + * Update the specified resource in storage. + * + * @param int $id + * + * @return Response + */ + public function update($id, Request $request) + { + $this->validate($request, [ + 'division_id' => 'required', + 'match_number' => 'required', + 'match_date' => 'required', + 'warm_up_time' => 'required', + 'start_time' => 'required', + 'home_team_id' => 'required', + 'away_team_id' => 'required', + 'venue_id' => 'required', + ]); + + $fixture = Fixture::findOrFail($id); + $fixture->update($request->all()); + + Flash::success('Fixture updated!'); + + return redirect('admin/data-management/fixtures'); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * + * @return Response + */ + public function destroy($id) + { + Fixture::destroy($id); + + Flash::success('Fixture deleted!'); + + return redirect('admin/data-management/fixtures'); + } + +} diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index e70f1dae..8147266d 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -139,4 +139,22 @@ Breadcrumbs::register('admin.data-management.teams.show', function($b) { $b->parent('admin.data-management.teams.index'); $b->push('View'); +}); + +// Data Management - Fixtures +Breadcrumbs::register('admin.data-management.fixtures.index', function($b) { + $b->parent('admin::dataManagement'); + $b->push('Fixtures', route('admin.data-management.fixtures.index')); +}); +Breadcrumbs::register('admin.data-management.fixtures.create', function($b) { + $b->parent('admin.data-management.fixtures.index'); + $b->push('Add', route('admin.data-management.fixtures.create')); +}); +Breadcrumbs::register('admin.data-management.fixtures.edit', function($b) { + $b->parent('admin.data-management.fixtures.index'); + $b->push('Edit'); +}); +Breadcrumbs::register('admin.data-management.fixtures.show', function($b) { + $b->parent('admin.data-management.fixtures.index'); + $b->push('View'); }); \ No newline at end of file diff --git a/app/Http/routes.php b/app/Http/routes.php index 417e4340..fcebd240 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -63,6 +63,7 @@ Route::resource('roles', 'RolesController'); Route::resource('divisions', 'DivisionsController'); Route::resource('teams', 'TeamsController'); + Route::resource('fixtures', 'FixturesController'); }); }); }); diff --git a/app/Models/Division.php b/app/Models/Division.php index 0847ede9..90f6fba5 100644 --- a/app/Models/Division.php +++ b/app/Models/Division.php @@ -25,4 +25,9 @@ public function season() { return $this->belongsTo('App\Models\Season'); } + + public function fixtures() + { + return $this->hasMany('App\Models\Fixture'); + } } diff --git a/app/Models/Fixture.php b/app/Models/Fixture.php new file mode 100644 index 00000000..e04aedff --- /dev/null +++ b/app/Models/Fixture.php @@ -0,0 +1,54 @@ +belongsTo('App\Models\Division'); + } + + public function home_team() + { + return $this->belongsTo('App\Models\Team'); + } + + public function away_team() + { + return $this->belongsTo('App\Models\Team'); + } + + public function venue() + { + return $this->belongsTo('App\Models\Venue'); + } +} diff --git a/app/Models/Team.php b/app/Models/Team.php index 2592d8da..eafb88c5 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -25,4 +25,9 @@ public function club() { return $this->belongsTo('App\Models\Club'); } + + public function fixtures() + { + return $this->hasMany('App\Models\Fixture'); + } } diff --git a/app/Models/Venue.php b/app/Models/Venue.php index 50082868..9c8c1b91 100644 --- a/app/Models/Venue.php +++ b/app/Models/Venue.php @@ -21,4 +21,8 @@ class Venue extends Model */ protected $fillable = ['venue']; + public function fixtures() + { + return $this->hasMany('App\Models\Fixture'); + } } diff --git a/database/deployment/2016_04_15_180829_create_fixtures_table.sql b/database/deployment/2016_04_15_180829_create_fixtures_table.sql new file mode 100644 index 00000000..b20c9b05 --- /dev/null +++ b/database/deployment/2016_04_15_180829_create_fixtures_table.sql @@ -0,0 +1,25 @@ +CREATE TABLE `fixtures` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `division_id` INT UNSIGNED NOT NULL, + `match_number` INT UNSIGNED NOT NULL, + `match_date` DATE NOT NULL, + `warm_up_time` TIME NOT NULL, + `start_time` TIME NOT NULL, + `home_team_id` INT UNSIGNED NOT NULL, + `away_team_id` INT UNSIGNED NOT NULL, + `venue_id` INT UNSIGNED NOT NULL, + `created_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL +) + DEFAULT CHARACTER SET utf8 + COLLATE utf8_unicode_ci + ENGINE = InnoDB; + +ALTER TABLE `fixtures` + ADD CONSTRAINT `fixtures_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`); +ALTER TABLE `fixtures` + ADD CONSTRAINT `fixtures_home_team_id_foreign` FOREIGN KEY (`home_team_id`) REFERENCES `teams` (`id`); +ALTER TABLE `fixtures` + ADD CONSTRAINT `fixtures_away_team_id_foreign` FOREIGN KEY (`away_team_id`) REFERENCES `teams` (`id`); +ALTER TABLE `fixtures` + ADD CONSTRAINT `fixtures_venue_id_foreign` FOREIGN KEY (`venue_id`) REFERENCES `venues` (`id`); diff --git a/database/migrations/2016_04_15_180829_create_fixtures_table.php b/database/migrations/2016_04_15_180829_create_fixtures_table.php new file mode 100644 index 00000000..537393cf --- /dev/null +++ b/database/migrations/2016_04_15_180829_create_fixtures_table.php @@ -0,0 +1,55 @@ +engine = 'InnoDB'; + + $table->increments('id'); + $table->integer('division_id')->unsigned(); + $table->integer('match_number')->unsigned(); + $table->date('match_date'); + $table->time('warm_up_time'); + $table->time('start_time'); + $table->integer('home_team_id')->unsigned(); + $table->integer('away_team_id')->unsigned(); + $table->integer('venue_id')->unsigned(); + + $table->timestamps(); + + $table->foreign('division_id')->references('id')->on('divisions'); + $table->foreign('home_team_id')->references('id')->on('teams'); + $table->foreign('away_team_id')->references('id')->on('teams'); + $table->foreign('venue_id')->references('id')->on('venues'); + }); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('fixtures', function (Blueprint $table) { + $table->dropForeign(['division_id']); + $table->dropForeign(['home_team_id']); + $table->dropForeign(['away_team_id']); + $table->dropForeign(['venue_id']); + }); + Schema::drop('fixtures'); + } + +} diff --git a/resources/views/admin/data-management/fixtures/create.blade.php b/resources/views/admin/data-management/fixtures/create.blade.php new file mode 100644 index 00000000..05b1ff82 --- /dev/null +++ b/resources/views/admin/data-management/fixtures/create.blade.php @@ -0,0 +1,85 @@ +@extends('layouts.app') + +@section('content') + +
+

Create New Fixture

+
+ + {!! Form::open(['url' => 'admin/data-management/fixtures', 'class' => 'form-horizontal']) !!} + +
+ {!! Form::label('division_id', 'Division: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('division_id', array_column($divisions->toArray(), 'division', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('division_id', '

:message

') !!} +
+
+
+ {!! Form::label('match_number', 'Match Number: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('match_number', '

:message

') !!} +
+
+
+ {!! Form::label('match_date', 'Match Date: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::date('match_date', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('match_date', '

:message

') !!} +
+
+
+ {!! Form::label('warm_up_time', 'Warm Up Time: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::input('time', 'warm_up_time', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('warm_up_time', '

:message

') !!} +
+
+
+ {!! Form::label('start_time', 'Start Time: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::input('time', 'start_time', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('start_time', '

:message

') !!} +
+
+
+ {!! Form::label('home_team_id', 'Home Team: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('home_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('home_team_id', '

:message

') !!} +
+
+
+ {!! Form::label('away_team_id', 'Away Team: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('away_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('away_team_id', '

:message

') !!} +
+
+
+ {!! Form::label('venue_id', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('venue_id', array_column($venues->toArray(), 'venue', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('venue_id', '

:message

') !!} +
+
+ + +
+
+ {!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::close() !!} + + @if ($errors->any()) +
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+ @endif +
+ +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/fixtures/edit.blade.php b/resources/views/admin/data-management/fixtures/edit.blade.php new file mode 100644 index 00000000..cd6a8495 --- /dev/null +++ b/resources/views/admin/data-management/fixtures/edit.blade.php @@ -0,0 +1,89 @@ +@extends('layouts.app') + +@section('content') + +
+

Edit Fixture

+
+ + {!! Form::model($fixture, [ + 'method' => 'PATCH', + 'url' => ['admin/data-management/fixtures', $fixture->id], + 'class' => 'form-horizontal' + ]) !!} + +
+ {!! Form::label('division_id', 'Division Id: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('division_id', array_column($divisions->toArray(), 'division', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('division_id', '

:message

') !!} +
+
+
+ {!! Form::label('match_number', 'Match Number: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('match_number', '

:message

') !!} +
+
+
+ {!! Form::label('match_date', 'Match Date: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::date('match_date', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('match_date', '

:message

') !!} +
+
+
+ {!! Form::label('warm_up_time', 'Warm Up Time: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::input('time', 'warm_up_time', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('warm_up_time', '

:message

') !!} +
+
+
+ {!! Form::label('start_time', 'Start Time: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::input('time', 'start_time', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('start_time', '

:message

') !!} +
+
+
+ {!! Form::label('home_team_id', 'Home Team Id: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('home_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('home_team_id', '

:message

') !!} +
+
+
+ {!! Form::label('away_team_id', 'Away Team Id: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('away_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('away_team_id', '

:message

') !!} +
+
+
+ {!! Form::label('venue_id', 'Venue Id: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('venue_id', array_column($venues->toArray(), 'venue', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('venue_id', '

:message

') !!} +
+
+ + +
+
+ {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::close() !!} + + @if ($errors->any()) +
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+ @endif +
+ +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/fixtures/index.blade.php b/resources/views/admin/data-management/fixtures/index.blade.php new file mode 100644 index 00000000..74e40e03 --- /dev/null +++ b/resources/views/admin/data-management/fixtures/index.blade.php @@ -0,0 +1,61 @@ +@extends('layouts.app') + +@section('content') + +
+

Fixtures Add New Fixture

+
+ + + + + + + + + + + + + + + @foreach($fixtures as $item) + + + + + + + + + + + @endforeach + +
DateWarm-up timeStart timeHomeAwayVenueActions
+ + {{ $item->division->season->season }} {{ $item->division->division }} {{ $item->match_number }} + + {{ $item->match_date->format('j M Y') }}{{ $item->warm_up_time }}{{ $item->start_time }}{{ $item->home_team->team }}{{ $item->away_team->team }}{{ $item->venue->venue }} + + + / + {!! Form::open([ + 'method'=>'DELETE', + 'url' => ['admin/data-management/fixtures', $item->id], + 'style' => 'display:inline' + ]) !!} + {!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs', 'data-toggle' => 'confirmation']) !!} + {!! Form::close() !!} +
+ +
+
+ +@endsection + +@section('javascript') + + +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/fixtures/show.blade.php b/resources/views/admin/data-management/fixtures/show.blade.php new file mode 100644 index 00000000..b25d16a4 --- /dev/null +++ b/resources/views/admin/data-management/fixtures/show.blade.php @@ -0,0 +1,39 @@ +@extends('layouts.app') + +@section('content') + +
+

Fixture

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
SeasonDivisionMatch #DateWarm-up timeStart timeHomeAwayVenue
{{ $fixture->division->season->season }}{{ $fixture->division->division }}{{ $fixture->match_number }}{{ $fixture->match_date->format('j M Y') }}{{ $fixture->warm_up_time }}{{ $fixture->start_time }}{{ $fixture->home_team->team }}{{ $fixture->away_team->team }}{{ $fixture->venue->venue }}
+
+
+ +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/home.blade.php b/resources/views/admin/data-management/home.blade.php index 80acb86b..b94467f6 100644 --- a/resources/views/admin/data-management/home.blade.php +++ b/resources/views/admin/data-management/home.blade.php @@ -10,6 +10,7 @@ Roles Divisions Teams + Fixtures From 3c7d74dd0b408f41f4bbe1bc2d60727febb88b33 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Tue, 19 Apr 2016 19:52:07 +0100 Subject: [PATCH 14/34] lva-9: Fixed the display of date and time - Added initial check for deletion of venues, teams and divisions --- .../DataManagement/DivisionsController.php | 22 ++++++++++------- .../Admin/DataManagement/TeamsController.php | 22 ++++++++++------- .../Admin/DataManagement/VenuesController.php | 24 +++++++++++-------- app/Models/Fixture.php | 16 +++++++++++++ .../data-management/fixtures/edit.blade.php | 6 ++--- .../data-management/fixtures/index.blade.php | 4 ++-- .../data-management/fixtures/show.blade.php | 4 ++-- 7 files changed, 63 insertions(+), 35 deletions(-) diff --git a/app/Http/Controllers/Admin/DataManagement/DivisionsController.php b/app/Http/Controllers/Admin/DataManagement/DivisionsController.php index 43bfdb69..6cee3e96 100644 --- a/app/Http/Controllers/Admin/DataManagement/DivisionsController.php +++ b/app/Http/Controllers/Admin/DataManagement/DivisionsController.php @@ -57,7 +57,7 @@ public function store(Request $request) /** * Display the specified resource. * - * @param int $id + * @param int $id * * @return Response */ @@ -71,7 +71,7 @@ public function show($id) /** * Show the form for editing the specified resource. * - * @param int $id + * @param int $id * * @return Response */ @@ -86,13 +86,13 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param int $id + * @param int $id * * @return Response */ public function update($id, Request $request) { - $this->validate($request, ['division' => 'required', ]); + $this->validate($request, ['division' => 'required',]); $division = Division::findOrFail($id); $division->update($request->all()); @@ -105,16 +105,20 @@ public function update($id, Request $request) /** * Remove the specified resource from storage. * - * @param int $id + * @param int $id * * @return Response */ public function destroy($id) { - Division::destroy($id); - - Flash::success('Division deleted!'); - + $canBeDeleted = empty(Division::find($id)->fixtures->toArray()); + if ($canBeDeleted) { + Division::destroy($id); + Flash::success('Division deleted!'); + } else { + Flash::error('Cannot delete because they are existing fixtures in this division.'); + } + return redirect('admin/data-management/divisions'); } diff --git a/app/Http/Controllers/Admin/DataManagement/TeamsController.php b/app/Http/Controllers/Admin/DataManagement/TeamsController.php index f216c6e7..fa94c0f0 100644 --- a/app/Http/Controllers/Admin/DataManagement/TeamsController.php +++ b/app/Http/Controllers/Admin/DataManagement/TeamsController.php @@ -44,7 +44,7 @@ public function create() */ public function store(Request $request) { - $this->validate($request, ['club_id' => 'required', 'team' => 'required', ]); + $this->validate($request, ['club_id' => 'required', 'team' => 'required',]); Team::create($request->all()); @@ -56,7 +56,7 @@ public function store(Request $request) /** * Display the specified resource. * - * @param int $id + * @param int $id * * @return Response */ @@ -70,7 +70,7 @@ public function show($id) /** * Show the form for editing the specified resource. * - * @param int $id + * @param int $id * * @return Response */ @@ -85,13 +85,13 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param int $id + * @param int $id * * @return Response */ public function update($id, Request $request) { - $this->validate($request, ['club_id' => 'required', 'team' => 'required', ]); + $this->validate($request, ['club_id' => 'required', 'team' => 'required']); $team = Team::findOrFail($id); $team->update($request->all()); @@ -104,15 +104,19 @@ public function update($id, Request $request) /** * Remove the specified resource from storage. * - * @param int $id + * @param int $id * * @return Response */ public function destroy($id) { - Team::destroy($id); - - Flash::success('Team deleted!'); + $canBeDeleted = empty(Team::find($id)->fixtures->toArray()); + if ($canBeDeleted) { + Team::destroy($id); + Flash::success('Team deleted!'); + } else { + Flash::error('Cannot delete because they are existing fixtures for this team.'); + } return redirect('admin/data-management/teams'); } diff --git a/app/Http/Controllers/Admin/DataManagement/VenuesController.php b/app/Http/Controllers/Admin/DataManagement/VenuesController.php index dc3ac228..c57be81c 100644 --- a/app/Http/Controllers/Admin/DataManagement/VenuesController.php +++ b/app/Http/Controllers/Admin/DataManagement/VenuesController.php @@ -43,7 +43,7 @@ public function create() */ public function store(Request $request) { - + Venue::create($request->all()); Flash::success('Venue added!'); @@ -54,7 +54,7 @@ public function store(Request $request) /** * Display the specified resource. * - * @param int $id + * @param int $id * * @return Response */ @@ -68,7 +68,7 @@ public function show($id) /** * Show the form for editing the specified resource. * - * @param int $id + * @param int $id * * @return Response */ @@ -82,13 +82,13 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param int $id + * @param int $id * * @return Response */ public function update($id, Request $request) { - + $venue = Venue::findOrFail($id); $venue->update($request->all()); @@ -100,16 +100,20 @@ public function update($id, Request $request) /** * Remove the specified resource from storage. * - * @param int $id + * @param int $id * * @return Response */ public function destroy($id) { - Venue::destroy($id); - - Flash::success('Venue deleted!'); - + $canBeDeleted = empty(Venue::find($id)->fixtures->toArray()); + if ($canBeDeleted) { + Venue::destroy($id); + Flash::success('Venue deleted!'); + } else { + Flash::error('Cannot delete because they are existing fixtures at this venue.'); + } + return redirect('admin/data-management/venues'); } diff --git a/app/Models/Fixture.php b/app/Models/Fixture.php index e04aedff..43001d30 100644 --- a/app/Models/Fixture.php +++ b/app/Models/Fixture.php @@ -2,6 +2,7 @@ namespace App\Models; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; class Fixture extends Model @@ -51,4 +52,19 @@ public function venue() { return $this->belongsTo('App\Models\Venue'); } + + public function getWarmUpTimeAttribute($time) + { + return Carbon::createFromFormat('H:i:s', $time); + } + + public function getStartTimeAttribute($time) + { + return Carbon::createFromFormat('H:i:s', $time); + } + + public function getMatchDateAttribute($date) + { + return Carbon::createFromFormat('Y-m-d', $date); + } } diff --git a/resources/views/admin/data-management/fixtures/edit.blade.php b/resources/views/admin/data-management/fixtures/edit.blade.php index cd6a8495..d5b76b63 100644 --- a/resources/views/admin/data-management/fixtures/edit.blade.php +++ b/resources/views/admin/data-management/fixtures/edit.blade.php @@ -29,21 +29,21 @@
{!! Form::label('match_date', 'Match Date: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::date('match_date', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::date('match_date', $fixture->match_date->format('Y-m-d'), ['class' => 'form-control', 'required' => 'required']) !!} {!! $errors->first('match_date', '

:message

') !!}
{!! Form::label('warm_up_time', 'Warm Up Time: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::input('time', 'warm_up_time', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::input('time', 'warm_up_time', $fixture->warm_up_time->format('H:i'), ['class' => 'form-control', 'required' => 'required']) !!} {!! $errors->first('warm_up_time', '

:message

') !!}
{!! Form::label('start_time', 'Start Time: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::input('time', 'start_time', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::input('time', 'start_time', $fixture->start_time->format('H:i'), ['class' => 'form-control', 'required' => 'required']) !!} {!! $errors->first('start_time', '

:message

') !!}
diff --git a/resources/views/admin/data-management/fixtures/index.blade.php b/resources/views/admin/data-management/fixtures/index.blade.php index 74e40e03..63e4bba8 100644 --- a/resources/views/admin/data-management/fixtures/index.blade.php +++ b/resources/views/admin/data-management/fixtures/index.blade.php @@ -28,8 +28,8 @@ class="btn btn-primary pull-right btn-sm">Add New Fixture
{{ $item->match_date->format('j M Y') }}{{ $item->warm_up_time }}{{ $item->start_time }}{{ $item->warm_up_time->format('H:i') }}{{ $item->start_time->format('H:i') }} {{ $item->home_team->team }} {{ $item->away_team->team }} {{ $item->venue->venue }}{{ $fixture->division->division }} {{ $fixture->match_number }} {{ $fixture->match_date->format('j M Y') }}{{ $fixture->warm_up_time }}{{ $fixture->start_time }}{{ $fixture->warm_up_time->format('H:i') }}{{ $fixture->start_time->format('H:i') }} {{ $fixture->home_team->team }} {{ $fixture->away_team->team }} {{ $fixture->venue->venue }}
+ + + + + + + + + @foreach($availableAppointments as $item) + + + + + + @endforeach + +
FixtureRoleActions
+ + {{ $item->fixture }} + + {{ $item->role->role }} + + + / + {!! Form::open([ + 'method'=>'DELETE', + 'url' => ['admin/data-management/available-appointments', $item->id], + 'style' => 'display:inline' + ]) !!} + {!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs', 'data-toggle' => 'confirmation']) !!} + {!! Form::close() !!} +
+ + + + +@endsection + +@section('javascript') + + +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/available-appointments/show.blade.php b/resources/views/admin/data-management/available-appointments/show.blade.php new file mode 100644 index 00000000..a4681380 --- /dev/null +++ b/resources/views/admin/data-management/available-appointments/show.blade.php @@ -0,0 +1,27 @@ +@extends('layouts.app') + +@section('content') + +
+

Availableappointment

+
+ + + + + + + + + + + + + + + +
IdFixture IdRole Id
{{ $availableappointment->id }} {{ $availableappointment->fixture_id }} {{ $availableappointment->role_id }}
+
+
+ +@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/fixtures/create.blade.php b/resources/views/admin/data-management/fixtures/create.blade.php index 05b1ff82..b95fd5d6 100644 --- a/resources/views/admin/data-management/fixtures/create.blade.php +++ b/resources/views/admin/data-management/fixtures/create.blade.php @@ -8,7 +8,7 @@ {!! Form::open(['url' => 'admin/data-management/fixtures', 'class' => 'form-horizontal']) !!} -
+
{!! Form::label('division_id', 'Division: ', ['class' => 'col-sm-3 control-label']) !!}
{!! Form::select('division_id', array_column($divisions->toArray(), 'division', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} diff --git a/resources/views/admin/data-management/fixtures/index.blade.php b/resources/views/admin/data-management/fixtures/index.blade.php index 63e4bba8..2b2287dd 100644 --- a/resources/views/admin/data-management/fixtures/index.blade.php +++ b/resources/views/admin/data-management/fixtures/index.blade.php @@ -24,15 +24,15 @@ class="btn btn-primary pull-right btn-sm">Add New Fixture
- {{ $item->division->season->season }} {{ $item->division->division }} {{ $item->match_number }} + {{ $item->division }}:{{ $item->match_number }} {{ $item->match_date->format('j M Y') }} {{ $item->warm_up_time->format('H:i') }} {{ $item->start_time->format('H:i') }}{{ $item->home_team->team }}{{ $item->away_team->team }}{{ $item->venue->venue }}{{ $item->home_team }}{{ $item->away_team }}{{ $item->venue }} diff --git a/resources/views/admin/data-management/fixtures/show.blade.php b/resources/views/admin/data-management/fixtures/show.blade.php index e77d9e35..b7ef2ae4 100644 --- a/resources/views/admin/data-management/fixtures/show.blade.php +++ b/resources/views/admin/data-management/fixtures/show.blade.php @@ -21,15 +21,15 @@
{{ $fixture->division->season->season }}{{ $fixture->division->season }} {{ $fixture->division->division }} {{ $fixture->match_number }} {{ $fixture->match_date->format('j M Y') }} {{ $fixture->warm_up_time->format('H:i') }} {{ $fixture->start_time->format('H:i') }}{{ $fixture->home_team->team }}{{ $fixture->away_team->team }}{{ $fixture->venue->venue }}{{ $fixture->home_team }}{{ $fixture->away_team }}{{ $fixture->venue }}
diff --git a/resources/views/admin/data-management/home.blade.php b/resources/views/admin/data-management/home.blade.php index b94467f6..63b0ddf4 100644 --- a/resources/views/admin/data-management/home.blade.php +++ b/resources/views/admin/data-management/home.blade.php @@ -11,6 +11,9 @@
Divisions Teams Fixtures + Available appointments From 4b48ddbd0f3b0d526bb28ce33d3c883e46506c22 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 1 May 2016 20:28:45 +0100 Subject: [PATCH 17/34] dev: Added some PHPDoc block and some other cosmetic changes --- .../AvailableAppointmentsController.php | 35 +- .../Admin/DataManagement/ClubsController.php | 34 +- .../DataManagement/DivisionsController.php | 39 +- .../DataManagement/FixturesController.php | 33 +- .../Admin/DataManagement/RolesController.php | 37 +- .../DataManagement/SeasonsController.php | 39 +- .../Admin/DataManagement/TeamsController.php | 39 +- .../Admin/DataManagement/VenuesController.php | 39 +- app/Models/AvailableAppointment.php | 17 + app/Models/Club.php | 14 + app/Models/Division.php | 17 + app/Models/Fixture.php | 32 ++ app/Models/Role.php | 14 + app/Models/Season.php | 14 + app/Models/Team.php | 18 + app/Models/Venue.php | 14 + app/User.php | 19 + composer.json | 3 +- composer.lock | 530 +++++++++++++++--- resources/crud-generator/controller.stub | 13 +- 20 files changed, 775 insertions(+), 225 deletions(-) diff --git a/app/Http/Controllers/Admin/DataManagement/AvailableAppointmentsController.php b/app/Http/Controllers/Admin/DataManagement/AvailableAppointmentsController.php index e6e0b898..b3f1b167 100644 --- a/app/Http/Controllers/Admin/DataManagement/AvailableAppointmentsController.php +++ b/app/Http/Controllers/Admin/DataManagement/AvailableAppointmentsController.php @@ -5,12 +5,11 @@ use App\Http\Requests; use App\Http\Controllers\Controller; +use App\Http\Requests\AvailableAppointmentRequest; + use App\Models\AvailableAppointment; use App\Models\Fixture; use App\Models\Role; -use Carbon\Carbon; -use Session; -use Laracasts\Flash\Flash; class AvailableAppointmentsController extends Controller { @@ -18,7 +17,7 @@ class AvailableAppointmentsController extends Controller /** * Display a listing of the resource. * - * @return Response + * @return mixed */ public function index() { @@ -30,7 +29,7 @@ public function index() /** * Show the form for creating a new resource. * - * @return Response + * @return mixed */ public function create() { @@ -43,14 +42,14 @@ public function create() /** * Store a newly created resource in storage. * - * @param Requests\AvailableAppointmentRequest $request - * @return Response + * @param AvailableAppointmentRequest $request + * @return mixed */ - public function store(Requests\AvailableAppointmentRequest $request) + public function store(AvailableAppointmentRequest $request) { AvailableAppointment::create($request->all()); - Flash::success('Appointment added!'); + \Flash::success('Appointment added!'); return redirect('admin/data-management/available-appointments'); } @@ -60,7 +59,7 @@ public function store(Requests\AvailableAppointmentRequest $request) * * @param int $id * - * @return Response + * @return mixed */ public function show($id) { @@ -74,7 +73,7 @@ public function show($id) * * @param int $id * - * @return Response + * @return mixed */ public function edit($id) { @@ -89,17 +88,17 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param Requests\AvailableAppointmentRequest $request - * @param int $id + * @param AvailableAppointmentRequest $request + * @param int $id * - * @return Response + * @return mixed */ - public function update(Requests\AvailableAppointmentRequest $request, $id) + public function update(AvailableAppointmentRequest $request, $id) { $availableAppointment = AvailableAppointment::findOrFail($id); $availableAppointment->update($request->all()); - Flash::success('Appointment updated!'); + \Flash::success('Appointment updated!'); return redirect('admin/data-management/available-appointments'); } @@ -109,13 +108,13 @@ public function update(Requests\AvailableAppointmentRequest $request, $id) * * @param int $id * - * @return Response + * @return mixed */ public function destroy($id) { AvailableAppointment::destroy($id); - Flash::success('Appointment deleted!'); + \Flash::success('Appointment deleted!'); return redirect('admin/data-management/available-appointments'); } diff --git a/app/Http/Controllers/Admin/DataManagement/ClubsController.php b/app/Http/Controllers/Admin/DataManagement/ClubsController.php index 92c99c15..eef5c52d 100644 --- a/app/Http/Controllers/Admin/DataManagement/ClubsController.php +++ b/app/Http/Controllers/Admin/DataManagement/ClubsController.php @@ -7,9 +7,6 @@ use App\Models\Club; use Illuminate\Http\Request; -use Carbon\Carbon; -use Session; -use Laracasts\Flash\Flash; class ClubsController extends Controller { @@ -17,7 +14,7 @@ class ClubsController extends Controller /** * Display a listing of the resource. * - * @return Response + * @return mixed */ public function index() { @@ -29,7 +26,7 @@ public function index() /** * Show the form for creating a new resource. * - * @return Response + * @return mixed */ public function create() { @@ -39,14 +36,15 @@ public function create() /** * Store a newly created resource in storage. * - * @return Response + * @param Request $request + * + * @return mixed */ public function store(Request $request) { - Club::create($request->all()); - Flash::success('Club added!'); + \Flash::success('Club added!'); return redirect('admin/data-management/clubs'); } @@ -56,7 +54,7 @@ public function store(Request $request) * * @param int $id * - * @return Response + * @return mixed */ public function show($id) { @@ -70,7 +68,7 @@ public function show($id) * * @param int $id * - * @return Response + * @return mixed */ public function edit($id) { @@ -82,17 +80,17 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param int $id + * @param Request $request + * @param int $id * - * @return Response + * @return mixed */ - public function update($id, Request $request) + public function update(Request $request, $id) { - $club = Club::findOrFail($id); $club->update($request->all()); - Flash::success('Club updated!'); + \Flash::success('Club updated!'); return redirect('admin/data-management/clubs'); } @@ -102,16 +100,16 @@ public function update($id, Request $request) * * @param int $id * - * @return Response + * @return mixed */ public function destroy($id) { $canBeDeleted = empty(Club::find($id)->teams->toArray()); if ($canBeDeleted) { Club::destroy($id); - Flash::success('Club deleted!'); + \Flash::success('Club deleted!'); } else { - Flash::error('Cannot delete because they are existing teams in this club.'); + \Flash::error('Cannot delete because they are existing teams in this club.'); } return redirect('admin/data-management/clubs'); diff --git a/app/Http/Controllers/Admin/DataManagement/DivisionsController.php b/app/Http/Controllers/Admin/DataManagement/DivisionsController.php index 6cee3e96..f135ef45 100644 --- a/app/Http/Controllers/Admin/DataManagement/DivisionsController.php +++ b/app/Http/Controllers/Admin/DataManagement/DivisionsController.php @@ -7,19 +7,15 @@ use App\Models\Division; use Illuminate\Http\Request; -use Carbon\Carbon; -use Session; -use Laracasts\Flash\Flash; use App\Models\Season; class DivisionsController extends Controller { - /** * Display a listing of the resource. * - * @return Response + * @return mixed */ public function index() { @@ -31,7 +27,7 @@ public function index() /** * Show the form for creating a new resource. * - * @return Response + * @return mixed */ public function create() { @@ -41,7 +37,9 @@ public function create() /** * Store a newly created resource in storage. * - * @return Response + * @param Request $request + * + * @return mixed */ public function store(Request $request) { @@ -49,7 +47,7 @@ public function store(Request $request) Division::create($request->all()); - Flash::success('Division added!'); + \Flash::success('Division added!'); return redirect('admin/data-management/divisions'); } @@ -57,9 +55,9 @@ public function store(Request $request) /** * Display the specified resource. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function show($id) { @@ -71,9 +69,9 @@ public function show($id) /** * Show the form for editing the specified resource. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function edit($id) { @@ -86,18 +84,19 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param int $id + * @param Request $request + * @param int $id * - * @return Response + * @return mixed */ - public function update($id, Request $request) + public function update(Request $request, $id) { $this->validate($request, ['division' => 'required',]); $division = Division::findOrFail($id); $division->update($request->all()); - Flash::success('Division updated!'); + \Flash::success('Division updated!'); return redirect('admin/data-management/divisions'); } @@ -105,18 +104,18 @@ public function update($id, Request $request) /** * Remove the specified resource from storage. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function destroy($id) { $canBeDeleted = empty(Division::find($id)->fixtures->toArray()); if ($canBeDeleted) { Division::destroy($id); - Flash::success('Division deleted!'); + \Flash::success('Division deleted!'); } else { - Flash::error('Cannot delete because they are existing fixtures in this division.'); + \Flash::error('Cannot delete because they are existing fixtures in this division.'); } return redirect('admin/data-management/divisions'); diff --git a/app/Http/Controllers/Admin/DataManagement/FixturesController.php b/app/Http/Controllers/Admin/DataManagement/FixturesController.php index 7d5219c7..e0ae47be 100644 --- a/app/Http/Controllers/Admin/DataManagement/FixturesController.php +++ b/app/Http/Controllers/Admin/DataManagement/FixturesController.php @@ -10,17 +10,13 @@ use App\Models\Team; use App\Models\Venue; use Illuminate\Http\Request; -use Carbon\Carbon; -use Session; -use Laracasts\Flash\Flash; class FixturesController extends Controller { - /** * Display a listing of the resource. * - * @return Response + * @return mixed */ public function index() { @@ -32,7 +28,7 @@ public function index() /** * Show the form for creating a new resource. * - * @return Response + * @return mixed */ public function create() { @@ -46,7 +42,9 @@ public function create() /** * Store a newly created resource in storage. * - * @return Response + * @param Request $request + * + * @return mixed */ public function store(Request $request) { @@ -63,7 +61,7 @@ public function store(Request $request) Fixture::create($request->all()); - Flash::success('Fixture added!'); + \Flash::success('Fixture added!'); return redirect('admin/data-management/fixtures'); } @@ -71,9 +69,9 @@ public function store(Request $request) /** * Display the specified resource. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function show($id) { @@ -85,9 +83,9 @@ public function show($id) /** * Show the form for editing the specified resource. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function edit($id) { @@ -102,11 +100,12 @@ public function edit($id) /** * Update the specified resource in storage. * + * @param Request $request * @param int $id * - * @return Response + * @return mixed */ - public function update($id, Request $request) + public function update(Request $request, $id) { $this->validate($request, [ 'division_id' => 'required', @@ -122,7 +121,7 @@ public function update($id, Request $request) $fixture = Fixture::findOrFail($id); $fixture->update($request->all()); - Flash::success('Fixture updated!'); + \Flash::success('Fixture updated!'); return redirect('admin/data-management/fixtures'); } @@ -132,13 +131,13 @@ public function update($id, Request $request) * * @param int $id * - * @return Response + * @return mixed */ public function destroy($id) { Fixture::destroy($id); - Flash::success('Fixture deleted!'); + \Flash::success('Fixture deleted!'); return redirect('admin/data-management/fixtures'); } diff --git a/app/Http/Controllers/Admin/DataManagement/RolesController.php b/app/Http/Controllers/Admin/DataManagement/RolesController.php index cebc4b3b..cc8a134b 100644 --- a/app/Http/Controllers/Admin/DataManagement/RolesController.php +++ b/app/Http/Controllers/Admin/DataManagement/RolesController.php @@ -7,17 +7,13 @@ use App\Models\Role; use Illuminate\Http\Request; -use Carbon\Carbon; -use Session; -use Laracasts\Flash\Flash; class RolesController extends Controller { - /** * Display a listing of the resource. * - * @return Response + * @return mixed */ public function index() { @@ -29,7 +25,7 @@ public function index() /** * Show the form for creating a new resource. * - * @return Response + * @return mixed */ public function create() { @@ -39,7 +35,9 @@ public function create() /** * Store a newly created resource in storage. * - * @return Response + * @param Request $request + * + * @return mixed */ public function store(Request $request) { @@ -47,7 +45,7 @@ public function store(Request $request) Role::create($request->all()); - Flash::success('Role added!'); + \Flash::success('Role added!'); return redirect('admin/data-management/roles'); } @@ -55,9 +53,9 @@ public function store(Request $request) /** * Display the specified resource. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function show($id) { @@ -69,9 +67,9 @@ public function show($id) /** * Show the form for editing the specified resource. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function edit($id) { @@ -83,18 +81,19 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param int $id + * @param Request $request + * @param int $id * - * @return Response + * @return mixed */ - public function update($id, Request $request) + public function update(Request $request, $id) { $this->validate($request, ['role' => 'required', ]); $role = Role::findOrFail($id); $role->update($request->all()); - Flash::success('Role updated!'); + \Flash::success('Role updated!'); return redirect('admin/data-management/roles'); } @@ -102,15 +101,15 @@ public function update($id, Request $request) /** * Remove the specified resource from storage. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function destroy($id) { Role::destroy($id); - Flash::success('Role deleted!'); + \Flash::success('Role deleted!'); return redirect('admin/data-management/roles'); } diff --git a/app/Http/Controllers/Admin/DataManagement/SeasonsController.php b/app/Http/Controllers/Admin/DataManagement/SeasonsController.php index a7c39e59..b10bb85e 100644 --- a/app/Http/Controllers/Admin/DataManagement/SeasonsController.php +++ b/app/Http/Controllers/Admin/DataManagement/SeasonsController.php @@ -7,17 +7,13 @@ use App\Models\Season; use Illuminate\Http\Request; -use Carbon\Carbon; -use Laracasts\Flash\Flash; -use Session; class SeasonsController extends Controller { - /** * Display a listing of the resource. * - * @return Response + * @return mixed */ public function index() { @@ -29,7 +25,7 @@ public function index() /** * Show the form for creating a new resource. * - * @return Response + * @return mixed */ public function create() { @@ -39,7 +35,9 @@ public function create() /** * Store a newly created resource in storage. * - * @return Response + * @param Request $request + * + * @return mixed */ public function store(Request $request) { @@ -47,7 +45,7 @@ public function store(Request $request) Season::create($request->all()); - Flash::success('Season added!'); + \Flash::success('Season added!'); return redirect('admin/data-management/seasons'); } @@ -55,9 +53,9 @@ public function store(Request $request) /** * Display the specified resource. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function show($id) { @@ -69,9 +67,9 @@ public function show($id) /** * Show the form for editing the specified resource. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function edit($id) { @@ -83,18 +81,19 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param int $id + * @param Request $request + * @param int $id * - * @return Response + * @return mixed */ - public function update($id, Request $request) + public function update(Request $request, $id) { $this->validate($request, ['season' => 'required',]); $season = Season::findOrFail($id); $season->update($request->all()); - Flash::success('Season updated!'); + \Flash::success('Season updated!'); return redirect('admin/data-management/seasons'); } @@ -102,18 +101,18 @@ public function update($id, Request $request) /** * Remove the specified resource from storage. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function destroy($id) { $canBeDeleted = empty(Season::find($id)->divisions->toArray()); if ($canBeDeleted) { Season::destroy($id); - Flash::success('Season deleted!'); + \Flash::success('Season deleted!'); } else { - Flash::error('Cannot delete because they are existing divisions in this season.'); + \Flash::error('Cannot delete because they are existing divisions in this season.'); } return redirect('admin/data-management/seasons'); diff --git a/app/Http/Controllers/Admin/DataManagement/TeamsController.php b/app/Http/Controllers/Admin/DataManagement/TeamsController.php index 9c2147a5..3dc558c4 100644 --- a/app/Http/Controllers/Admin/DataManagement/TeamsController.php +++ b/app/Http/Controllers/Admin/DataManagement/TeamsController.php @@ -8,17 +8,13 @@ use App\Models\Club; use App\Models\Team; use Illuminate\Http\Request; -use Carbon\Carbon; -use Session; -use Laracasts\Flash\Flash; class TeamsController extends Controller { - /** * Display a listing of the resource. * - * @return Response + * @return mixed */ public function index() { @@ -30,7 +26,7 @@ public function index() /** * Show the form for creating a new resource. * - * @return Response + * @return mixed */ public function create() { @@ -40,7 +36,9 @@ public function create() /** * Store a newly created resource in storage. * - * @return Response + * @param Request $request + * + * @return mixed */ public function store(Request $request) { @@ -48,7 +46,7 @@ public function store(Request $request) Team::create($request->all()); - Flash::success('Team added!'); + \Flash::success('Team added!'); return redirect('admin/data-management/teams'); } @@ -56,9 +54,9 @@ public function store(Request $request) /** * Display the specified resource. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function show($id) { @@ -70,9 +68,9 @@ public function show($id) /** * Show the form for editing the specified resource. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function edit($id) { @@ -85,18 +83,19 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param int $id + * @param Request $request + * @param int $id * - * @return Response + * @return mixed */ - public function update($id, Request $request) + public function update(Request $request, $id) { $this->validate($request, ['club_id' => 'required', 'team' => 'required']); $team = Team::findOrFail($id); $team->update($request->all()); - Flash::success('Team updated!'); + \Flash::success('Team updated!'); return redirect('admin/data-management/teams'); } @@ -104,9 +103,9 @@ public function update($id, Request $request) /** * Remove the specified resource from storage. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function destroy($id) { @@ -114,9 +113,9 @@ public function destroy($id) $canBeDeleted = empty($team->homeFixtures->toArray()) && empty($team->awayFixtures->toArray()); if ($canBeDeleted) { Team::destroy($id); - Flash::success('Team deleted!'); + \Flash::success('Team deleted!'); } else { - Flash::error('Cannot delete because they are existing fixtures for this team.'); + \Flash::error('Cannot delete because they are existing fixtures for this team.'); } return redirect('admin/data-management/teams'); diff --git a/app/Http/Controllers/Admin/DataManagement/VenuesController.php b/app/Http/Controllers/Admin/DataManagement/VenuesController.php index c57be81c..a51a0a6f 100644 --- a/app/Http/Controllers/Admin/DataManagement/VenuesController.php +++ b/app/Http/Controllers/Admin/DataManagement/VenuesController.php @@ -7,17 +7,13 @@ use App\Models\Venue; use Illuminate\Http\Request; -use Carbon\Carbon; -use Session; -use Laracasts\Flash\Flash; class VenuesController extends Controller { - /** * Display a listing of the resource. * - * @return Response + * @return mixed */ public function index() { @@ -29,7 +25,7 @@ public function index() /** * Show the form for creating a new resource. * - * @return Response + * @return mixed */ public function create() { @@ -39,14 +35,16 @@ public function create() /** * Store a newly created resource in storage. * - * @return Response + * @param Request $request + * + * @return mixed */ public function store(Request $request) { Venue::create($request->all()); - Flash::success('Venue added!'); + \Flash::success('Venue added!'); return redirect('admin/data-management/venues'); } @@ -54,9 +52,9 @@ public function store(Request $request) /** * Display the specified resource. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function show($id) { @@ -68,9 +66,9 @@ public function show($id) /** * Show the form for editing the specified resource. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function edit($id) { @@ -82,17 +80,18 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param int $id + * @param Request $request + * @param int $id * - * @return Response + * @return mixed */ - public function update($id, Request $request) + public function update(Request $request, $id) { $venue = Venue::findOrFail($id); $venue->update($request->all()); - Flash::success('Venue updated!'); + \Flash::success('Venue updated!'); return redirect('admin/data-management/venues'); } @@ -100,18 +99,18 @@ public function update($id, Request $request) /** * Remove the specified resource from storage. * - * @param int $id + * @param int $id * - * @return Response + * @return mixed */ public function destroy($id) { $canBeDeleted = empty(Venue::find($id)->fixtures->toArray()); if ($canBeDeleted) { Venue::destroy($id); - Flash::success('Venue deleted!'); + \Flash::success('Venue deleted!'); } else { - Flash::error('Cannot delete because they are existing fixtures at this venue.'); + \Flash::error('Cannot delete because they are existing fixtures at this venue.'); } return redirect('admin/data-management/venues'); diff --git a/app/Models/AvailableAppointment.php b/app/Models/AvailableAppointment.php index c359a1b4..6de3e5ff 100644 --- a/app/Models/AvailableAppointment.php +++ b/app/Models/AvailableAppointment.php @@ -4,6 +4,23 @@ use Illuminate\Database\Eloquent\Model; +/** + * App\Models\AvailableAppointment + * + * @property-read \App\Models\Fixture $fixture + * @property-read \App\Models\Role $role + * @mixin \Eloquent + * @property integer $id + * @property integer $fixture_id + * @property integer $role_id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @method static \Illuminate\Database\Query\Builder|\App\Models\AvailableAppointment whereId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\AvailableAppointment whereFixtureId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\AvailableAppointment whereRoleId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\AvailableAppointment whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\AvailableAppointment whereUpdatedAt($value) + */ class AvailableAppointment extends Model { diff --git a/app/Models/Club.php b/app/Models/Club.php index 5fa42b1d..914c76e4 100644 --- a/app/Models/Club.php +++ b/app/Models/Club.php @@ -4,6 +4,20 @@ use Illuminate\Database\Eloquent\Model; +/** + * App\Models\Club + * + * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Team[] $teams + * @mixin \Eloquent + * @property integer $id + * @property string $club + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @method static \Illuminate\Database\Query\Builder|\App\Models\Club whereId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Club whereClub($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Club whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Club whereUpdatedAt($value) + */ class Club extends Model { diff --git a/app/Models/Division.php b/app/Models/Division.php index 9e04ea42..6e4d8706 100644 --- a/app/Models/Division.php +++ b/app/Models/Division.php @@ -4,6 +4,23 @@ use Illuminate\Database\Eloquent\Model; +/** + * App\Models\Division + * + * @property-read \App\Models\Season $season + * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Fixture[] $fixtures + * @mixin \Eloquent + * @property integer $id + * @property integer $season_id + * @property string $division + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @method static \Illuminate\Database\Query\Builder|\App\Models\Division whereId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Division whereSeasonId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Division whereDivision($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Division whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Division whereUpdatedAt($value) + */ class Division extends Model { diff --git a/app/Models/Fixture.php b/app/Models/Fixture.php index ac089ca8..a7819f5b 100644 --- a/app/Models/Fixture.php +++ b/app/Models/Fixture.php @@ -5,6 +5,38 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; +/** + * App\Models\Fixture + * + * @property-read \App\Models\Division $division + * @property-read \App\Models\Team $home_team + * @property-read \App\Models\Team $away_team + * @property-read \App\Models\Venue $venue + * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AvailableAppointment[] $available_appointments + * @property-read mixed $warm_up_time + * @property-read mixed $start_time + * @property-read mixed $match_date + * @mixin \Eloquent + * @property integer $id + * @property integer $division_id + * @property integer $match_number + * @property integer $home_team_id + * @property integer $away_team_id + * @property integer $venue_id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereDivisionId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereMatchNumber($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereMatchDate($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereWarmUpTime($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereStartTime($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereHomeTeamId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereAwayTeamId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereVenueId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereUpdatedAt($value) + */ class Fixture extends Model { diff --git a/app/Models/Role.php b/app/Models/Role.php index 3b298806..70cdca04 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -4,6 +4,20 @@ use Illuminate\Database\Eloquent\Model; +/** + * App\Models\Role + * + * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AvailableAppointment[] $available_appointment + * @mixin \Eloquent + * @property integer $id + * @property string $role + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @method static \Illuminate\Database\Query\Builder|\App\Models\Role whereId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Role whereRole($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Role whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Role whereUpdatedAt($value) + */ class Role extends Model { diff --git a/app/Models/Season.php b/app/Models/Season.php index 04b107a3..4b9171ab 100644 --- a/app/Models/Season.php +++ b/app/Models/Season.php @@ -4,6 +4,20 @@ use Illuminate\Database\Eloquent\Model; +/** + * App\Models\Season + * + * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Division[] $divisions + * @mixin \Eloquent + * @property integer $id + * @property string $season + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @method static \Illuminate\Database\Query\Builder|\App\Models\Season whereId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Season whereSeason($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Season whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Season whereUpdatedAt($value) + */ class Season extends Model { diff --git a/app/Models/Team.php b/app/Models/Team.php index 3a8f5dd3..e6c8b2d3 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -4,6 +4,24 @@ use Illuminate\Database\Eloquent\Model; +/** + * App\Models\Team + * + * @property-read \App\Models\Club $club + * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Fixture[] $awayFixtures + * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Fixture[] $homeFixtures + * @mixin \Eloquent + * @property integer $id + * @property integer $club_id + * @property string $team + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @method static \Illuminate\Database\Query\Builder|\App\Models\Team whereId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Team whereClubId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Team whereTeam($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Team whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Team whereUpdatedAt($value) + */ class Team extends Model { diff --git a/app/Models/Venue.php b/app/Models/Venue.php index 073fce48..01dc56bd 100644 --- a/app/Models/Venue.php +++ b/app/Models/Venue.php @@ -4,6 +4,20 @@ use Illuminate\Database\Eloquent\Model; +/** + * App\Models\Venue + * + * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Fixture[] $fixtures + * @mixin \Eloquent + * @property integer $id + * @property string $venue + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @method static \Illuminate\Database\Query\Builder|\App\Models\Venue whereId($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Venue whereVenue($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Venue whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\App\Models\Venue whereUpdatedAt($value) + */ class Venue extends Model { diff --git a/app/User.php b/app/User.php index ef6fe91e..5fe3cafa 100644 --- a/app/User.php +++ b/app/User.php @@ -4,6 +4,25 @@ use Illuminate\Foundation\Auth\User as Authenticatable; +/** + * App\User + * + * @mixin \Eloquent + * @property integer $id + * @property string $name + * @property string $email + * @property string $password + * @property string $remember_token + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @method static \Illuminate\Database\Query\Builder|\App\User whereId($value) + * @method static \Illuminate\Database\Query\Builder|\App\User whereName($value) + * @method static \Illuminate\Database\Query\Builder|\App\User whereEmail($value) + * @method static \Illuminate\Database\Query\Builder|\App\User wherePassword($value) + * @method static \Illuminate\Database\Query\Builder|\App\User whereRememberToken($value) + * @method static \Illuminate\Database\Query\Builder|\App\User whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\App\User whereUpdatedAt($value) + */ class User extends Authenticatable { /** diff --git a/composer.json b/composer.json index 32076539..436d6b94 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "symfony/css-selector": "2.8.*|3.0.*", "symfony/dom-crawler": "2.8.*|3.0.*", "barryvdh/laravel-ide-helper": "^2.1", - "appzcoder/crud-generator": "^1.0" + "appzcoder/crud-generator": "^1.0", + "doctrine/dbal": "~2.3" }, "autoload": { "classmap": [ diff --git a/composer.lock b/composer.lock index f1e9d1b2..f849bae3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "219a7ad7d4d6d10a8dc5329720094583", - "content-hash": "ad5e3ad085634af0ec78e7b6d189b423", + "hash": "5d1223f27a2378ce72fe0a6cf29e26a6", + "content-hash": "1e1a72b5a999e3b23204b8f7039882e0", "packages": [ { "name": "classpreloader/classpreloader", @@ -400,16 +400,16 @@ }, { "name": "laravel/framework", - "version": "v5.2.29", + "version": "v5.2.31", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "e3d644eb131f18c5f3d28ff7bc678bc797091f20" + "reference": "2fa2797604bf54b06faf7bb139a9fc0d66826fea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/e3d644eb131f18c5f3d28ff7bc678bc797091f20", - "reference": "e3d644eb131f18c5f3d28ff7bc678bc797091f20", + "url": "https://api.github.com/repos/laravel/framework/zipball/2fa2797604bf54b06faf7bb139a9fc0d66826fea", + "reference": "2fa2797604bf54b06faf7bb139a9fc0d66826fea", "shasum": "" }, "require": { @@ -470,7 +470,7 @@ }, "require-dev": { "aws/aws-sdk-php": "~3.0", - "mockery/mockery": "~0.9.2", + "mockery/mockery": "~0.9.4", "pda/pheanstalk": "~3.0", "phpunit/phpunit": "~4.1", "predis/predis": "~1.0", @@ -488,7 +488,8 @@ "predis/predis": "Required to use the redis cache and queue drivers (~1.0).", "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (~2.0).", "symfony/css-selector": "Required to use some of the crawler integration testing tools (2.8.*|3.0.*).", - "symfony/dom-crawler": "Required to use most of the crawler integration testing tools (2.8.*|3.0.*)." + "symfony/dom-crawler": "Required to use most of the crawler integration testing tools (2.8.*|3.0.*).", + "symfony/psr-http-message-bridge": "Required to psr7 bridging features (0.2.*)." }, "type": "library", "extra": { @@ -524,7 +525,7 @@ "framework", "laravel" ], - "time": "2016-04-03 01:43:55" + "time": "2016-04-27 13:02:09" }, { "name": "laravelcollective/html", @@ -582,16 +583,16 @@ }, { "name": "league/flysystem", - "version": "1.0.20", + "version": "1.0.22", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "e87a786e3ae12a25cf78a71bb07b4b384bfaa83a" + "reference": "bd73a91703969a2d20ab4bfbf971d6c2cbe36612" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/e87a786e3ae12a25cf78a71bb07b4b384bfaa83a", - "reference": "e87a786e3ae12a25cf78a71bb07b4b384bfaa83a", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/bd73a91703969a2d20ab4bfbf971d6c2cbe36612", + "reference": "bd73a91703969a2d20ab4bfbf971d6c2cbe36612", "shasum": "" }, "require": { @@ -661,20 +662,20 @@ "sftp", "storage" ], - "time": "2016-03-14 21:54:11" + "time": "2016-04-28 06:53:12" }, { "name": "monolog/monolog", - "version": "1.18.2", + "version": "1.19.0", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "064b38c16790249488e7a8b987acf1c9d7383c09" + "reference": "5f56ed5212dc509c8dc8caeba2715732abb32dbf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/064b38c16790249488e7a8b987acf1c9d7383c09", - "reference": "064b38c16790249488e7a8b987acf1c9d7383c09", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/5f56ed5212dc509c8dc8caeba2715732abb32dbf", + "reference": "5f56ed5212dc509c8dc8caeba2715732abb32dbf", "shasum": "" }, "require": { @@ -739,7 +740,7 @@ "logging", "psr-3" ], - "time": "2016-04-02 13:12:58" + "time": "2016-04-12 18:29:35" }, { "name": "mtdowling/cron-expression", @@ -834,16 +835,16 @@ }, { "name": "nikic/php-parser", - "version": "v2.0.1", + "version": "v2.1.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "ce5be709d59b32dd8a88c80259028759991a4206" + "reference": "47b254ea51f1d6d5dc04b9b299e88346bf2369e3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/ce5be709d59b32dd8a88c80259028759991a4206", - "reference": "ce5be709d59b32dd8a88c80259028759991a4206", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/47b254ea51f1d6d5dc04b9b299e88346bf2369e3", + "reference": "47b254ea51f1d6d5dc04b9b299e88346bf2369e3", "shasum": "" }, "require": { @@ -859,7 +860,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "2.1-dev" } }, "autoload": { @@ -881,7 +882,7 @@ "parser", "php" ], - "time": "2016-02-28 19:48:28" + "time": "2016-04-19 13:41:41" }, { "name": "paragonie/random_compat", @@ -1875,23 +1876,23 @@ }, { "name": "vlucas/phpdotenv", - "version": "v2.2.0", + "version": "v2.2.1", "source": { "type": "git", "url": "https://github.com/vlucas/phpdotenv.git", - "reference": "9caf304153dc2288e4970caec6f1f3b3bc205412" + "reference": "63f37b9395e8041cd4313129c08ece896d06ca8e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/9caf304153dc2288e4970caec6f1f3b3bc205412", - "reference": "9caf304153dc2288e4970caec6f1f3b3bc205412", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/63f37b9395e8041cd4313129c08ece896d06ca8e", + "reference": "63f37b9395e8041cd4313129c08ece896d06ca8e", "shasum": "" }, "require": { "php": ">=5.3.9" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.0" + "phpunit/phpunit": "^4.8 || ^5.0" }, "type": "library", "extra": { @@ -1906,7 +1907,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD" + "BSD-3-Clause-Attribution" ], "authors": [ { @@ -1916,28 +1917,27 @@ } ], "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", - "homepage": "http://github.com/vlucas/phpdotenv", "keywords": [ "dotenv", "env", "environment" ], - "time": "2015-12-29 15:10:30" + "time": "2016-04-15 10:48:49" } ], "packages-dev": [ { "name": "appzcoder/crud-generator", - "version": "v1.0.7", + "version": "v1.0.8", "source": { "type": "git", "url": "https://github.com/appzcoder/crud-generator.git", - "reference": "4363192ba2c910057088a48a42fecd719eb0c262" + "reference": "f1dee5a78f963fada17bb0d003b988e3137c4fe9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appzcoder/crud-generator/zipball/4363192ba2c910057088a48a42fecd719eb0c262", - "reference": "4363192ba2c910057088a48a42fecd719eb0c262", + "url": "https://api.github.com/repos/appzcoder/crud-generator/zipball/f1dee5a78f963fada17bb0d003b988e3137c4fe9", + "reference": "f1dee5a78f963fada17bb0d003b988e3137c4fe9", "shasum": "" }, "require": { @@ -1968,7 +1968,7 @@ "laravel", "laravel crud generator" ], - "time": "2016-02-06 19:14:18" + "time": "2016-04-26 18:29:26" }, { "name": "barryvdh/laravel-ide-helper", @@ -2033,6 +2033,354 @@ ], "time": "2016-03-03 08:45:00" }, + { + "name": "doctrine/annotations", + "version": "v1.2.7", + "source": { + "type": "git", + "url": "https://github.com/doctrine/annotations.git", + "reference": "f25c8aab83e0c3e976fd7d19875f198ccf2f7535" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/f25c8aab83e0c3e976fd7d19875f198ccf2f7535", + "reference": "f25c8aab83e0c3e976fd7d19875f198ccf2f7535", + "shasum": "" + }, + "require": { + "doctrine/lexer": "1.*", + "php": ">=5.3.2" + }, + "require-dev": { + "doctrine/cache": "1.*", + "phpunit/phpunit": "4.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Annotations\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Docblock Annotations Parser", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "docblock", + "parser" + ], + "time": "2015-08-31 12:32:49" + }, + { + "name": "doctrine/cache", + "version": "v1.6.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/cache.git", + "reference": "f8af318d14bdb0eff0336795b428b547bd39ccb6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/cache/zipball/f8af318d14bdb0eff0336795b428b547bd39ccb6", + "reference": "f8af318d14bdb0eff0336795b428b547bd39ccb6", + "shasum": "" + }, + "require": { + "php": "~5.5|~7.0" + }, + "conflict": { + "doctrine/common": ">2.2,<2.4" + }, + "require-dev": { + "phpunit/phpunit": "~4.8|~5.0", + "predis/predis": "~1.0", + "satooshi/php-coveralls": "~0.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Caching library offering an object-oriented API for many cache backends", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "cache", + "caching" + ], + "time": "2015-12-31 16:37:02" + }, + { + "name": "doctrine/collections", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/collections.git", + "reference": "6c1e4eef75f310ea1b3e30945e9f06e652128b8a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/collections/zipball/6c1e4eef75f310ea1b3e30945e9f06e652128b8a", + "reference": "6c1e4eef75f310ea1b3e30945e9f06e652128b8a", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Collections\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Collections Abstraction library", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "array", + "collections", + "iterator" + ], + "time": "2015-04-14 22:21:58" + }, + { + "name": "doctrine/common", + "version": "v2.6.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/common.git", + "reference": "a579557bc689580c19fee4e27487a67fe60defc0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/common/zipball/a579557bc689580c19fee4e27487a67fe60defc0", + "reference": "a579557bc689580c19fee4e27487a67fe60defc0", + "shasum": "" + }, + "require": { + "doctrine/annotations": "1.*", + "doctrine/cache": "1.*", + "doctrine/collections": "1.*", + "doctrine/inflector": "1.*", + "doctrine/lexer": "1.*", + "php": "~5.5|~7.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.8|~5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\": "lib/Doctrine/Common" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common Library for Doctrine projects", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "collections", + "eventmanager", + "persistence", + "spl" + ], + "time": "2015-12-25 13:18:31" + }, + { + "name": "doctrine/dbal", + "version": "v2.5.4", + "source": { + "type": "git", + "url": "https://github.com/doctrine/dbal.git", + "reference": "abbdfd1cff43a7b99d027af3be709bc8fc7d4769" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/abbdfd1cff43a7b99d027af3be709bc8fc7d4769", + "reference": "abbdfd1cff43a7b99d027af3be709bc8fc7d4769", + "shasum": "" + }, + "require": { + "doctrine/common": ">=2.4,<2.7-dev", + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "4.*", + "symfony/console": "2.*" + }, + "suggest": { + "symfony/console": "For helpful console commands such as SQL execution and import of files." + }, + "bin": [ + "bin/doctrine-dbal" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.5.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\DBAL\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Database Abstraction Layer", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database", + "dbal", + "persistence", + "queryobject" + ], + "time": "2016-01-05 22:11:12" + }, { "name": "doctrine/instantiator", "version": "1.0.5", @@ -2087,35 +2435,85 @@ ], "time": "2015-06-14 21:17:01" }, + { + "name": "doctrine/lexer", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Lexer\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "lexer", + "parser" + ], + "time": "2014-09-09 13:34:57" + }, { "name": "fzaninotto/faker", - "version": "v1.5.0", + "version": "v1.6.0", "source": { "type": "git", "url": "https://github.com/fzaninotto/Faker.git", - "reference": "d0190b156bcca848d401fb80f31f504f37141c8d" + "reference": "44f9a286a04b80c76a4e5fb7aad8bb539b920123" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/d0190b156bcca848d401fb80f31f504f37141c8d", - "reference": "d0190b156bcca848d401fb80f31f504f37141c8d", + "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/44f9a286a04b80c76a4e5fb7aad8bb539b920123", + "reference": "44f9a286a04b80c76a4e5fb7aad8bb539b920123", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3|^7.0" }, "require-dev": { + "ext-intl": "*", "phpunit/phpunit": "~4.0", "squizlabs/php_codesniffer": "~1.5" }, - "suggest": { - "ext-intl": "*" - }, "type": "library", "extra": { - "branch-alias": { - "dev-master": "1.5.x-dev" - } + "branch-alias": [] }, "autoload": { "psr-4": { @@ -2137,7 +2535,7 @@ "faker", "fixtures" ], - "time": "2015-05-29 06:29:14" + "time": "2016-04-29 12:21:54" }, { "name": "hamcrest/hamcrest-php", @@ -2251,16 +2649,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.5.0", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "e3abefcd7f106677fd352cd7c187d6c969aa9ddc" + "reference": "a8773992b362b58498eed24bf85005f363c34771" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/e3abefcd7f106677fd352cd7c187d6c969aa9ddc", - "reference": "e3abefcd7f106677fd352cd7c187d6c969aa9ddc", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/a8773992b362b58498eed24bf85005f363c34771", + "reference": "a8773992b362b58498eed24bf85005f363c34771", "shasum": "" }, "require": { @@ -2289,7 +2687,7 @@ "object", "object graph" ], - "time": "2015-11-07 22:20:37" + "time": "2015-11-20 12:04:31" }, { "name": "phpdocumentor/reflection-docblock", @@ -2404,16 +2802,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "3.3.0", + "version": "3.3.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "fe33716763b604ade4cb442c0794f5bd5ad73004" + "reference": "2431befdd451fac43fbcde94d1a92fb3b8b68f86" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/fe33716763b604ade4cb442c0794f5bd5ad73004", - "reference": "fe33716763b604ade4cb442c0794f5bd5ad73004", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2431befdd451fac43fbcde94d1a92fb3b8b68f86", + "reference": "2431befdd451fac43fbcde94d1a92fb3b8b68f86", "shasum": "" }, "require": { @@ -2431,7 +2829,7 @@ }, "suggest": { "ext-dom": "*", - "ext-xdebug": ">=2.2.1", + "ext-xdebug": ">=2.4.0", "ext-xmlwriter": "*" }, "type": "library", @@ -2463,7 +2861,7 @@ "testing", "xunit" ], - "time": "2016-03-03 08:49:08" + "time": "2016-04-08 08:14:53" }, { "name": "phpunit/php-file-iterator", @@ -2719,16 +3117,16 @@ }, { "name": "phpunit/phpunit-mock-objects", - "version": "3.1.2", + "version": "3.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "7c34c9bdde4131b824086457a3145e27dba10ca1" + "reference": "151c96874bff6fe61a25039df60e776613a61489" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/7c34c9bdde4131b824086457a3145e27dba10ca1", - "reference": "7c34c9bdde4131b824086457a3145e27dba10ca1", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/151c96874bff6fe61a25039df60e776613a61489", + "reference": "151c96874bff6fe61a25039df60e776613a61489", "shasum": "" }, "require": { @@ -2771,7 +3169,7 @@ "mock", "xunit" ], - "time": "2016-03-24 05:58:25" + "time": "2016-04-20 14:39:26" }, { "name": "sebastian/code-unit-reverse-lookup", diff --git a/resources/crud-generator/controller.stub b/resources/crud-generator/controller.stub index 467c8e06..4915cef5 100644 --- a/resources/crud-generator/controller.stub +++ b/resources/crud-generator/controller.stub @@ -9,11 +9,9 @@ use DummyRootNamespaceModels\{{modelName}}; use Illuminate\Http\Request; use Carbon\Carbon; use Session; -use Laracasts\Flash\Flash; class DummyClass extends Controller { - /** * Display a listing of the resource. * @@ -39,6 +37,8 @@ class DummyClass extends Controller /** * Store a newly created resource in storage. * + * @param Request $request + * * @return Response */ public function store(Request $request) @@ -46,7 +46,7 @@ class DummyClass extends Controller {{validationRules}} {{modelName}}::create($request->all()); - Flash::success('{{modelName}} added!'); + \Flash::success('{{modelName}} added!'); return redirect('{{routeGroup}}{{crudName}}'); } @@ -82,17 +82,18 @@ class DummyClass extends Controller /** * Update the specified resource in storage. * + * @param Request $request * @param int $id * * @return Response */ - public function update($id, Request $request) + public function update(Request $request, $id) { {{validationRules}} ${{crudNameSingular}} = {{modelName}}::findOrFail($id); ${{crudNameSingular}}->update($request->all()); - Flash::success('{{modelName}} updated!'); + \Flash::success('{{modelName}} updated!'); return redirect('{{routeGroup}}{{crudName}}'); } @@ -108,7 +109,7 @@ class DummyClass extends Controller { {{modelName}}::destroy($id); - Flash::success('{{modelName}} deleted!'); + \Flash::success('{{modelName}} deleted!'); return redirect('{{routeGroup}}{{crudName}}'); } From e1ed3e2e0d5a34094e79c1bd2f9f526cf8fdd386 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Mon, 2 May 2016 17:01:16 +0100 Subject: [PATCH 18/34] dev: Cleaned up the layout of the Data Management pages --- .../views/_partial/crud-errors.blade.php | 7 + .../available-appointments/create.blade.php | 20 +-- .../available-appointments/edit.blade.php | 18 +-- .../available-appointments/index.blade.php | 18 +-- .../available-appointments/show.blade.php | 16 +- .../data-management/clubs/create.blade.php | 46 +++--- .../data-management/clubs/edit.blade.php | 62 ++++---- .../data-management/clubs/index.blade.php | 65 ++++---- .../data-management/clubs/show.blade.php | 30 ++-- .../divisions/create.blade.php | 59 ++++--- .../data-management/divisions/edit.blade.php | 75 +++++---- .../data-management/divisions/index.blade.php | 65 ++++---- .../data-management/divisions/show.blade.php | 32 ++-- .../data-management/fixtures/create.blade.php | 137 +++++++++-------- .../data-management/fixtures/edit.blade.php | 145 +++++++++--------- .../data-management/fixtures/index.blade.php | 28 ++-- .../data-management/fixtures/show.blade.php | 4 +- .../admin/data-management/home.blade.php | 51 ++++-- .../data-management/roles/create.blade.php | 46 +++--- .../data-management/roles/edit.blade.php | 62 ++++---- .../data-management/roles/index.blade.php | 62 ++++---- .../data-management/roles/show.blade.php | 30 ++-- .../data-management/seasons/create.blade.php | 46 +++--- .../data-management/seasons/edit.blade.php | 62 ++++---- .../data-management/seasons/index.blade.php | 15 +- .../data-management/seasons/show.blade.php | 30 ++-- .../data-management/teams/create.blade.php | 59 ++++--- .../data-management/teams/edit.blade.php | 75 +++++---- .../data-management/teams/index.blade.php | 65 ++++---- .../data-management/teams/show.blade.php | 32 ++-- .../data-management/venues/create.blade.php | 46 +++--- .../data-management/venues/edit.blade.php | 62 ++++---- .../data-management/venues/index.blade.php | 62 ++++---- .../data-management/venues/show.blade.php | 30 ++-- 34 files changed, 823 insertions(+), 839 deletions(-) create mode 100644 resources/views/_partial/crud-errors.blade.php diff --git a/resources/views/_partial/crud-errors.blade.php b/resources/views/_partial/crud-errors.blade.php new file mode 100644 index 00000000..74969955 --- /dev/null +++ b/resources/views/_partial/crud-errors.blade.php @@ -0,0 +1,7 @@ +@if ($errors->any()) +
+ @foreach ($errors->all() as $error) +

{{ $error }}

+ @endforeach +
+@endif \ No newline at end of file diff --git a/resources/views/admin/data-management/available-appointments/create.blade.php b/resources/views/admin/data-management/available-appointments/create.blade.php index c646e2f9..04982b85 100644 --- a/resources/views/admin/data-management/available-appointments/create.blade.php +++ b/resources/views/admin/data-management/available-appointments/create.blade.php @@ -1,6 +1,6 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud')
-

Create new appointment

+

Add new appointment


- @if ($errors->any()) -
- @foreach ($errors->all() as $error) -

{{ $error }}

- @endforeach -
- @endif + @include('_partial.crud-errors'); {!! Form::open(['url' => 'admin/data-management/available-appointments', 'class' => 'form-horizontal']) !!} @@ -29,6 +23,7 @@ {!! $errors->first('fixture_id', '

:message

') !!}
+
{!! Form::label('role_id', 'Role: ', ['class' => 'col-sm-3 control-label']) !!}
@@ -39,12 +34,11 @@
- {!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!} + {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!}
- {!! Form::close() !!} - + {!! Form::close() !!}
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/available-appointments/edit.blade.php b/resources/views/admin/data-management/available-appointments/edit.blade.php index ab06e107..a3869386 100644 --- a/resources/views/admin/data-management/available-appointments/edit.blade.php +++ b/resources/views/admin/data-management/available-appointments/edit.blade.php @@ -1,6 +1,6 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') Edit appointment
- @if ($errors->any()) -
- @foreach ($errors->all() as $error) -

{{ $error }}

- @endforeach -
- @endif + @include('_partial.crud-errors'); {!! Form::model($availableAppointment, [ 'method' => 'PATCH', @@ -28,6 +22,7 @@ ]) !!} {!! Form::hidden('id', $availableAppointment->id) !!} +
{!! Form::label('fixture_id', 'Fixture: ', ['class' => 'col-sm-3 control-label']) !!}
@@ -35,6 +30,7 @@ {!! $errors->first('fixture_id', '

:message

') !!}
+
{!! Form::label('role_id', 'Role: ', ['class' => 'col-sm-3 control-label']) !!}
@@ -43,15 +39,13 @@
-
{!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!}
- {!! Form::close() !!} - + {!! Form::close() !!}
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/available-appointments/index.blade.php b/resources/views/admin/data-management/available-appointments/index.blade.php index 594b28b7..64e24052 100644 --- a/resources/views/admin/data-management/available-appointments/index.blade.php +++ b/resources/views/admin/data-management/available-appointments/index.blade.php @@ -1,10 +1,10 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud')

Available appointments Add New Appointment

+ class="btn btn-primary pull-right btn-sm">New appointment
@@ -15,21 +15,21 @@ class="btn btn-primary pull-right btn-sm">Add New Appointment - @foreach($availableAppointments as $item) + @foreach($availableAppointments as $appointment) - + + + @endforeach + +
- - {{ $item->fixture }} + + {{ $appointment->fixture }} {{ $item->role->role }}{{ $appointment->role->role }} - + / {!! Form::open([ 'method'=>'DELETE', - 'url' => ['admin/data-management/available-appointments', $item->id], + 'url' => ['admin/data-management/available-appointments', $appointment->id], 'style' => 'display:inline' ]) !!} {!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs', 'data-toggle' => 'confirmation']) !!} diff --git a/resources/views/admin/data-management/available-appointments/show.blade.php b/resources/views/admin/data-management/available-appointments/show.blade.php index a4681380..4a003e4f 100644 --- a/resources/views/admin/data-management/available-appointments/show.blade.php +++ b/resources/views/admin/data-management/available-appointments/show.blade.php @@ -1,23 +1,23 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud')
-

Availableappointment

+

Available appointment

- - + + - - - + + +
IdFixture IdRole IdFixtureRole
{{ $availableappointment->id }} {{ $availableappointment->fixture_id }} {{ $availableappointment->role_id }} {{ $availableAppointment->id }}{{ $availableAppointment->fixture }}{{ $availableAppointment->role }}
diff --git a/resources/views/admin/data-management/clubs/create.blade.php b/resources/views/admin/data-management/clubs/create.blade.php index 5a7b7597..d17dcfd9 100644 --- a/resources/views/admin/data-management/clubs/create.blade.php +++ b/resources/views/admin/data-management/clubs/create.blade.php @@ -1,36 +1,30 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Create New Club

-
+
+

Add new club

+
- {!! Form::open(['url' => 'admin/data-management/clubs', 'class' => 'form-horizontal']) !!} + @include('_partial.crud-errors'); -
- {!! Form::label('club', 'Club: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::text('club', null, ['class' => 'form-control']) !!} - {!! $errors->first('club', '

:message

') !!} -
-
+ {!! Form::open(['url' => 'admin/data-management/clubs', 'class' => 'form-horizontal']) !!} +
+ {!! Form::label('club', 'Club: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('club', null, ['class' => 'form-control']) !!} + {!! $errors->first('club', '

:message

') !!} +
+
-
-
- {!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!} +
+ + {!! Form::close() !!}
- {!! Form::close() !!} - - @if ($errors->any()) -
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
- @endif -
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/clubs/edit.blade.php b/resources/views/admin/data-management/clubs/edit.blade.php index 6327d663..e6365523 100644 --- a/resources/views/admin/data-management/clubs/edit.blade.php +++ b/resources/views/admin/data-management/clubs/edit.blade.php @@ -1,40 +1,34 @@ -@extends('layouts.app') - -@section('content') - -
-

Edit Club

-
- - {!! Form::model($club, [ - 'method' => 'PATCH', - 'url' => ['admin/data-management/clubs', $club->id], - 'class' => 'form-horizontal' - ]) !!} - -
- {!! Form::label('club', 'Club: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::text('club', null, ['class' => 'form-control']) !!} - {!! $errors->first('club', '

:message

') !!} -
-
+@extends('admin.data-management.home') + +@section('crud') + +
+

Edit club

+
+ @include('_partial.crud-errors'); -
-
- {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} + {!! Form::model($club, [ + 'method' => 'PATCH', + 'url' => ['admin/data-management/clubs', $club->id], + 'class' => 'form-horizontal' + ]) !!} + +
+ {!! Form::label('club', 'Club: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('club', null, ['class' => 'form-control']) !!} + {!! $errors->first('club', '

:message

') !!} +
+ +
+
+ {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} +
+
+ + {!! Form::close() !!}
- {!! Form::close() !!} - - @if ($errors->any()) -
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
- @endif -
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/clubs/index.blade.php b/resources/views/admin/data-management/clubs/index.blade.php index 0a8cf4f2..7f0630aa 100644 --- a/resources/views/admin/data-management/clubs/index.blade.php +++ b/resources/views/admin/data-management/clubs/index.blade.php @@ -1,42 +1,41 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Clubs Add New Club

-
- - +
+

Clubs New + club

+
+
+ - + + - - - {{-- */$x=0;/* --}} - @foreach($clubs as $item) - {{-- */$x++;/* --}} - - - - + @foreach($clubs as $club) + + + - - @endforeach - -
IdClubActionsClubActions
{{ $x }}{{ $item->club }} - - - / - {!! Form::open([ - 'method'=>'DELETE', - 'url' => ['admin/data-management/clubs', $item->id], - 'style' => 'display:inline' - ]) !!} + +
{{ $club->club }} + + + / + {!! Form::open([ + 'method'=>'DELETE', + 'url' => ['admin/data-management/clubs', $club->id], + 'style' => 'display:inline' + ]) !!} {!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs', 'data-toggle' => 'confirmation']) !!} - {!! Form::close() !!} -
- + {!! Form::close() !!} +
+ +
- @endsection diff --git a/resources/views/admin/data-management/clubs/show.blade.php b/resources/views/admin/data-management/clubs/show.blade.php index 5b24b5db..413d4200 100644 --- a/resources/views/admin/data-management/clubs/show.blade.php +++ b/resources/views/admin/data-management/clubs/show.blade.php @@ -1,23 +1,25 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Club

-
- - +
+

Club

+
+
+ - + + - - + + - + + - -
IdClubIdClub
{{ $club->id }} {{ $club->club }} {{ $club->id }}{{ $club->club }}
+
+ - @endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/divisions/create.blade.php b/resources/views/admin/data-management/divisions/create.blade.php index fd413be4..c55ce55e 100644 --- a/resources/views/admin/data-management/divisions/create.blade.php +++ b/resources/views/admin/data-management/divisions/create.blade.php @@ -1,43 +1,38 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Create New Division

-
+
+

Add new division

+
- {!! Form::open(['url' => 'admin/data-management/divisions', 'class' => 'form-horizontal']) !!} + @include('_partial.crud-errors'); -
- {!! Form::label('season_id', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::select('season_id', array_column($seasons->toArray(), 'season', 'id'), null, ['class' => 'form-control']) !!} - {!! $errors->first('season_id', '

:message

') !!} -
-
-
- {!! Form::label('division', 'Division: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::text('division', null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('division', '

:message

') !!} -
+ {!! Form::open(['url' => 'admin/data-management/divisions', 'class' => 'form-horizontal']) !!} + +
+ {!! Form::label('season_id', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('season_id', array_column($seasons->toArray(), 'season', 'id'), null, ['class' => 'form-control']) !!} + {!! $errors->first('season_id', '

:message

') !!}
+
+
+ {!! Form::label('division', 'Division: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('division', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('division', '

:message

') !!} +
+
-
-
- {!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!} +
+ + {!! Form::close() !!}
- {!! Form::close() !!} - - @if ($errors->any()) -
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
- @endif -
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/divisions/edit.blade.php b/resources/views/admin/data-management/divisions/edit.blade.php index f012afae..bb319aa0 100644 --- a/resources/views/admin/data-management/divisions/edit.blade.php +++ b/resources/views/admin/data-management/divisions/edit.blade.php @@ -1,47 +1,42 @@ -@extends('layouts.app') - -@section('content') - -
-

Edit Division

-
- - {!! Form::model($division, [ - 'method' => 'PATCH', - 'url' => ['admin/data-management/divisions', $division->id], - 'class' => 'form-horizontal' - ]) !!} - -
- {!! Form::label('season_id', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::select('season_id', array_column($seasons->toArray(), 'season', 'id'), $division->season->id, ['class' => 'form-control']) !!} - {!! $errors->first('season_id', '

:message

') !!} -
-
-
- {!! Form::label('division', 'Division: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::text('division', null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('division', '

:message

') !!} -
+@extends('admin.data-management.home') + +@section('crud') + +
+

Edit division

+
+ + @include('_partial.crud-errors'); + + {!! Form::model($division, [ + 'method' => 'PATCH', + 'url' => ['admin/data-management/divisions', $division->id], + 'class' => 'form-horizontal' + ]) !!} + +
+ {!! Form::label('season_id', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('season_id', array_column($seasons->toArray(), 'season', 'id'), $division->season->id, ['class' => 'form-control']) !!} + {!! $errors->first('season_id', '

:message

') !!}
+
+
+ {!! Form::label('division', 'Division: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('division', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('division', '

:message

') !!} +
+
-
-
- {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} +
+ + {!! Form::close() !!}
- {!! Form::close() !!} - - @if ($errors->any()) -
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
- @endif -
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/divisions/index.blade.php b/resources/views/admin/data-management/divisions/index.blade.php index 751dda14..e57c4374 100644 --- a/resources/views/admin/data-management/divisions/index.blade.php +++ b/resources/views/admin/data-management/divisions/index.blade.php @@ -1,40 +1,45 @@ @extends('layouts.app') -@section('content') +@section('crud') -
-

Divisions Add New Division

-
- - +
+

Divisions New division

+
+
+ - + + + - - - @foreach($divisions as $item) - - - - + @foreach($divisions as $division) + + + + - - @endforeach - -
SeasonDivisionActionsSeasonDivisionActions
{{ $item->season->season }}{{ $item->division }} - - - / - {!! Form::open([ - 'method'=>'DELETE', - 'url' => ['admin/data-management/divisions', $item->id], - 'style' => 'display:inline' - ]) !!} + +
{{ $division->season->season }} + {{ $division->division }} + + + + / + {!! Form::open([ + 'method'=>'DELETE', + 'url' => ['admin/data-management/divisions', $division->id], + 'style' => 'display:inline' + ]) !!} {!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs', 'data-toggle' => 'confirmation']) !!} - {!! Form::close() !!} -
- + {!! Form::close() !!} +
+ + - @endsection diff --git a/resources/views/admin/data-management/divisions/show.blade.php b/resources/views/admin/data-management/divisions/show.blade.php index 2d856b9c..61b293eb 100644 --- a/resources/views/admin/data-management/divisions/show.blade.php +++ b/resources/views/admin/data-management/divisions/show.blade.php @@ -1,23 +1,27 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Division

-
- - +
+

Division

+
+
+ - + + + - - + + - + + + - -
Id SeasonDivisionIdSeasonDivision
{{ $division->id }} {{ $division->season->season }} {{ $division->division }} {{ $division->id }}{{ $division->season->season }}{{ $division->division }}
+
+ - @endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/fixtures/create.blade.php b/resources/views/admin/data-management/fixtures/create.blade.php index b95fd5d6..a57313ac 100644 --- a/resources/views/admin/data-management/fixtures/create.blade.php +++ b/resources/views/admin/data-management/fixtures/create.blade.php @@ -1,85 +1,86 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Create New Fixture

-
+
+

Add new fixture

+
- {!! Form::open(['url' => 'admin/data-management/fixtures', 'class' => 'form-horizontal']) !!} + @include('_partial.crud-errors'); -
- {!! Form::label('division_id', 'Division: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::select('division_id', array_column($divisions->toArray(), 'division', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('division_id', '

:message

') !!} -
-
-
- {!! Form::label('match_number', 'Match Number: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('match_number', '

:message

') !!} -
+ {!! Form::open(['url' => 'admin/data-management/fixtures', 'class' => 'form-horizontal']) !!} + +
+ {!! Form::label('division_id', 'Division: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('division_id', array_column($divisions->toArray(), 'division', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('division_id', '

:message

') !!}
-
- {!! Form::label('match_date', 'Match Date: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::date('match_date', null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('match_date', '

:message

') !!} -
+
+ +
+ {!! Form::label('match_number', 'Match Number: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('match_number', '

:message

') !!}
-
- {!! Form::label('warm_up_time', 'Warm Up Time: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::input('time', 'warm_up_time', null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('warm_up_time', '

:message

') !!} -
+
+ +
+ {!! Form::label('match_date', 'Match Date: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::date('match_date', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('match_date', '

:message

') !!}
-
- {!! Form::label('start_time', 'Start Time: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::input('time', 'start_time', null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('start_time', '

:message

') !!} -
+
+ +
+ {!! Form::label('warm_up_time', 'Warm Up Time: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::input('time', 'warm_up_time', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('warm_up_time', '

:message

') !!}
-
- {!! Form::label('home_team_id', 'Home Team: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::select('home_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('home_team_id', '

:message

') !!} -
+
+ +
+ {!! Form::label('start_time', 'Start Time: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::input('time', 'start_time', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('start_time', '

:message

') !!}
-
- {!! Form::label('away_team_id', 'Away Team: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::select('away_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('away_team_id', '

:message

') !!} -
+
+ +
+ {!! Form::label('home_team_id', 'Home Team: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('home_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('home_team_id', '

:message

') !!}
-
- {!! Form::label('venue_id', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::select('venue_id', array_column($venues->toArray(), 'venue', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('venue_id', '

:message

') !!} -
+
+ +
+ {!! Form::label('away_team_id', 'Away Team: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('away_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('away_team_id', '

:message

') !!}
+
+
+ {!! Form::label('venue_id', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('venue_id', array_column($venues->toArray(), 'venue', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('venue_id', '

:message

') !!} +
+
-
-
- {!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!} +
-
- {!! Form::close() !!} - @if ($errors->any()) -
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
- @endif -
+ {!! Form::close() !!} +
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/fixtures/edit.blade.php b/resources/views/admin/data-management/fixtures/edit.blade.php index d5b76b63..67ef3b55 100644 --- a/resources/views/admin/data-management/fixtures/edit.blade.php +++ b/resources/views/admin/data-management/fixtures/edit.blade.php @@ -1,89 +1,90 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Edit Fixture

-
+
+

Edit fixture

+
- {!! Form::model($fixture, [ - 'method' => 'PATCH', - 'url' => ['admin/data-management/fixtures', $fixture->id], - 'class' => 'form-horizontal' - ]) !!} + @include('_partial.crud-errors'); -
- {!! Form::label('division_id', 'Division Id: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::select('division_id', array_column($divisions->toArray(), 'division', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('division_id', '

:message

') !!} -
-
-
- {!! Form::label('match_number', 'Match Number: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('match_number', '

:message

') !!} -
+ {!! Form::model($fixture, [ + 'method' => 'PATCH', + 'url' => ['admin/data-management/fixtures', $fixture->id], + 'class' => 'form-horizontal' + ]) !!} + +
+ {!! Form::label('division_id', 'Division Id: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('division_id', array_column($divisions->toArray(), 'division', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('division_id', '

:message

') !!}
-
- {!! Form::label('match_date', 'Match Date: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::date('match_date', $fixture->match_date->format('Y-m-d'), ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('match_date', '

:message

') !!} -
+
+ +
+ {!! Form::label('match_number', 'Match Number: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('match_number', '

:message

') !!}
-
- {!! Form::label('warm_up_time', 'Warm Up Time: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::input('time', 'warm_up_time', $fixture->warm_up_time->format('H:i'), ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('warm_up_time', '

:message

') !!} -
+
+ +
+ {!! Form::label('match_date', 'Match Date: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::date('match_date', $fixture->match_date->format('Y-m-d'), ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('match_date', '

:message

') !!}
-
- {!! Form::label('start_time', 'Start Time: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::input('time', 'start_time', $fixture->start_time->format('H:i'), ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('start_time', '

:message

') !!} -
+
+ +
+ {!! Form::label('warm_up_time', 'Warm Up Time: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::input('time', 'warm_up_time', $fixture->warm_up_time->format('H:i'), ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('warm_up_time', '

:message

') !!}
-
- {!! Form::label('home_team_id', 'Home Team Id: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::select('home_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('home_team_id', '

:message

') !!} -
+
+ +
+ {!! Form::label('start_time', 'Start Time: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::input('time', 'start_time', $fixture->start_time->format('H:i'), ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('start_time', '

:message

') !!}
-
- {!! Form::label('away_team_id', 'Away Team Id: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::select('away_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('away_team_id', '

:message

') !!} -
+
+ +
+ {!! Form::label('home_team_id', 'Home Team Id: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('home_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('home_team_id', '

:message

') !!}
-
- {!! Form::label('venue_id', 'Venue Id: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::select('venue_id', array_column($venues->toArray(), 'venue', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('venue_id', '

:message

') !!} -
+
+ +
+ {!! Form::label('away_team_id', 'Away Team Id: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('away_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('away_team_id', '

:message

') !!}
+
+
+ {!! Form::label('venue_id', 'Venue Id: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('venue_id', array_column($venues->toArray(), 'venue', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('venue_id', '

:message

') !!} +
+
-
-
- {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} +
-
- {!! Form::close() !!} - @if ($errors->any()) -
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
- @endif -
+ {!! Form::close() !!} +
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/fixtures/index.blade.php b/resources/views/admin/data-management/fixtures/index.blade.php index 2b2287dd..b18ab69a 100644 --- a/resources/views/admin/data-management/fixtures/index.blade.php +++ b/resources/views/admin/data-management/fixtures/index.blade.php @@ -1,10 +1,10 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud')

Fixtures Add New Fixture

+ class="btn btn-primary pull-right btn-sm">New fixture
@@ -20,26 +20,26 @@ class="btn btn-primary pull-right btn-sm">Add New Fixture - @foreach($fixtures as $item) + @foreach($fixtures as $fixture) - - - - - - + + + + + + + + @endforeach + +
- - {{ $item->division }}:{{ $item->match_number }} + + {{ $fixture->division }}:{{ $fixture->match_number }} {{ $item->match_date->format('j M Y') }}{{ $item->warm_up_time->format('H:i') }}{{ $item->start_time->format('H:i') }}{{ $item->home_team }}{{ $item->away_team }}{{ $item->venue }}{{ $fixture->match_date->format('j M Y') }}{{ $fixture->warm_up_time->format('H:i') }}{{ $fixture->start_time->format('H:i') }}{{ $fixture->home_team }}{{ $fixture->away_team }}{{ $fixture->venue }} - + / {!! Form::open([ 'method'=>'DELETE', - 'url' => ['admin/data-management/fixtures', $item->id], + 'url' => ['admin/data-management/fixtures', $fixture->id], 'style' => 'display:inline' ]) !!} {!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs', 'data-toggle' => 'confirmation']) !!} diff --git a/resources/views/admin/data-management/fixtures/show.blade.php b/resources/views/admin/data-management/fixtures/show.blade.php index b7ef2ae4..bf414028 100644 --- a/resources/views/admin/data-management/fixtures/show.blade.php +++ b/resources/views/admin/data-management/fixtures/show.blade.php @@ -1,6 +1,6 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud')

Fixture

diff --git a/resources/views/admin/data-management/home.blade.php b/resources/views/admin/data-management/home.blade.php index 63b0ddf4..9f4f9507 100644 --- a/resources/views/admin/data-management/home.blade.php +++ b/resources/views/admin/data-management/home.blade.php @@ -3,18 +3,45 @@ @section('content')
- +

From here you can manage all the data. Click on the button of teh table you want to use and from there + you will be able to add, modify and delete records.

+ + + @yield('crud')
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/roles/create.blade.php b/resources/views/admin/data-management/roles/create.blade.php index c47ccddb..50fcae13 100644 --- a/resources/views/admin/data-management/roles/create.blade.php +++ b/resources/views/admin/data-management/roles/create.blade.php @@ -1,36 +1,30 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Create New Role

-
+
+

Add new role

+
- {!! Form::open(['url' => 'admin/data-management/roles', 'class' => 'form-horizontal']) !!} + @include('_partial.crud-errors'); -
- {!! Form::label('role', 'Role: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::text('role', null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('role', '

:message

') !!} -
-
+ {!! Form::open(['url' => 'admin/data-management/roles', 'class' => 'form-horizontal']) !!} +
+ {!! Form::label('role', 'Role: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('role', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('role', '

:message

') !!} +
+
-
-
- {!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!} +
+ + {!! Form::close() !!}
- {!! Form::close() !!} - - @if ($errors->any()) -
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
- @endif -
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/roles/edit.blade.php b/resources/views/admin/data-management/roles/edit.blade.php index b711a6fa..51d41e8d 100644 --- a/resources/views/admin/data-management/roles/edit.blade.php +++ b/resources/views/admin/data-management/roles/edit.blade.php @@ -1,40 +1,34 @@ -@extends('layouts.app') - -@section('content') - -
-

Edit Role

-
- - {!! Form::model($role, [ - 'method' => 'PATCH', - 'url' => ['admin/data-management/roles', $role->id], - 'class' => 'form-horizontal' - ]) !!} - -
- {!! Form::label('role', 'Role: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::text('role', null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('role', '

:message

') !!} -
-
+@extends('admin.data-management.home') + +@section('crud') + +
+

Edit role

+
+ @include('_partial.crud-errors'); -
-
- {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} + {!! Form::model($role, [ + 'method' => 'PATCH', + 'url' => ['admin/data-management/roles', $role->id], + 'class' => 'form-horizontal' + ]) !!} + +
+ {!! Form::label('role', 'Role: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('role', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('role', '

:message

') !!} +
+ +
+
+ {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} +
+
+ + {!! Form::close() !!}
- {!! Form::close() !!} - - @if ($errors->any()) -
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
- @endif -
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/roles/index.blade.php b/resources/views/admin/data-management/roles/index.blade.php index 2fb99794..784ecded 100644 --- a/resources/views/admin/data-management/roles/index.blade.php +++ b/resources/views/admin/data-management/roles/index.blade.php @@ -1,39 +1,41 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Roles Add New Role

-
- - +
+

Roles New + role

+
+
+ - + + - - - @foreach($roles as $item) - - - + @foreach($roles as $role) + + + - - @endforeach - -
RoleActionsRoleActions
{{ $item->role }} - - - / - {!! Form::open([ - 'method'=>'DELETE', - 'url' => ['admin/data-management/roles', $item->id], - 'style' => 'display:inline' - ]) !!} + +
{{ $role->role }} + + + / + {!! Form::open([ + 'method'=>'DELETE', + 'url' => ['admin/data-management/roles', $role->id], + 'style' => 'display:inline' + ]) !!} {!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs', 'data-toggle' => 'confirmation']) !!} - {!! Form::close() !!} -
- + {!! Form::close() !!} +
+ +
-
@endsection diff --git a/resources/views/admin/data-management/roles/show.blade.php b/resources/views/admin/data-management/roles/show.blade.php index e24294fd..d9000a18 100644 --- a/resources/views/admin/data-management/roles/show.blade.php +++ b/resources/views/admin/data-management/roles/show.blade.php @@ -1,23 +1,25 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Role

-
- - +
+

Role

+
+
+ - + + - - + + - + + - -
Id RoleIdRole
{{ $role->id }} {{ $role->role }} {{ $role->id }}{{ $role->role }}
+
+ - @endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/seasons/create.blade.php b/resources/views/admin/data-management/seasons/create.blade.php index 4961b1d7..a45ea881 100644 --- a/resources/views/admin/data-management/seasons/create.blade.php +++ b/resources/views/admin/data-management/seasons/create.blade.php @@ -1,36 +1,30 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Create New Season

-
+
+

Add a new season

+
- {!! Form::open(['url' => 'admin/data-management/seasons', 'class' => 'form-horizontal']) !!} + @include('_partial.crud-errors'); -
- {!! Form::label('season', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::text('season', null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('season', '

:message

') !!} -
-
+ {!! Form::open(['url' => 'admin/data-management/seasons', 'class' => 'form-horizontal']) !!} +
+ {!! Form::label('season', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('season', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('season', '

:message

') !!} +
+
-
-
- {!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!} +
+ + {!! Form::close() !!}
- {!! Form::close() !!} - - @if ($errors->any()) -
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
- @endif -
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/seasons/edit.blade.php b/resources/views/admin/data-management/seasons/edit.blade.php index 1f6b9493..b6762035 100644 --- a/resources/views/admin/data-management/seasons/edit.blade.php +++ b/resources/views/admin/data-management/seasons/edit.blade.php @@ -1,40 +1,34 @@ -@extends('layouts.app') - -@section('content') - -
-

Edit Season

-
- - {!! Form::model($season, [ - 'method' => 'PATCH', - 'url' => ['admin/data-management/seasons', $season->id], - 'class' => 'form-horizontal' - ]) !!} - -
- {!! Form::label('season', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::text('season', null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('season', '

:message

') !!} -
-
+@extends('admin.data-management.home') + +@section('crud') + +
+

Edit season

+
+ @include('_partial.crud-errors'); -
-
- {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} + {!! Form::model($season, [ + 'method' => 'PATCH', + 'url' => ['admin/data-management/seasons', $season->id], + 'class' => 'form-horizontal' + ]) !!} + +
+ {!! Form::label('season', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('season', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('season', '

:message

') !!} +
+ +
+
+ {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} +
+
+ + {!! Form::close() !!}
- {!! Form::close() !!} - - @if ($errors->any()) -
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
- @endif -
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/seasons/index.blade.php b/resources/views/admin/data-management/seasons/index.blade.php index 69e7f96d..0245749c 100644 --- a/resources/views/admin/data-management/seasons/index.blade.php +++ b/resources/views/admin/data-management/seasons/index.blade.php @@ -1,9 +1,10 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud')
-

Seasons Add New Season

+

Seasons New + season

@@ -12,16 +13,16 @@ - @foreach($seasons as $item) + @foreach($seasons as $season) - + +
{{ $item->season }}{{ $season->season }} - + / {!! Form::open([ 'method'=>'DELETE', - 'url' => ['admin/data-management/seasons', $item->id], + 'url' => ['admin/data-management/seasons', $season->id], 'style' => 'display:inline' ]) !!} {!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs', 'data-toggle' => 'confirmation']) !!} diff --git a/resources/views/admin/data-management/seasons/show.blade.php b/resources/views/admin/data-management/seasons/show.blade.php index a8cecc83..81638f3e 100644 --- a/resources/views/admin/data-management/seasons/show.blade.php +++ b/resources/views/admin/data-management/seasons/show.blade.php @@ -1,23 +1,25 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Season

-
- - +
+

Season

+
+
+ - + + - - + + - + + - -
Id SeasonIdSeason
{{ $season->id }} {{ $season->season }} {{ $season->id }}{{ $season->season }}
+
+
-
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/teams/create.blade.php b/resources/views/admin/data-management/teams/create.blade.php index 81d89488..0dbe60cb 100644 --- a/resources/views/admin/data-management/teams/create.blade.php +++ b/resources/views/admin/data-management/teams/create.blade.php @@ -1,43 +1,38 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Create New Team

-
+
+

Add new team

+
- {!! Form::open(['url' => 'admin/data-management/teams', 'class' => 'form-horizontal']) !!} + @include('_partial.crud-errors'); -
- {!! Form::label('club_id', 'Club: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::select('club_id', array_column($clubs->toArray(), 'club', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('club_id', '

:message

') !!} -
-
-
- {!! Form::label('team', 'Team: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::text('team', null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('team', '

:message

') !!} -
+ {!! Form::open(['url' => 'admin/data-management/teams', 'class' => 'form-horizontal']) !!} + +
+ {!! Form::label('club_id', 'Club: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('club_id', array_column($clubs->toArray(), 'club', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('club_id', '

:message

') !!}
+
+
+ {!! Form::label('team', 'Team: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('team', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('team', '

:message

') !!} +
+
-
-
- {!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!} +
+ + {!! Form::close() !!}
- {!! Form::close() !!} - - @if ($errors->any()) -
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
- @endif -
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/teams/edit.blade.php b/resources/views/admin/data-management/teams/edit.blade.php index 883643f2..d7ce53f3 100644 --- a/resources/views/admin/data-management/teams/edit.blade.php +++ b/resources/views/admin/data-management/teams/edit.blade.php @@ -1,47 +1,42 @@ -@extends('layouts.app') - -@section('content') - -
-

Edit Team

-
- - {!! Form::model($team, [ - 'method' => 'PATCH', - 'url' => ['admin/data-management/teams', $team->id], - 'class' => 'form-horizontal' - ]) !!} - -
- {!! Form::label('club_id', 'Club Id: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::select('club_id', array_column($clubs->toArray(), 'club', 'id'), $team->club->id, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('club_id', '

:message

') !!} -
-
-
- {!! Form::label('team', 'Team: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::text('team', null, ['class' => 'form-control', 'required' => 'required']) !!} - {!! $errors->first('team', '

:message

') !!} -
+@extends('admin.data-management.home') + +@section('crud') + +
+

Edit team

+
+ + @include('_partial.crud-errors'); + + {!! Form::model($team, [ + 'method' => 'PATCH', + 'url' => ['admin/data-management/teams', $team->id], + 'class' => 'form-horizontal' + ]) !!} + +
+ {!! Form::label('club_id', 'Club Id: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('club_id', array_column($clubs->toArray(), 'club', 'id'), $team->club->id, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('club_id', '

:message

') !!}
+
+
+ {!! Form::label('team', 'Team: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('team', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! $errors->first('team', '

:message

') !!} +
+
-
-
- {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} +
+ + {!! Form::close() !!}
- {!! Form::close() !!} - - @if ($errors->any()) -
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
- @endif -
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/teams/index.blade.php b/resources/views/admin/data-management/teams/index.blade.php index 492da9f6..97fd3854 100644 --- a/resources/views/admin/data-management/teams/index.blade.php +++ b/resources/views/admin/data-management/teams/index.blade.php @@ -1,40 +1,43 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Teams Add New Team

-
- - +
+

Teams New + team

+
+
+ - + + + - - - @foreach($teams as $item) - - - - + @foreach($teams as $team) + + + + - - @endforeach - -
ClubTeamActionsClubTeamActions
{{ $item->club->club }}{{ $item->team }} - - - / - {!! Form::open([ - 'method'=>'DELETE', - 'url' => ['admin/data-management/teams', $item->id], - 'style' => 'display:inline' - ]) !!} + +
{{ $team->club->club }}{{ $team->team }} + + + / + {!! Form::open([ + 'method'=>'DELETE', + 'url' => ['admin/data-management/teams', $team->id], + 'style' => 'display:inline' + ]) !!} {!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs', 'data-toggle' => 'confirmation']) !!} - {!! Form::close() !!} -
- + {!! Form::close() !!} +
+ +
-
@endsection diff --git a/resources/views/admin/data-management/teams/show.blade.php b/resources/views/admin/data-management/teams/show.blade.php index cc7bca6c..a88c1f4b 100644 --- a/resources/views/admin/data-management/teams/show.blade.php +++ b/resources/views/admin/data-management/teams/show.blade.php @@ -1,23 +1,27 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Team

-
- - +
+

Team

+
+
+ - + + + - - + + - + + + - -
IdClubTeamIdClubTeam
{{ $team->id }} {{ $team->club->club }} {{ $team->team }} {{ $team->id }}{{ $team->club->club }}{{ $team->team }}
+ + +
-
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/venues/create.blade.php b/resources/views/admin/data-management/venues/create.blade.php index 223f24ff..29610030 100644 --- a/resources/views/admin/data-management/venues/create.blade.php +++ b/resources/views/admin/data-management/venues/create.blade.php @@ -1,36 +1,30 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Create New Venue

-
+
+

Add new venue

+
- {!! Form::open(['url' => 'admin/data-management/venues', 'class' => 'form-horizontal']) !!} + @include('_partial.crud-errors'); -
- {!! Form::label('venue', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::text('venue', null, ['class' => 'form-control']) !!} - {!! $errors->first('venue', '

:message

') !!} -
-
+ {!! Form::open(['url' => 'admin/data-management/venues', 'class' => 'form-horizontal']) !!} +
+ {!! Form::label('venue', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('venue', null, ['class' => 'form-control']) !!} + {!! $errors->first('venue', '

:message

') !!} +
+
-
-
- {!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!} +
+
+ {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!} +
+ + {!! Form::close() !!}
- {!! Form::close() !!} - - @if ($errors->any()) -
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
- @endif -
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/venues/edit.blade.php b/resources/views/admin/data-management/venues/edit.blade.php index 67904976..5669f38b 100644 --- a/resources/views/admin/data-management/venues/edit.blade.php +++ b/resources/views/admin/data-management/venues/edit.blade.php @@ -1,40 +1,34 @@ -@extends('layouts.app') - -@section('content') - -
-

Edit Venue

-
- - {!! Form::model($venue, [ - 'method' => 'PATCH', - 'url' => ['admin/data-management/venues', $venue->id], - 'class' => 'form-horizontal' - ]) !!} - -
- {!! Form::label('venue', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!} -
- {!! Form::text('venue', null, ['class' => 'form-control']) !!} - {!! $errors->first('venue', '

:message

') !!} -
-
+@extends('admin.data-management.home') + +@section('crud') + +
+

Edit venue

+
+ @include('_partial.crud-errors'); -
-
- {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} + {!! Form::model($venue, [ + 'method' => 'PATCH', + 'url' => ['admin/data-management/venues', $venue->id], + 'class' => 'form-horizontal' + ]) !!} + +
+ {!! Form::label('venue', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::text('venue', null, ['class' => 'form-control']) !!} + {!! $errors->first('venue', '

:message

') !!} +
+ +
+
+ {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} +
+
+ + {!! Form::close() !!}
- {!! Form::close() !!} - - @if ($errors->any()) -
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
- @endif -
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/venues/index.blade.php b/resources/views/admin/data-management/venues/index.blade.php index 80f1cb46..10973773 100644 --- a/resources/views/admin/data-management/venues/index.blade.php +++ b/resources/views/admin/data-management/venues/index.blade.php @@ -1,39 +1,41 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Venues Add New Venue

-
- - +
+

Venues New + venue

+
+
+ - + + - - - @foreach($venues as $item) - - - + @foreach($venues as $venue) + + + - - @endforeach - -
VenueActionsVenueActions
{{ $item->venue }} - - - / - {!! Form::open([ - 'method'=>'DELETE', - 'url' => ['admin/data-management/venues', $item->id], - 'style' => 'display:inline' - ]) !!} + +
{{ $venue->venue }} + + + / + {!! Form::open([ + 'method'=>'DELETE', + 'url' => ['admin/data-management/venues', $venue->id], + 'style' => 'display:inline' + ]) !!} {!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs', 'data-toggle' => 'confirmation']) !!} - {!! Form::close() !!} -
- + {!! Form::close() !!} + + + @endforeach + + + +
-
@endsection diff --git a/resources/views/admin/data-management/venues/show.blade.php b/resources/views/admin/data-management/venues/show.blade.php index f3d3c28f..aa173cc3 100644 --- a/resources/views/admin/data-management/venues/show.blade.php +++ b/resources/views/admin/data-management/venues/show.blade.php @@ -1,23 +1,25 @@ -@extends('layouts.app') +@extends('admin.data-management.home') -@section('content') +@section('crud') -
-

Venue

-
- - +
+

Venue

+
+
+ - + + - - + + - + + - -
Id VenueIdVenue
{{ $venue->id }} {{ $venue->venue }} {{ $venue->id }}{{ $venue->venue }}
+ + +
-
@endsection \ No newline at end of file From 8bd0871df3a41b8c3b57b25fa545af9fe06818ec Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Mon, 2 May 2016 18:05:54 +0100 Subject: [PATCH 19/34] dev: Added some more tests for the Data Management --- .../AvailableAppointmentsTableTest.php | 27 +++++ tests/Admin/DataManagement/ClubsTableTest.php | 27 +++++ .../DataManagement/DivisionsTableTest.php | 27 +++++ .../DataManagement/FixturesTableTest.php | 27 +++++ tests/Admin/DataManagement/HomePageTest.php | 44 -------- tests/Admin/DataManagement/RolesTableTest.php | 27 +++++ .../Admin/DataManagement/SeasonsTableTest.php | 34 +++++- tests/Admin/DataManagement/TeamsTableTest.php | 27 +++++ .../Admin/DataManagement/VenuesTableTest.php | 27 +++++ tests/Admin/DataManagementTest.php | 100 ++++++++++++++++++ 10 files changed, 321 insertions(+), 46 deletions(-) create mode 100644 tests/Admin/DataManagement/AvailableAppointmentsTableTest.php create mode 100644 tests/Admin/DataManagement/ClubsTableTest.php create mode 100644 tests/Admin/DataManagement/DivisionsTableTest.php create mode 100644 tests/Admin/DataManagement/FixturesTableTest.php delete mode 100644 tests/Admin/DataManagement/HomePageTest.php create mode 100644 tests/Admin/DataManagement/RolesTableTest.php create mode 100644 tests/Admin/DataManagement/TeamsTableTest.php create mode 100644 tests/Admin/DataManagement/VenuesTableTest.php create mode 100644 tests/Admin/DataManagementTest.php diff --git a/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php b/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php new file mode 100644 index 00000000..425b144a --- /dev/null +++ b/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php @@ -0,0 +1,27 @@ +visit(route('admin.data-management.available-appointments.index')) + ->seePageIs(route('login')); + } + + public function testBreadcrumbs() + { + $this->be($this->getFakeUser()); + $this->breadcrumbsTests('admin.data-management.available-appointments.index', 'Available appointments'); + } + +} diff --git a/tests/Admin/DataManagement/ClubsTableTest.php b/tests/Admin/DataManagement/ClubsTableTest.php new file mode 100644 index 00000000..93dbfa0f --- /dev/null +++ b/tests/Admin/DataManagement/ClubsTableTest.php @@ -0,0 +1,27 @@ +visit(route('admin.data-management.clubs.index')) + ->seePageIs(route('login')); + } + + public function testBreadcrumbs() + { + $this->be($this->getFakeUser()); + $this->breadcrumbsTests('admin.data-management.clubs.index', 'Clubs'); + } + +} diff --git a/tests/Admin/DataManagement/DivisionsTableTest.php b/tests/Admin/DataManagement/DivisionsTableTest.php new file mode 100644 index 00000000..f0f8e6a7 --- /dev/null +++ b/tests/Admin/DataManagement/DivisionsTableTest.php @@ -0,0 +1,27 @@ +visit(route('admin.data-management.divisions.index')) + ->seePageIs(route('login')); + } + + public function testBreadcrumbs() + { + $this->be($this->getFakeUser()); + $this->breadcrumbsTests('admin.data-management.divisions.index', 'Divisions'); + } + +} diff --git a/tests/Admin/DataManagement/FixturesTableTest.php b/tests/Admin/DataManagement/FixturesTableTest.php new file mode 100644 index 00000000..56abe65a --- /dev/null +++ b/tests/Admin/DataManagement/FixturesTableTest.php @@ -0,0 +1,27 @@ +visit(route('admin.data-management.fixtures.index')) + ->seePageIs(route('login')); + } + + public function testBreadcrumbs() + { + $this->be($this->getFakeUser()); + $this->breadcrumbsTests('admin.data-management.fixtures.index', 'Fixtures'); + } + +} diff --git a/tests/Admin/DataManagement/HomePageTest.php b/tests/Admin/DataManagement/HomePageTest.php deleted file mode 100644 index 28022370..00000000 --- a/tests/Admin/DataManagement/HomePageTest.php +++ /dev/null @@ -1,44 +0,0 @@ -admin = $this->getFakeUser(); - } - - public function testRedirectToLoginIfNotAdmin() - { - $this->visit(route('admin::dataManagement')) - ->seePageIs(route('login')); - } - - public function testBreadcrumbs() - { - $this->be($this->admin); - - $this->breadcrumbsTests('admin::dataManagement', 'Data Management'); - } - - public function testSeasonsTableButton() - { - $this->be($this->admin); - - $this->visit(route('admin::dataManagement')) - ->seeLink('Seasons', route('admin::dataManagement::seasons')); - } -} diff --git a/tests/Admin/DataManagement/RolesTableTest.php b/tests/Admin/DataManagement/RolesTableTest.php new file mode 100644 index 00000000..f93fab0a --- /dev/null +++ b/tests/Admin/DataManagement/RolesTableTest.php @@ -0,0 +1,27 @@ +visit(route('admin.data-management.roles.index')) + ->seePageIs(route('login')); + } + + public function testBreadcrumbs() + { + $this->be($this->getFakeUser()); + $this->breadcrumbsTests('admin.data-management.roles.index', 'Roles'); + } + +} diff --git a/tests/Admin/DataManagement/SeasonsTableTest.php b/tests/Admin/DataManagement/SeasonsTableTest.php index f84e1a98..0cc34daa 100644 --- a/tests/Admin/DataManagement/SeasonsTableTest.php +++ b/tests/Admin/DataManagement/SeasonsTableTest.php @@ -14,15 +14,45 @@ class SeasonsTableTest extends TestCase { public function testRedirectToLoginIfNotAdmin() { - $this->visit(route('admin::dataManagement::seasons')) + $this->post(route('admin.data-management.seasons.store')) + ->assertResponseStatus(302); + $this->visit(route('admin.data-management.seasons.index')) + ->seePageIs(route('login')); + $this->visit(route('admin.data-management.seasons.create')) + ->seePageIs(route('login')); + $response = $this->call('DELETE', route('admin.data-management.seasons.destroy', [1])); + $this->assertEquals(302, $response->status()); + $response = $this->call('PUT', route('admin.data-management.seasons.update', [1])); + $this->assertEquals(302, $response->status()); + $this->visit(route('admin.data-management.seasons.show', [1])) + ->seePageIs(route('login')); + $this->visit(route('admin.data-management.seasons.edit', [1])) ->seePageIs(route('login')); } public function testBreadcrumbs() { $this->be($this->getFakeUser()); + $this->breadcrumbsTests('admin.data-management.seasons.index', 'Seasons'); + } + + public function testAddSeason() + { + + } + + public function testEditSeason() + { + + } + + public function testShowSeason() + { - $this->breadcrumbsTests('admin::dataManagement::seasons', 'Seasons'); } + public function testDeleteSeason() + { + + } } diff --git a/tests/Admin/DataManagement/TeamsTableTest.php b/tests/Admin/DataManagement/TeamsTableTest.php new file mode 100644 index 00000000..c3ecc0f7 --- /dev/null +++ b/tests/Admin/DataManagement/TeamsTableTest.php @@ -0,0 +1,27 @@ +visit(route('admin.data-management.teams.index')) + ->seePageIs(route('login')); + } + + public function testBreadcrumbs() + { + $this->be($this->getFakeUser()); + $this->breadcrumbsTests('admin.data-management.teams.index', 'Teams'); + } + +} diff --git a/tests/Admin/DataManagement/VenuesTableTest.php b/tests/Admin/DataManagement/VenuesTableTest.php new file mode 100644 index 00000000..1163d576 --- /dev/null +++ b/tests/Admin/DataManagement/VenuesTableTest.php @@ -0,0 +1,27 @@ +visit(route('admin.data-management.venues.index')) + ->seePageIs(route('login')); + } + + public function testBreadcrumbs() + { + $this->be($this->getFakeUser()); + $this->breadcrumbsTests('admin.data-management.venues.index', 'Venues'); + } + +} diff --git a/tests/Admin/DataManagementTest.php b/tests/Admin/DataManagementTest.php new file mode 100644 index 00000000..7a1db45c --- /dev/null +++ b/tests/Admin/DataManagementTest.php @@ -0,0 +1,100 @@ +visit(route('admin::dataManagement')) + ->seePageIs(route('login')); + } + + public function testBreadcrumbs() + { + $this->be($this->admin); + + $this->breadcrumbsTests('admin::dataManagement', 'Data Management'); + } + + public function testSeasonsTableButton() + { + $this->be($this->admin); + + $this->visit(route('admin::dataManagement')) + ->seeLink('Seasons', route('admin.data-management.seasons.index')); + } + + public function testDivisionsTableButton() + { + $this->be($this->admin); + + $this->visit(route('admin::dataManagement')) + ->seeLink('Divisions', route('admin.data-management.divisions.index')); + } + + public function testVenuesTableButton() + { + $this->be($this->admin); + + $this->visit(route('admin::dataManagement')) + ->seeLink('Venues', route('admin.data-management.venues.index')); + } + + public function testClubsTableButton() + { + $this->be($this->admin); + + $this->visit(route('admin::dataManagement')) + ->seeLink('Clubs', route('admin.data-management.clubs.index')); + } + + public function testTeamsTableButton() + { + $this->be($this->admin); + + $this->visit(route('admin::dataManagement')) + ->seeLink('Teams', route('admin.data-management.teams.index')); + } + + public function testRolesTableButton() + { + $this->be($this->admin); + + $this->visit(route('admin::dataManagement')) + ->seeLink('Roles', route('admin.data-management.roles.index')); + } + + public function testFixturesTableButton() + { + $this->be($this->admin); + + $this->visit(route('admin::dataManagement')) + ->seeLink('Fixtures', route('admin.data-management.fixtures.index')); + } + + public function testAvailableAppointmentsTableButton() + { + $this->be($this->admin); + + $this->visit(route('admin::dataManagement')) + ->seeLink('Available appointments', route('admin.data-management.available-appointments.index')); + } + + protected function setUp() + { + parent::setUp(); + + $this->admin = $this->getFakeUser(); + } +} From 8546e548d8250254886433da80440a229367991e Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Tue, 3 May 2016 19:57:03 +0100 Subject: [PATCH 20/34] dev: add more tests for the Seasons CRUD --- database/factories/ModelFactory.php | 6 ++ .../Admin/DataManagement/SeasonsTableTest.php | 78 +++++++++++++++---- tests/HomePageTest.php | 2 - tests/TestCase.php | 3 +- 4 files changed, 72 insertions(+), 17 deletions(-) diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 0876c70c..9be2c462 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -19,3 +19,9 @@ 'remember_token' => str_random(10), ]; }); + +$factory->define(\App\Models\Season::class, function (\Faker\Generator $faker) { + return [ + 'season' => $faker->name, + ]; +}); diff --git a/tests/Admin/DataManagement/SeasonsTableTest.php b/tests/Admin/DataManagement/SeasonsTableTest.php index 0cc34daa..7972225f 100644 --- a/tests/Admin/DataManagement/SeasonsTableTest.php +++ b/tests/Admin/DataManagement/SeasonsTableTest.php @@ -8,51 +8,103 @@ namespace Admin\DataManagement; +use App\Models\Season; use Tests\TestCase; class SeasonsTableTest extends TestCase { - public function testRedirectToLoginIfNotAdmin() + const BASE_ROUTE = 'admin.data-management.seasons'; + + /** @var Season $existingSeason */ + private $existingSeason = null; + + public function testRedirectIfNotAdmin() { - $this->post(route('admin.data-management.seasons.store')) - ->assertResponseStatus(302); - $this->visit(route('admin.data-management.seasons.index')) + $this->visit(route(self::BASE_ROUTE . '.index')) ->seePageIs(route('login')); - $this->visit(route('admin.data-management.seasons.create')) + + $this->visit(route(self::BASE_ROUTE . '.create')) ->seePageIs(route('login')); - $response = $this->call('DELETE', route('admin.data-management.seasons.destroy', [1])); - $this->assertEquals(302, $response->status()); - $response = $this->call('PUT', route('admin.data-management.seasons.update', [1])); - $this->assertEquals(302, $response->status()); - $this->visit(route('admin.data-management.seasons.show', [1])) + + $this->visit(route(self::BASE_ROUTE . '.show', [1])) ->seePageIs(route('login')); - $this->visit(route('admin.data-management.seasons.edit', [1])) + + $this->visit(route(self::BASE_ROUTE . '.edit', [1])) ->seePageIs(route('login')); + + $this->call('POST', route(self::BASE_ROUTE . '.store')); + $this->assertResponseStatus(302); + + $this->call('DELETE', route(self::BASE_ROUTE . '.destroy', [1])); + $this->assertResponseStatus(302); + + $this->call('PUT', route(self::BASE_ROUTE . '.update', [1])); + $this->assertResponseStatus(302); } public function testBreadcrumbs() { $this->be($this->getFakeUser()); - $this->breadcrumbsTests('admin.data-management.seasons.index', 'Seasons'); + $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Seasons'); } public function testAddSeason() { + $this->be($this->getFakeUser()); + // Brand new season + $newSeason = 'New ' . $this->existingSeason->season; + $this->visit(route(self::BASE_ROUTE . '.create')) + ->type($newSeason, 'season') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Season added!') + ->seeInDatabase('seasons', ['id' => 2, 'season' => $newSeason]); + + // Already existing season + $this->markTestIncomplete('Fix the validation for already existing season'); } public function testEditSeason() { + $this->be($this->getFakeUser()); + + // Brand new season + $newSeason = 'New ' . $this->existingSeason->season; + $this->seeInDatabase('seasons', ['id' => 1, 'season' => $this->existingSeason->season]) + ->visit(route(self::BASE_ROUTE . '.edit', [1])) + ->type($newSeason, 'season') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Season updated!') + ->seeInDatabase('seasons', ['id' => 1, 'season' => $newSeason]); + // Already existing season + $this->markTestIncomplete('Fix the validation for already existing season'); } public function testShowSeason() { + $this->be($this->getFakeUser()); + $this->visit(route(self::BASE_ROUTE . '.show', [1])) + ->seeInElement('tbody tr td:nth-child(1)', 1) + ->seeInElement('tbody tr td:nth-child(2)', $this->existingSeason->season); } public function testDeleteSeason() { - + $this->be($this->getFakeUser()); + + $this->seeInDatabase('seasons', ['id' => 1, 'season' => $this->existingSeason->season]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [1])) + ->isRedirect(route(self::BASE_ROUTE . '.index')); + $this->dontSeeInDatabase('seasons', ['id' => 1]); + } + + protected function setUp() + { + parent::setUp(); + $this->existingSeason = factory(Season::class)->create(); } } diff --git a/tests/HomePageTest.php b/tests/HomePageTest.php index 08ad6130..d51a45fc 100644 --- a/tests/HomePageTest.php +++ b/tests/HomePageTest.php @@ -2,8 +2,6 @@ namespace Tests; -use Tests\TestCase; - class HomePageTest extends TestCase { public function testLandingPage() diff --git a/tests/TestCase.php b/tests/TestCase.php index 471df9f3..7edba2bb 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,12 +2,11 @@ namespace Tests; -use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use Illuminate\Contracts\Console\Kernel; use Artisan; use App\User; -class TestCase extends BaseTestCase +class TestCase extends \Illuminate\Foundation\Testing\TestCase { protected $users = []; From dc02e9c812c2b19308739055ba2d0ac6aeae4d1c Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sat, 7 May 2016 12:58:19 +0100 Subject: [PATCH 21/34] dev: removed spurious semicolon character --- .../data-management/available-appointments/create.blade.php | 2 +- .../admin/data-management/available-appointments/edit.blade.php | 2 +- resources/views/admin/data-management/clubs/create.blade.php | 2 +- resources/views/admin/data-management/clubs/edit.blade.php | 2 +- .../views/admin/data-management/divisions/create.blade.php | 2 +- resources/views/admin/data-management/divisions/edit.blade.php | 2 +- resources/views/admin/data-management/fixtures/create.blade.php | 2 +- resources/views/admin/data-management/fixtures/edit.blade.php | 2 +- resources/views/admin/data-management/roles/create.blade.php | 2 +- resources/views/admin/data-management/roles/edit.blade.php | 2 +- resources/views/admin/data-management/seasons/create.blade.php | 2 +- resources/views/admin/data-management/seasons/edit.blade.php | 2 +- resources/views/admin/data-management/teams/create.blade.php | 2 +- resources/views/admin/data-management/teams/edit.blade.php | 2 +- resources/views/admin/data-management/venues/create.blade.php | 2 +- resources/views/admin/data-management/venues/edit.blade.php | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/resources/views/admin/data-management/available-appointments/create.blade.php b/resources/views/admin/data-management/available-appointments/create.blade.php index 04982b85..7698fa00 100644 --- a/resources/views/admin/data-management/available-appointments/create.blade.php +++ b/resources/views/admin/data-management/available-appointments/create.blade.php @@ -12,7 +12,7 @@

Add new appointment


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::open(['url' => 'admin/data-management/available-appointments', 'class' => 'form-horizontal']) !!} diff --git a/resources/views/admin/data-management/available-appointments/edit.blade.php b/resources/views/admin/data-management/available-appointments/edit.blade.php index a3869386..88470474 100644 --- a/resources/views/admin/data-management/available-appointments/edit.blade.php +++ b/resources/views/admin/data-management/available-appointments/edit.blade.php @@ -13,7 +13,7 @@

Edit appointment


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::model($availableAppointment, [ 'method' => 'PATCH', diff --git a/resources/views/admin/data-management/clubs/create.blade.php b/resources/views/admin/data-management/clubs/create.blade.php index d17dcfd9..ca649c5d 100644 --- a/resources/views/admin/data-management/clubs/create.blade.php +++ b/resources/views/admin/data-management/clubs/create.blade.php @@ -6,7 +6,7 @@

Add new club


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::open(['url' => 'admin/data-management/clubs', 'class' => 'form-horizontal']) !!} diff --git a/resources/views/admin/data-management/clubs/edit.blade.php b/resources/views/admin/data-management/clubs/edit.blade.php index e6365523..a593dc80 100644 --- a/resources/views/admin/data-management/clubs/edit.blade.php +++ b/resources/views/admin/data-management/clubs/edit.blade.php @@ -6,7 +6,7 @@

Edit club


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::model($club, [ 'method' => 'PATCH', diff --git a/resources/views/admin/data-management/divisions/create.blade.php b/resources/views/admin/data-management/divisions/create.blade.php index c55ce55e..1950be54 100644 --- a/resources/views/admin/data-management/divisions/create.blade.php +++ b/resources/views/admin/data-management/divisions/create.blade.php @@ -6,7 +6,7 @@

Add new division


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::open(['url' => 'admin/data-management/divisions', 'class' => 'form-horizontal']) !!} diff --git a/resources/views/admin/data-management/divisions/edit.blade.php b/resources/views/admin/data-management/divisions/edit.blade.php index bb319aa0..7725ab70 100644 --- a/resources/views/admin/data-management/divisions/edit.blade.php +++ b/resources/views/admin/data-management/divisions/edit.blade.php @@ -6,7 +6,7 @@

Edit division


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::model($division, [ 'method' => 'PATCH', diff --git a/resources/views/admin/data-management/fixtures/create.blade.php b/resources/views/admin/data-management/fixtures/create.blade.php index a57313ac..f8eda342 100644 --- a/resources/views/admin/data-management/fixtures/create.blade.php +++ b/resources/views/admin/data-management/fixtures/create.blade.php @@ -6,7 +6,7 @@

Add new fixture


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::open(['url' => 'admin/data-management/fixtures', 'class' => 'form-horizontal']) !!} diff --git a/resources/views/admin/data-management/fixtures/edit.blade.php b/resources/views/admin/data-management/fixtures/edit.blade.php index 67ef3b55..e66f7b16 100644 --- a/resources/views/admin/data-management/fixtures/edit.blade.php +++ b/resources/views/admin/data-management/fixtures/edit.blade.php @@ -6,7 +6,7 @@

Edit fixture


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::model($fixture, [ 'method' => 'PATCH', diff --git a/resources/views/admin/data-management/roles/create.blade.php b/resources/views/admin/data-management/roles/create.blade.php index 50fcae13..1609ae4c 100644 --- a/resources/views/admin/data-management/roles/create.blade.php +++ b/resources/views/admin/data-management/roles/create.blade.php @@ -6,7 +6,7 @@

Add new role


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::open(['url' => 'admin/data-management/roles', 'class' => 'form-horizontal']) !!} diff --git a/resources/views/admin/data-management/roles/edit.blade.php b/resources/views/admin/data-management/roles/edit.blade.php index 51d41e8d..1e4fc977 100644 --- a/resources/views/admin/data-management/roles/edit.blade.php +++ b/resources/views/admin/data-management/roles/edit.blade.php @@ -6,7 +6,7 @@

Edit role


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::model($role, [ 'method' => 'PATCH', diff --git a/resources/views/admin/data-management/seasons/create.blade.php b/resources/views/admin/data-management/seasons/create.blade.php index a45ea881..0f20d75a 100644 --- a/resources/views/admin/data-management/seasons/create.blade.php +++ b/resources/views/admin/data-management/seasons/create.blade.php @@ -6,7 +6,7 @@

Add a new season


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::open(['url' => 'admin/data-management/seasons', 'class' => 'form-horizontal']) !!} diff --git a/resources/views/admin/data-management/seasons/edit.blade.php b/resources/views/admin/data-management/seasons/edit.blade.php index b6762035..8c227309 100644 --- a/resources/views/admin/data-management/seasons/edit.blade.php +++ b/resources/views/admin/data-management/seasons/edit.blade.php @@ -6,7 +6,7 @@

Edit season


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::model($season, [ 'method' => 'PATCH', diff --git a/resources/views/admin/data-management/teams/create.blade.php b/resources/views/admin/data-management/teams/create.blade.php index 0dbe60cb..56ae0a07 100644 --- a/resources/views/admin/data-management/teams/create.blade.php +++ b/resources/views/admin/data-management/teams/create.blade.php @@ -6,7 +6,7 @@

Add new team


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::open(['url' => 'admin/data-management/teams', 'class' => 'form-horizontal']) !!} diff --git a/resources/views/admin/data-management/teams/edit.blade.php b/resources/views/admin/data-management/teams/edit.blade.php index d7ce53f3..b7060454 100644 --- a/resources/views/admin/data-management/teams/edit.blade.php +++ b/resources/views/admin/data-management/teams/edit.blade.php @@ -6,7 +6,7 @@

Edit team


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::model($team, [ 'method' => 'PATCH', diff --git a/resources/views/admin/data-management/venues/create.blade.php b/resources/views/admin/data-management/venues/create.blade.php index 29610030..ce3dd765 100644 --- a/resources/views/admin/data-management/venues/create.blade.php +++ b/resources/views/admin/data-management/venues/create.blade.php @@ -6,7 +6,7 @@

Add new venue


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::open(['url' => 'admin/data-management/venues', 'class' => 'form-horizontal']) !!} diff --git a/resources/views/admin/data-management/venues/edit.blade.php b/resources/views/admin/data-management/venues/edit.blade.php index 5669f38b..e9876621 100644 --- a/resources/views/admin/data-management/venues/edit.blade.php +++ b/resources/views/admin/data-management/venues/edit.blade.php @@ -6,7 +6,7 @@

Edit venue


- @include('_partial.crud-errors'); + @include('_partial.crud-errors') {!! Form::model($venue, [ 'method' => 'PATCH', From b3a855bd5a796fd7266ee8dc68bf4d719ad95a2e Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sat, 7 May 2016 14:55:48 +0100 Subject: [PATCH 22/34] dev: finished test for the Seasons CRUD --- .../DataManagement/SeasonsController.php | 4 +- .../2016_05_07_133457_make_season_unique.sql | 2 + .../2016_05_07_133457_make_season_unique.php | 31 ++++++++ resources/lang/en/validation.php | 4 +- .../Admin/DataManagement/SeasonsTableTest.php | 77 ++++++++++++------- tests/TestCase.php | 12 +-- 6 files changed, 94 insertions(+), 36 deletions(-) create mode 100644 database/deployment/2016_05_07_133457_make_season_unique.sql create mode 100644 database/migrations/2016_05_07_133457_make_season_unique.php diff --git a/app/Http/Controllers/Admin/DataManagement/SeasonsController.php b/app/Http/Controllers/Admin/DataManagement/SeasonsController.php index b10bb85e..2cfaf9a0 100644 --- a/app/Http/Controllers/Admin/DataManagement/SeasonsController.php +++ b/app/Http/Controllers/Admin/DataManagement/SeasonsController.php @@ -41,7 +41,7 @@ public function create() */ public function store(Request $request) { - $this->validate($request, ['season' => 'required',]); + $this->validate($request, ['season' => 'required|unique:seasons']); Season::create($request->all()); @@ -88,7 +88,7 @@ public function edit($id) */ public function update(Request $request, $id) { - $this->validate($request, ['season' => 'required',]); + $this->validate($request, ['season' => 'required|unique:seasons,season,' . $id]); $season = Season::findOrFail($id); $season->update($request->all()); diff --git a/database/deployment/2016_05_07_133457_make_season_unique.sql b/database/deployment/2016_05_07_133457_make_season_unique.sql new file mode 100644 index 00000000..08cb4913 --- /dev/null +++ b/database/deployment/2016_05_07_133457_make_season_unique.sql @@ -0,0 +1,2 @@ +ALTER TABLE `seasons` + ADD UNIQUE `seasons_season_unique`(`season`); diff --git a/database/migrations/2016_05_07_133457_make_season_unique.php b/database/migrations/2016_05_07_133457_make_season_unique.php new file mode 100644 index 00000000..47083e23 --- /dev/null +++ b/database/migrations/2016_05_07_133457_make_season_unique.php @@ -0,0 +1,31 @@ +unique(['season']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('seasons', function (Blueprint $table) { + $table->dropUnique(['season']); + }); + } +} diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index b0a1f143..eb63096a 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -89,8 +89,8 @@ */ 'custom' => [ - 'attribute-name' => [ - 'rule-name' => 'custom-message', + 'season' => [ + 'unique' => 'The season already exists.', ], ], diff --git a/tests/Admin/DataManagement/SeasonsTableTest.php b/tests/Admin/DataManagement/SeasonsTableTest.php index 7972225f..0d7059fd 100644 --- a/tests/Admin/DataManagement/SeasonsTableTest.php +++ b/tests/Admin/DataManagement/SeasonsTableTest.php @@ -15,9 +15,6 @@ class SeasonsTableTest extends TestCase { const BASE_ROUTE = 'admin.data-management.seasons'; - /** @var Season $existingSeason */ - private $existingSeason = null; - public function testRedirectIfNotAdmin() { $this->visit(route(self::BASE_ROUTE . '.index')) @@ -52,59 +49,87 @@ public function testAddSeason() { $this->be($this->getFakeUser()); + /** @var Season $season */ + $season = factory(Season::class)->create(); + $seasonId = $season->id; + $seasonName = $season->season; + // Brand new season - $newSeason = 'New ' . $this->existingSeason->season; + $newSeasonName = 'New ' . $season->season; $this->visit(route(self::BASE_ROUTE . '.create')) - ->type($newSeason, 'season') + ->type($newSeasonName, 'season') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Season added!') - ->seeInDatabase('seasons', ['id' => 2, 'season' => $newSeason]); + ->seeInDatabase('seasons', ['id' => $seasonId + 1, 'season' => $newSeasonName]); // Already existing season - $this->markTestIncomplete('Fix the validation for already existing season'); + $this->visit(route(self::BASE_ROUTE . '.create')) + ->type($seasonName, 'season') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.create')) + ->seeInElement('.alert.alert-danger', 'The season already exists.') + ->seeInDatabase('seasons', ['id' => $seasonId, 'season' => $seasonName]); } public function testEditSeason() { $this->be($this->getFakeUser()); - // Brand new season - $newSeason = 'New ' . $this->existingSeason->season; - $this->seeInDatabase('seasons', ['id' => 1, 'season' => $this->existingSeason->season]) - ->visit(route(self::BASE_ROUTE . '.edit', [1])) - ->type($newSeason, 'season') + /** @var Season $season */ + $season = factory(Season::class)->create(); + $seasonId = $season->id; + $seasonName = $season->season; + + $newSeasonName = 'New ' . $seasonName; + $this->seeInDatabase('seasons', ['id' => $seasonId, 'season' => $seasonName]) + ->visit(route(self::BASE_ROUTE . '.edit', [$seasonId])) + ->type($newSeasonName, 'season') ->press('Update') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Season updated!') - ->seeInDatabase('seasons', ['id' => 1, 'season' => $newSeason]); + ->seeInDatabase('seasons', ['id' => $seasonId, 'season' => $newSeasonName]); + $seasonName = $newSeasonName; + + $anotherSeason = factory(Season::class)->create(); + $anotherSeasonName = $anotherSeason->season; // Already existing season - $this->markTestIncomplete('Fix the validation for already existing season'); + $this->seeInDatabase('seasons', ['id' => $seasonId, 'season' => $seasonName]) + ->visit(route(self::BASE_ROUTE . '.edit', [$seasonId])) + ->type($anotherSeasonName, 'season') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$seasonId])) + ->seeInElement('.alert.alert-danger', 'The season already exists.') + ->seeInDatabase('seasons', ['id' => $seasonId, 'season' => $seasonName]); } public function testShowSeason() { $this->be($this->getFakeUser()); - $this->visit(route(self::BASE_ROUTE . '.show', [1])) - ->seeInElement('tbody tr td:nth-child(1)', 1) - ->seeInElement('tbody tr td:nth-child(2)', $this->existingSeason->season); + /** @var Season $season */ + $season = factory(Season::class)->create(); + $seasonId = $season->id; + $seasonName = $season->season; + + $this->visit(route(self::BASE_ROUTE . '.show', [$seasonId])) + ->seeInElement('tbody tr td:nth-child(1)', $seasonId) + ->seeInElement('tbody tr td:nth-child(2)', $seasonName); } public function testDeleteSeason() { $this->be($this->getFakeUser()); - $this->seeInDatabase('seasons', ['id' => 1, 'season' => $this->existingSeason->season]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [1])) - ->isRedirect(route(self::BASE_ROUTE . '.index')); - $this->dontSeeInDatabase('seasons', ['id' => 1]); - } + /** @var Season $season */ + $season = factory(Season::class)->create(); + $seasonId = $season->id; + $seasonName = $season->season; - protected function setUp() - { - parent::setUp(); - $this->existingSeason = factory(Season::class)->create(); + $this->seeInDatabase('seasons', ['id' => $seasonId, 'season' => $seasonName]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$seasonId])) + ->isRedirect(route(self::BASE_ROUTE . '.index')); + $this->dontSeeInDatabase('seasons', ['id' => $seasonId]); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 7edba2bb..d96783ba 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -8,7 +8,7 @@ class TestCase extends \Illuminate\Foundation\Testing\TestCase { - protected $users = []; + protected $seasons = []; /** * The base URL to use while testing the application. @@ -51,8 +51,8 @@ protected function getFakeUser($userId = null) ]); $user->clearPassword = $password; $userId = $user->id; - $this->users[$userId] = $user; - } elseif (!isset($this->users[$userId])) { + $this->seasons[$userId] = $user; + } elseif (!isset($this->seasons[$userId])) { $password = str_random(10); $user = factory(User::class) ->create([ @@ -60,10 +60,10 @@ protected function getFakeUser($userId = null) 'password' => bcrypt($password), ]); $user->clearPassword = $password; - $this->users[$userId] = $user; + $this->seasons[$userId] = $user; } - - return $this->users[$userId]; + + return $this->seasons[$userId]; } /** From 7299b9ffef2b34149a2b25a50aa755d35780b53d Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sat, 7 May 2016 18:34:51 +0100 Subject: [PATCH 23/34] dev: used variables instead of accessing the property directly --- tests/Admin/DataManagement/SeasonsTableTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Admin/DataManagement/SeasonsTableTest.php b/tests/Admin/DataManagement/SeasonsTableTest.php index 0d7059fd..00db8a6c 100644 --- a/tests/Admin/DataManagement/SeasonsTableTest.php +++ b/tests/Admin/DataManagement/SeasonsTableTest.php @@ -55,7 +55,7 @@ public function testAddSeason() $seasonName = $season->season; // Brand new season - $newSeasonName = 'New ' . $season->season; + $newSeasonName = 'New ' . $seasonName; $this->visit(route(self::BASE_ROUTE . '.create')) ->type($newSeasonName, 'season') ->press('Add') From 56b14cf62469aeb084f0b0a3b54bff4a9130019d Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sat, 7 May 2016 18:35:13 +0100 Subject: [PATCH 24/34] dev: finished test for the Divisions CRUD --- .../DataManagement/DivisionsController.php | 12 +- ..._172130_make_division_unique_in_season.sql | 2 + database/factories/ModelFactory.php | 11 +- ..._172130_make_division_unique_in_season.php | 36 +++++ resources/lang/en/validation.php | 5 +- .../data-management/divisions/index.blade.php | 2 +- .../DataManagement/DivisionsTableTest.php | 141 +++++++++++++++++- 7 files changed, 200 insertions(+), 9 deletions(-) create mode 100644 database/deployment/2016_05_07_172130_make_division_unique_in_season.sql create mode 100644 database/migrations/2016_05_07_172130_make_division_unique_in_season.php diff --git a/app/Http/Controllers/Admin/DataManagement/DivisionsController.php b/app/Http/Controllers/Admin/DataManagement/DivisionsController.php index f135ef45..46ef7c0d 100644 --- a/app/Http/Controllers/Admin/DataManagement/DivisionsController.php +++ b/app/Http/Controllers/Admin/DataManagement/DivisionsController.php @@ -43,7 +43,10 @@ public function create() */ public function store(Request $request) { - $this->validate($request, ['season_id' => 'required', 'division' => 'required']); + $this->validate($request, [ + 'season_id' => 'required|exists:seasons,id', + 'division' => 'required|unique:divisions,division,NULL,id,season_id,' . $request->get('season_id'), + ]); Division::create($request->all()); @@ -91,7 +94,10 @@ public function edit($id) */ public function update(Request $request, $id) { - $this->validate($request, ['division' => 'required',]); + $this->validate($request, [ + 'season_id' => 'required|exists:seasons,id', + 'division' => 'required|unique:divisions,division,NULL,id,season_id,' . $request->get('season_id'), + ]); $division = Division::findOrFail($id); $division->update($request->all()); @@ -117,7 +123,7 @@ public function destroy($id) } else { \Flash::error('Cannot delete because they are existing fixtures in this division.'); } - + return redirect('admin/data-management/divisions'); } diff --git a/database/deployment/2016_05_07_172130_make_division_unique_in_season.sql b/database/deployment/2016_05_07_172130_make_division_unique_in_season.sql new file mode 100644 index 00000000..cdd59f9b --- /dev/null +++ b/database/deployment/2016_05_07_172130_make_division_unique_in_season.sql @@ -0,0 +1,2 @@ +ALTER TABLE `divisions` + ADD UNIQUE `unique_division`(`season_id`, `division`); \ No newline at end of file diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 9be2c462..d50b9aef 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -22,6 +22,15 @@ $factory->define(\App\Models\Season::class, function (\Faker\Generator $faker) { return [ - 'season' => $faker->name, + 'season' => $faker->word, ]; }); + +$factory->define(App\Models\Division::class, function (\Faker\Generator $faker) { + return [ + 'division' => $faker->word, + 'season_id' => function () { + return factory(App\Models\Season::class)->create()->id; + }, + ]; +}); \ No newline at end of file diff --git a/database/migrations/2016_05_07_172130_make_division_unique_in_season.php b/database/migrations/2016_05_07_172130_make_division_unique_in_season.php new file mode 100644 index 00000000..88476cf4 --- /dev/null +++ b/database/migrations/2016_05_07_172130_make_division_unique_in_season.php @@ -0,0 +1,36 @@ +unique(['season_id', 'division'], 'unique_division'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // Adding the unique index deleted the index on season_id necessary for the foreign key + // MySQL would also complain if we try to just drop the unique index saying that it's + // necessary for the foreign key (sigh). This is why we drop the foreign key and add it again + Schema::table('divisions', function (Blueprint $table) { + $table->dropForeign(['season_id']); + $table->dropIndex('unique_division'); + $table->foreign('season_id')->references('id')->on('seasons'); + }); + } +} diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index eb63096a..bb4667b2 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -89,9 +89,12 @@ */ 'custom' => [ - 'season' => [ + 'season' => [ 'unique' => 'The season already exists.', ], + 'division' => [ + 'unique' => 'The division already exists in the same season.', + ], ], /* diff --git a/resources/views/admin/data-management/divisions/index.blade.php b/resources/views/admin/data-management/divisions/index.blade.php index e57c4374..5c7729f6 100644 --- a/resources/views/admin/data-management/divisions/index.blade.php +++ b/resources/views/admin/data-management/divisions/index.blade.php @@ -1,4 +1,4 @@ -@extends('layouts.app') +@extends('admin.data-management.home') @section('crud') diff --git a/tests/Admin/DataManagement/DivisionsTableTest.php b/tests/Admin/DataManagement/DivisionsTableTest.php index f0f8e6a7..b8859d96 100644 --- a/tests/Admin/DataManagement/DivisionsTableTest.php +++ b/tests/Admin/DataManagement/DivisionsTableTest.php @@ -8,20 +8,155 @@ namespace Admin\DataManagement; +use App\Models\Division; +use App\Models\Season; use Tests\TestCase; class DivisionsTableTest extends TestCase { - public function testRedirectToLoginIfNotAdmin() + const BASE_ROUTE = 'admin.data-management.divisions'; + + public function testRedirectIfNotAdmin() { - $this->visit(route('admin.data-management.divisions.index')) + $this->visit(route(self::BASE_ROUTE . '.index')) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.create')) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.show', [1])) ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.edit', [1])) + ->seePageIs(route('login')); + + $this->call('POST', route(self::BASE_ROUTE . '.store')); + $this->assertResponseStatus(302); + + $this->call('DELETE', route(self::BASE_ROUTE . '.destroy', [1])); + $this->assertResponseStatus(302); + + $this->call('PUT', route(self::BASE_ROUTE . '.update', [1])); + $this->assertResponseStatus(302); } public function testBreadcrumbs() { $this->be($this->getFakeUser()); - $this->breadcrumbsTests('admin.data-management.divisions.index', 'Divisions'); + $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Divisions'); } + public function testAddDivision() + { + $this->be($this->getFakeUser()); + + /** @var Division $division */ + $division = factory(Division::class)->create(); + $divisionId = $division->id; + $seasonId = $division->season_id; + $divisionName = $division->division; + + // Brand new division + $newDivisionName = 'New ' . $divisionName; + $this->visit(route(self::BASE_ROUTE . '.create')) + ->select($seasonId, 'season_id') + ->type($newDivisionName, 'division') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Division added!') + ->seeInDatabase('divisions', ['id' => $divisionId + 1, 'season_id' => $seasonId, 'division' => $newDivisionName]); + + // Already existing division in the same season + $this->visit(route(self::BASE_ROUTE . '.create')) + ->select($seasonId, 'season_id') + ->type($divisionName, 'division') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.create')) + ->seeInElement('.alert.alert-danger', 'The division already exists in the same season.') + ->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $seasonId, 'division' => $divisionName]); + } + + public function testEditDivision() + { + $this->be($this->getFakeUser()); + + /** @var Division $division */ + $division = factory(Division::class)->create(); + $divisionId = $division->id; + $seasonId = $division->season_id; + $divisionName = $division->division; + + // Change the name of the division + $newDivisionName = 'New ' . $divisionName; + $this->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $seasonId, 'division' => $divisionName]) + ->visit(route(self::BASE_ROUTE . '.edit', [$divisionId])) + ->type($newDivisionName, 'division') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Division updated!') + ->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $seasonId, 'division' => $newDivisionName]); + $divisionName = $newDivisionName; + + // Already existing division in the same season + /** @var Division $anotherDivision */ + $anotherDivision = factory(Division::class)->create(['season_id' => $seasonId]); + $anotherDivisionName = $anotherDivision->division; + + $this->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $seasonId, 'division' => $divisionName]) + ->visit(route(self::BASE_ROUTE . '.edit', [$divisionId])) + ->type($anotherDivisionName, 'division') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$divisionId])) + ->seeInElement('.alert.alert-danger', 'The division already exists in the same season.') + ->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $seasonId, 'division' => $divisionName]); + + // Move division to a different season + $anotherSeason = factory(Season::class)->create(); + $anotherSeasonId = $anotherSeason->id; + + $this->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $seasonId, 'division' => $divisionName]) + ->visit(route(self::BASE_ROUTE . '.edit', [$divisionId])) + ->select($anotherSeasonId, 'season_id') + ->type($divisionName, 'division') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Division updated!') + ->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $anotherSeasonId, 'division' => $newDivisionName]); + } + + public function testShowDivision() + { + $this->be($this->getFakeUser()); + + /** @var Division $division */ + $division = factory(Division::class)->create(); + $divisionId = $division->id; + $seasonId = $division->season_id; + $divisionName = $division->division; + + /** @var Season $season */ + $season = Season::find($seasonId); + $seasonName = $season->season; + + $this->visit(route(self::BASE_ROUTE . '.show', [$divisionId])) + ->seeInElement('tbody tr td:nth-child(1)', $divisionId) + ->seeInElement('tbody tr td:nth-child(2)', $seasonName) + ->seeInElement('tbody tr td:nth-child(3)', $divisionName); + } + + public function testDeleteDivision() + { + $this->be($this->getFakeUser()); + + /** @var Division $division */ + $division = factory(Division::class)->create(); + $divisionId = $division->id; + $seasonId = $division->season_id; + $divisionName = $division->division; + + $this->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $seasonId, 'division' => $divisionName]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$divisionId])) + ->isRedirect(route(self::BASE_ROUTE . '.index')); + $this->dontSeeInDatabase('divisions', ['id' => $divisionId]); + } } From dfe29574055baab4daeaca2f7bdba96874ce425a Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Mon, 9 May 2016 18:47:20 +0100 Subject: [PATCH 25/34] dev: finished test for the Clubs CRUD --- .../Admin/DataManagement/ClubsController.php | 4 + .../2016_05_09_183614_make_club_unique.sql | 2 + database/factories/ModelFactory.php | 6 + .../2016_05_09_183614_make_club_unique.php | 31 +++++ resources/lang/en/validation.php | 3 + .../data-management/clubs/create.blade.php | 2 +- tests/Admin/DataManagement/ClubsTableTest.php | 114 +++++++++++++++++- 7 files changed, 158 insertions(+), 4 deletions(-) create mode 100644 database/deployment/2016_05_09_183614_make_club_unique.sql create mode 100644 database/migrations/2016_05_09_183614_make_club_unique.php diff --git a/app/Http/Controllers/Admin/DataManagement/ClubsController.php b/app/Http/Controllers/Admin/DataManagement/ClubsController.php index eef5c52d..62f200b9 100644 --- a/app/Http/Controllers/Admin/DataManagement/ClubsController.php +++ b/app/Http/Controllers/Admin/DataManagement/ClubsController.php @@ -42,6 +42,8 @@ public function create() */ public function store(Request $request) { + $this->validate($request, ['club' => 'required|unique:clubs']); + Club::create($request->all()); \Flash::success('Club added!'); @@ -87,6 +89,8 @@ public function edit($id) */ public function update(Request $request, $id) { + $this->validate($request, ['club' => 'required|unique:clubs,club,' . $id]); + $club = Club::findOrFail($id); $club->update($request->all()); diff --git a/database/deployment/2016_05_09_183614_make_club_unique.sql b/database/deployment/2016_05_09_183614_make_club_unique.sql new file mode 100644 index 00000000..93fa1885 --- /dev/null +++ b/database/deployment/2016_05_09_183614_make_club_unique.sql @@ -0,0 +1,2 @@ +ALTER TABLE `clubs` + ADD UNIQUE `unique_club`(`club`); \ No newline at end of file diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index d50b9aef..75e6895e 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -33,4 +33,10 @@ return factory(App\Models\Season::class)->create()->id; }, ]; +}); + +$factory->define(\App\Models\Club::class, function (\Faker\Generator $faker) { + return [ + 'club' => $faker->word, + ]; }); \ No newline at end of file diff --git a/database/migrations/2016_05_09_183614_make_club_unique.php b/database/migrations/2016_05_09_183614_make_club_unique.php new file mode 100644 index 00000000..44da3ce0 --- /dev/null +++ b/database/migrations/2016_05_09_183614_make_club_unique.php @@ -0,0 +1,31 @@ +unique(['club'], 'unique_club'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('clubs', function (Blueprint $table) { + $table->dropUnique('unique_club'); + }); + } +} diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index bb4667b2..9bf0ad9c 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -95,6 +95,9 @@ 'division' => [ 'unique' => 'The division already exists in the same season.', ], + 'club' => [ + 'unique' => 'The club already exists.', + ], ], /* diff --git a/resources/views/admin/data-management/clubs/create.blade.php b/resources/views/admin/data-management/clubs/create.blade.php index ca649c5d..fba72686 100644 --- a/resources/views/admin/data-management/clubs/create.blade.php +++ b/resources/views/admin/data-management/clubs/create.blade.php @@ -3,7 +3,7 @@ @section('crud')
-

Add new club

+

Add a new club


@include('_partial.crud-errors') diff --git a/tests/Admin/DataManagement/ClubsTableTest.php b/tests/Admin/DataManagement/ClubsTableTest.php index 93dbfa0f..b08df1d5 100644 --- a/tests/Admin/DataManagement/ClubsTableTest.php +++ b/tests/Admin/DataManagement/ClubsTableTest.php @@ -9,19 +9,127 @@ namespace Admin\DataManagement; use Tests\TestCase; +use App\Models\Club; class ClubsTableTest extends TestCase { - public function testRedirectToLoginIfNotAdmin() + const BASE_ROUTE = 'admin.data-management.clubs'; + + public function testRedirectIfNotAdmin() { - $this->visit(route('admin.data-management.clubs.index')) + $this->visit(route(self::BASE_ROUTE . '.index')) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.create')) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.show', [1])) ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.edit', [1])) + ->seePageIs(route('login')); + + $this->call('POST', route(self::BASE_ROUTE . '.store')); + $this->assertResponseStatus(302); + + $this->call('DELETE', route(self::BASE_ROUTE . '.destroy', [1])); + $this->assertResponseStatus(302); + + $this->call('PUT', route(self::BASE_ROUTE . '.update', [1])); + $this->assertResponseStatus(302); } public function testBreadcrumbs() { $this->be($this->getFakeUser()); - $this->breadcrumbsTests('admin.data-management.clubs.index', 'Clubs'); + $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Clubs'); + } + + public function testAddClub() + { + $this->be($this->getFakeUser()); + + /** @var Club $club */ + $club = factory(Club::class)->create(); + $clubId = $club->id; + $clubName = $club->club; + + // Brand new club + $newClubName = 'New ' . $clubName; + $this->visit(route(self::BASE_ROUTE . '.create')) + ->type($newClubName, 'club') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Club added!') + ->seeInDatabase('clubs', ['id' => $clubId + 1, 'club' => $newClubName]); + + // Already existing club + $this->visit(route(self::BASE_ROUTE . '.create')) + ->type($clubName, 'club') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.create')) + ->seeInElement('.alert.alert-danger', 'The club already exists.') + ->seeInDatabase('clubs', ['id' => $clubId, 'club' => $clubName]); + } + + public function testEditClub() + { + $this->be($this->getFakeUser()); + + /** @var Club $club */ + $club = factory(Club::class)->create(); + $clubId = $club->id; + $clubName = $club->club; + + $newClubName = 'New ' . $clubName; + $this->seeInDatabase('clubs', ['id' => $clubId, 'club' => $clubName]) + ->visit(route(self::BASE_ROUTE . '.edit', [$clubId])) + ->type($newClubName, 'club') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Club updated!') + ->seeInDatabase('clubs', ['id' => $clubId, 'club' => $newClubName]); + $clubName = $newClubName; + + $anotherClub = factory(Club::class)->create(); + $anotherClubName = $anotherClub->club; + + // Already existing club + $this->seeInDatabase('clubs', ['id' => $clubId, 'club' => $clubName]) + ->visit(route(self::BASE_ROUTE . '.edit', [$clubId])) + ->type($anotherClubName, 'club') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$clubId])) + ->seeInElement('.alert.alert-danger', 'The club already exists.') + ->seeInDatabase('clubs', ['id' => $clubId, 'club' => $clubName]); + } + + public function testShowClub() + { + $this->be($this->getFakeUser()); + + /** @var Club $club */ + $club = factory(Club::class)->create(); + $clubId = $club->id; + $clubName = $club->club; + + $this->visit(route(self::BASE_ROUTE . '.show', [$clubId])) + ->seeInElement('tbody tr td:nth-child(1)', $clubId) + ->seeInElement('tbody tr td:nth-child(2)', $clubName); } + public function testDeleteClub() + { + $this->be($this->getFakeUser()); + + /** @var Club $club */ + $club = factory(Club::class)->create(); + $clubId = $club->id; + $clubName = $club->club; + + $this->seeInDatabase('clubs', ['id' => $clubId, 'club' => $clubName]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$clubId])) + ->isRedirect(route(self::BASE_ROUTE . '.index')); + $this->dontSeeInDatabase('clubs', ['id' => $clubId]); + } } From d5dc8cc5939c13e3e1412592c3e291ecb4dd1c5f Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Mon, 9 May 2016 18:59:57 +0100 Subject: [PATCH 26/34] dev: finished test for the Teams CRUD --- .../Admin/DataManagement/TeamsController.php | 12 +- ..._05_09_185137_make_team_unique_in_club.sql | 2 + database/factories/ModelFactory.php | 15 +- ..._05_09_185137_make_team_unique_in_club.php | 36 +++++ resources/lang/en/validation.php | 3 + tests/Admin/DataManagement/TeamsTableTest.php | 141 +++++++++++++++++- 6 files changed, 200 insertions(+), 9 deletions(-) create mode 100644 database/deployment/2016_05_09_185137_make_team_unique_in_club.sql create mode 100644 database/migrations/2016_05_09_185137_make_team_unique_in_club.php diff --git a/app/Http/Controllers/Admin/DataManagement/TeamsController.php b/app/Http/Controllers/Admin/DataManagement/TeamsController.php index 3dc558c4..bd6fd851 100644 --- a/app/Http/Controllers/Admin/DataManagement/TeamsController.php +++ b/app/Http/Controllers/Admin/DataManagement/TeamsController.php @@ -42,7 +42,10 @@ public function create() */ public function store(Request $request) { - $this->validate($request, ['club_id' => 'required', 'team' => 'required',]); + $this->validate($request, [ + 'club_id' => 'required|exists:clubs,id', + 'team' => 'required|unique:teams,team,NULL,id,club_id,' . $request->get('club_id'), + ]); Team::create($request->all()); @@ -90,8 +93,11 @@ public function edit($id) */ public function update(Request $request, $id) { - $this->validate($request, ['club_id' => 'required', 'team' => 'required']); - + $this->validate($request, [ + 'club_id' => 'required|exists:clubs,id', + 'team' => 'required|unique:teams,team,NULL,id,club_id,' . $request->get('club_id'), + ]); + $team = Team::findOrFail($id); $team->update($request->all()); diff --git a/database/deployment/2016_05_09_185137_make_team_unique_in_club.sql b/database/deployment/2016_05_09_185137_make_team_unique_in_club.sql new file mode 100644 index 00000000..d166ab60 --- /dev/null +++ b/database/deployment/2016_05_09_185137_make_team_unique_in_club.sql @@ -0,0 +1,2 @@ +ALTER TABLE `teams` + ADD UNIQUE `unique_team_in_club`(`club_id`, `team`); \ No newline at end of file diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 75e6895e..10c0de44 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -13,9 +13,9 @@ $factory->define(App\User::class, function (Faker\Generator $faker) { return [ - 'name' => $faker->name, - 'email' => $faker->email, - 'password' => bcrypt(str_random(10)), + 'name' => $faker->name, + 'email' => $faker->email, + 'password' => bcrypt(str_random(10)), 'remember_token' => str_random(10), ]; }); @@ -39,4 +39,13 @@ return [ 'club' => $faker->word, ]; +}); + +$factory->define(App\Models\Team::class, function (\Faker\Generator $faker) { + return [ + 'team' => $faker->word, + 'club_id' => function () { + return factory(App\Models\Club::class)->create()->id; + }, + ]; }); \ No newline at end of file diff --git a/database/migrations/2016_05_09_185137_make_team_unique_in_club.php b/database/migrations/2016_05_09_185137_make_team_unique_in_club.php new file mode 100644 index 00000000..aefa1840 --- /dev/null +++ b/database/migrations/2016_05_09_185137_make_team_unique_in_club.php @@ -0,0 +1,36 @@ +unique(['club_id', 'team'], 'unique_team_in_club'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // Adding the unique index deleted the index on season_id necessary for the foreign key + // MySQL would also complain if we try to just drop the unique index saying that it's + // necessary for the foreign key (sigh). This is why we drop the foreign key and add it again + Schema::table('teams', function (Blueprint $table) { + $table->dropForeign(['club_id']); + $table->dropIndex('unique_team_in_club'); + $table->foreign('club_id')->references('id')->on('clubs'); + }); + } +} diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 9bf0ad9c..133a3300 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -98,6 +98,9 @@ 'club' => [ 'unique' => 'The club already exists.', ], + 'team' => [ + 'unique' => 'The team already exists in the same club.', + ], ], /* diff --git a/tests/Admin/DataManagement/TeamsTableTest.php b/tests/Admin/DataManagement/TeamsTableTest.php index c3ecc0f7..2dec3a38 100644 --- a/tests/Admin/DataManagement/TeamsTableTest.php +++ b/tests/Admin/DataManagement/TeamsTableTest.php @@ -9,19 +9,154 @@ namespace Admin\DataManagement; use Tests\TestCase; +use App\Models\Team; +use App\Models\Club; class TeamsTableTest extends TestCase { - public function testRedirectToLoginIfNotAdmin() + const BASE_ROUTE = 'admin.data-management.teams'; + + public function testRedirectIfNotAdmin() { - $this->visit(route('admin.data-management.teams.index')) + $this->visit(route(self::BASE_ROUTE . '.index')) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.create')) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.show', [1])) ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.edit', [1])) + ->seePageIs(route('login')); + + $this->call('POST', route(self::BASE_ROUTE . '.store')); + $this->assertResponseStatus(302); + + $this->call('DELETE', route(self::BASE_ROUTE . '.destroy', [1])); + $this->assertResponseStatus(302); + + $this->call('PUT', route(self::BASE_ROUTE . '.update', [1])); + $this->assertResponseStatus(302); } public function testBreadcrumbs() { $this->be($this->getFakeUser()); - $this->breadcrumbsTests('admin.data-management.teams.index', 'Teams'); + $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Teams'); } + public function testAddTeam() + { + $this->be($this->getFakeUser()); + + /** @var Team $team */ + $team = factory(Team::class)->create(); + $teamId = $team->id; + $clubId = $team->club_id; + $teamName = $team->team; + + // Brand new team + $newTeamName = 'New ' . $teamName; + $this->visit(route(self::BASE_ROUTE . '.create')) + ->select($clubId, 'club_id') + ->type($newTeamName, 'team') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Team added!') + ->seeInDatabase('teams', ['id' => $teamId + 1, 'club_id' => $clubId, 'team' => $newTeamName]); + + // Already existing team in the same club + $this->visit(route(self::BASE_ROUTE . '.create')) + ->select($clubId, 'club_id') + ->type($teamName, 'team') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.create')) + ->seeInElement('.alert.alert-danger', 'The team already exists in the same club.') + ->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $clubId, 'team' => $teamName]); + } + + public function testEditTeam() + { + $this->be($this->getFakeUser()); + + /** @var Team $team */ + $team = factory(Team::class)->create(); + $teamId = $team->id; + $clubId = $team->club_id; + $teamName = $team->team; + + // Change the name of the team + $newTeamName = 'New ' . $teamName; + $this->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $clubId, 'team' => $teamName]) + ->visit(route(self::BASE_ROUTE . '.edit', [$teamId])) + ->type($newTeamName, 'team') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Team updated!') + ->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $clubId, 'team' => $newTeamName]); + $teamName = $newTeamName; + + // Already existing team in the same club + /** @var Team $anotherTeam */ + $anotherTeam = factory(Team::class)->create(['club_id' => $clubId]); + $anotherTeamName = $anotherTeam->team; + + $this->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $clubId, 'team' => $teamName]) + ->visit(route(self::BASE_ROUTE . '.edit', [$teamId])) + ->type($anotherTeamName, 'team') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$teamId])) + ->seeInElement('.alert.alert-danger', 'The team already exists in the same club.') + ->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $clubId, 'team' => $teamName]); + + // Move team to a different club + $anotherClub = factory(Club::class)->create(); + $anotherClubId = $anotherClub->id; + + $this->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $clubId, 'team' => $teamName]) + ->visit(route(self::BASE_ROUTE . '.edit', [$teamId])) + ->select($anotherClubId, 'club_id') + ->type($teamName, 'team') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Team updated!') + ->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $anotherClubId, 'team' => $newTeamName]); + } + + public function testShowTeam() + { + $this->be($this->getFakeUser()); + + /** @var Team $team */ + $team = factory(Team::class)->create(); + $teamId = $team->id; + $clubId = $team->club_id; + $teamName = $team->team; + + /** @var Club $club */ + $club = Club::find($clubId); + $clubName = $club->club; + + $this->visit(route(self::BASE_ROUTE . '.show', [$teamId])) + ->seeInElement('tbody tr td:nth-child(1)', $teamId) + ->seeInElement('tbody tr td:nth-child(2)', $clubName) + ->seeInElement('tbody tr td:nth-child(3)', $teamName); + } + + public function testDeleteTeam() + { + $this->be($this->getFakeUser()); + + /** @var Team $team */ + $team = factory(Team::class)->create(); + $teamId = $team->id; + $clubId = $team->club_id; + $teamName = $team->team; + + $this->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $clubId, 'team' => $teamName]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$teamId])) + ->isRedirect(route(self::BASE_ROUTE . '.index')); + $this->dontSeeInDatabase('teams', ['id' => $teamId]); + } } From 7bd759010cd8cc4efc31bd348a5227b4101a8f80 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Mon, 9 May 2016 19:08:47 +0100 Subject: [PATCH 27/34] dev: finished test for the Roles CRUD --- .../Admin/DataManagement/RolesController.php | 4 +- .../2016_05_09_190454_make_role_unique.sql | 2 + database/factories/ModelFactory.php | 6 + .../2016_05_09_190454_make_role_unique.php | 31 +++++ resources/lang/en/validation.php | 3 + tests/Admin/DataManagement/RolesTableTest.php | 114 +++++++++++++++++- 6 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 database/deployment/2016_05_09_190454_make_role_unique.sql create mode 100644 database/migrations/2016_05_09_190454_make_role_unique.php diff --git a/app/Http/Controllers/Admin/DataManagement/RolesController.php b/app/Http/Controllers/Admin/DataManagement/RolesController.php index cc8a134b..2dfdcdfa 100644 --- a/app/Http/Controllers/Admin/DataManagement/RolesController.php +++ b/app/Http/Controllers/Admin/DataManagement/RolesController.php @@ -41,7 +41,7 @@ public function create() */ public function store(Request $request) { - $this->validate($request, ['role' => 'required', ]); + $this->validate($request, ['role' => 'required|unique:roles']); Role::create($request->all()); @@ -88,7 +88,7 @@ public function edit($id) */ public function update(Request $request, $id) { - $this->validate($request, ['role' => 'required', ]); + $this->validate($request, ['role' => 'required|unique:roles,role,' . $id]); $role = Role::findOrFail($id); $role->update($request->all()); diff --git a/database/deployment/2016_05_09_190454_make_role_unique.sql b/database/deployment/2016_05_09_190454_make_role_unique.sql new file mode 100644 index 00000000..dffb753d --- /dev/null +++ b/database/deployment/2016_05_09_190454_make_role_unique.sql @@ -0,0 +1,2 @@ +ALTER TABLE `roles` + ADD UNIQUE `unique_role`(`role`); \ No newline at end of file diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 10c0de44..9a6ede69 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -48,4 +48,10 @@ return factory(App\Models\Club::class)->create()->id; }, ]; +}); + +$factory->define(\App\Models\Role::class, function (\Faker\Generator $faker) { + return [ + 'role' => $faker->word, + ]; }); \ No newline at end of file diff --git a/database/migrations/2016_05_09_190454_make_role_unique.php b/database/migrations/2016_05_09_190454_make_role_unique.php new file mode 100644 index 00000000..8be7a2d0 --- /dev/null +++ b/database/migrations/2016_05_09_190454_make_role_unique.php @@ -0,0 +1,31 @@ +unique(['role'], 'unique_role'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('roles', function (Blueprint $table) { + $table->dropUnique('unique_role'); + }); + } +} diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 133a3300..2f85153e 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -101,6 +101,9 @@ 'team' => [ 'unique' => 'The team already exists in the same club.', ], + 'role' => [ + 'unique' => 'The role already exists.', + ], ], /* diff --git a/tests/Admin/DataManagement/RolesTableTest.php b/tests/Admin/DataManagement/RolesTableTest.php index f93fab0a..27267ca1 100644 --- a/tests/Admin/DataManagement/RolesTableTest.php +++ b/tests/Admin/DataManagement/RolesTableTest.php @@ -9,19 +9,127 @@ namespace Admin\DataManagement; use Tests\TestCase; +use App\Models\Role; class RolesTableTest extends TestCase { - public function testRedirectToLoginIfNotAdmin() + const BASE_ROUTE = 'admin.data-management.roles'; + + public function testRedirectIfNotAdmin() { - $this->visit(route('admin.data-management.roles.index')) + $this->visit(route(self::BASE_ROUTE . '.index')) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.create')) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.show', [1])) ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.edit', [1])) + ->seePageIs(route('login')); + + $this->call('POST', route(self::BASE_ROUTE . '.store')); + $this->assertResponseStatus(302); + + $this->call('DELETE', route(self::BASE_ROUTE . '.destroy', [1])); + $this->assertResponseStatus(302); + + $this->call('PUT', route(self::BASE_ROUTE . '.update', [1])); + $this->assertResponseStatus(302); } public function testBreadcrumbs() { $this->be($this->getFakeUser()); - $this->breadcrumbsTests('admin.data-management.roles.index', 'Roles'); + $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Roles'); + } + + public function testAddRole() + { + $this->be($this->getFakeUser()); + + /** @var Role $role */ + $role = factory(Role::class)->create(); + $roleId = $role->id; + $roleName = $role->role; + + // Brand new role + $newRoleName = 'New ' . $roleName; + $this->visit(route(self::BASE_ROUTE . '.create')) + ->type($newRoleName, 'role') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Role added!') + ->seeInDatabase('roles', ['id' => $roleId + 1, 'role' => $newRoleName]); + + // Already existing role + $this->visit(route(self::BASE_ROUTE . '.create')) + ->type($roleName, 'role') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.create')) + ->seeInElement('.alert.alert-danger', 'The role already exists.') + ->seeInDatabase('roles', ['id' => $roleId, 'role' => $roleName]); + } + + public function testEditRole() + { + $this->be($this->getFakeUser()); + + /** @var Role $role */ + $role = factory(Role::class)->create(); + $roleId = $role->id; + $roleName = $role->role; + + $newRoleName = 'New ' . $roleName; + $this->seeInDatabase('roles', ['id' => $roleId, 'role' => $roleName]) + ->visit(route(self::BASE_ROUTE . '.edit', [$roleId])) + ->type($newRoleName, 'role') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Role updated!') + ->seeInDatabase('roles', ['id' => $roleId, 'role' => $newRoleName]); + $roleName = $newRoleName; + + $anotherRole = factory(Role::class)->create(); + $anotherRoleName = $anotherRole->role; + + // Already existing role + $this->seeInDatabase('roles', ['id' => $roleId, 'role' => $roleName]) + ->visit(route(self::BASE_ROUTE . '.edit', [$roleId])) + ->type($anotherRoleName, 'role') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$roleId])) + ->seeInElement('.alert.alert-danger', 'The role already exists.') + ->seeInDatabase('roles', ['id' => $roleId, 'role' => $roleName]); + } + + public function testShowRole() + { + $this->be($this->getFakeUser()); + + /** @var Role $role */ + $role = factory(Role::class)->create(); + $roleId = $role->id; + $roleName = $role->role; + + $this->visit(route(self::BASE_ROUTE . '.show', [$roleId])) + ->seeInElement('tbody tr td:nth-child(1)', $roleId) + ->seeInElement('tbody tr td:nth-child(2)', $roleName); } + public function testDeleteRole() + { + $this->be($this->getFakeUser()); + + /** @var Role $role */ + $role = factory(Role::class)->create(); + $roleId = $role->id; + $roleName = $role->role; + + $this->seeInDatabase('roles', ['id' => $roleId, 'role' => $roleName]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$roleId])) + ->isRedirect(route(self::BASE_ROUTE . '.index')); + $this->dontSeeInDatabase('roles', ['id' => $roleId]); + } } From 98b2cf64af391a6e7a5fd85414e271c0b8fd13d2 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Mon, 9 May 2016 19:14:00 +0100 Subject: [PATCH 28/34] dev: finished test for the Venues CRUD --- .../Admin/DataManagement/VenuesController.php | 2 + .../2016_05_09_191122_make_venue_unique.sql | 2 + database/factories/ModelFactory.php | 6 + .../2016_05_09_191122_make_venue_unique.php | 31 +++++ resources/lang/en/validation.php | 3 + .../Admin/DataManagement/VenuesTableTest.php | 114 +++++++++++++++++- 6 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 database/deployment/2016_05_09_191122_make_venue_unique.sql create mode 100644 database/migrations/2016_05_09_191122_make_venue_unique.php diff --git a/app/Http/Controllers/Admin/DataManagement/VenuesController.php b/app/Http/Controllers/Admin/DataManagement/VenuesController.php index a51a0a6f..e8a96d29 100644 --- a/app/Http/Controllers/Admin/DataManagement/VenuesController.php +++ b/app/Http/Controllers/Admin/DataManagement/VenuesController.php @@ -41,6 +41,7 @@ public function create() */ public function store(Request $request) { + $this->validate($request, ['venue' => 'required|unique:venues']); Venue::create($request->all()); @@ -87,6 +88,7 @@ public function edit($id) */ public function update(Request $request, $id) { + $this->validate($request, ['venue' => 'required|unique:venues,venue,' . $id]); $venue = Venue::findOrFail($id); $venue->update($request->all()); diff --git a/database/deployment/2016_05_09_191122_make_venue_unique.sql b/database/deployment/2016_05_09_191122_make_venue_unique.sql new file mode 100644 index 00000000..8c14df28 --- /dev/null +++ b/database/deployment/2016_05_09_191122_make_venue_unique.sql @@ -0,0 +1,2 @@ +ALTER TABLE `venues` + ADD UNIQUE `unique_venue`(`venue`); \ No newline at end of file diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 9a6ede69..9403fcd8 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -54,4 +54,10 @@ return [ 'role' => $faker->word, ]; +}); + +$factory->define(\App\Models\Venue::class, function (\Faker\Generator $faker) { + return [ + 'venue' => $faker->word, + ]; }); \ No newline at end of file diff --git a/database/migrations/2016_05_09_191122_make_venue_unique.php b/database/migrations/2016_05_09_191122_make_venue_unique.php new file mode 100644 index 00000000..595ae675 --- /dev/null +++ b/database/migrations/2016_05_09_191122_make_venue_unique.php @@ -0,0 +1,31 @@ +unique(['venue'], 'unique_venue'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('venues', function (Blueprint $table) { + $table->dropUnique('unique_venue'); + }); + } +} diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 2f85153e..cf5cc4aa 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -104,6 +104,9 @@ 'role' => [ 'unique' => 'The role already exists.', ], + 'venue' => [ + 'unique' => 'The venue already exists.', + ], ], /* diff --git a/tests/Admin/DataManagement/VenuesTableTest.php b/tests/Admin/DataManagement/VenuesTableTest.php index 1163d576..defd5cbc 100644 --- a/tests/Admin/DataManagement/VenuesTableTest.php +++ b/tests/Admin/DataManagement/VenuesTableTest.php @@ -9,19 +9,127 @@ namespace Admin\DataManagement; use Tests\TestCase; +use App\Models\Venue; class VenuesTableTest extends TestCase { - public function testRedirectToLoginIfNotAdmin() + const BASE_ROUTE = 'admin.data-management.venues'; + + public function testRedirectIfNotAdmin() { - $this->visit(route('admin.data-management.venues.index')) + $this->visit(route(self::BASE_ROUTE . '.index')) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.create')) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.show', [1])) ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.edit', [1])) + ->seePageIs(route('login')); + + $this->call('POST', route(self::BASE_ROUTE . '.store')); + $this->assertResponseStatus(302); + + $this->call('DELETE', route(self::BASE_ROUTE . '.destroy', [1])); + $this->assertResponseStatus(302); + + $this->call('PUT', route(self::BASE_ROUTE . '.update', [1])); + $this->assertResponseStatus(302); } public function testBreadcrumbs() { $this->be($this->getFakeUser()); - $this->breadcrumbsTests('admin.data-management.venues.index', 'Venues'); + $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Venues'); + } + + public function testAddVenue() + { + $this->be($this->getFakeUser()); + + /** @var Venue $venue */ + $venue = factory(Venue::class)->create(); + $venueId = $venue->id; + $venueName = $venue->venue; + + // Brand new venue + $newVenueName = 'New ' . $venueName; + $this->visit(route(self::BASE_ROUTE . '.create')) + ->type($newVenueName, 'venue') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Venue added!') + ->seeInDatabase('venues', ['id' => $venueId + 1, 'venue' => $newVenueName]); + + // Already existing venue + $this->visit(route(self::BASE_ROUTE . '.create')) + ->type($venueName, 'venue') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.create')) + ->seeInElement('.alert.alert-danger', 'The venue already exists.') + ->seeInDatabase('venues', ['id' => $venueId, 'venue' => $venueName]); + } + + public function testEditVenue() + { + $this->be($this->getFakeUser()); + + /** @var Venue $venue */ + $venue = factory(Venue::class)->create(); + $venueId = $venue->id; + $venueName = $venue->venue; + + $newVenueName = 'New ' . $venueName; + $this->seeInDatabase('venues', ['id' => $venueId, 'venue' => $venueName]) + ->visit(route(self::BASE_ROUTE . '.edit', [$venueId])) + ->type($newVenueName, 'venue') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Venue updated!') + ->seeInDatabase('venues', ['id' => $venueId, 'venue' => $newVenueName]); + $venueName = $newVenueName; + + $anotherVenue = factory(Venue::class)->create(); + $anotherVenueName = $anotherVenue->venue; + + // Already existing venue + $this->seeInDatabase('venues', ['id' => $venueId, 'venue' => $venueName]) + ->visit(route(self::BASE_ROUTE . '.edit', [$venueId])) + ->type($anotherVenueName, 'venue') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$venueId])) + ->seeInElement('.alert.alert-danger', 'The venue already exists.') + ->seeInDatabase('venues', ['id' => $venueId, 'venue' => $venueName]); + } + + public function testShowVenue() + { + $this->be($this->getFakeUser()); + + /** @var Venue $venue */ + $venue = factory(Venue::class)->create(); + $venueId = $venue->id; + $venueName = $venue->venue; + + $this->visit(route(self::BASE_ROUTE . '.show', [$venueId])) + ->seeInElement('tbody tr td:nth-child(1)', $venueId) + ->seeInElement('tbody tr td:nth-child(2)', $venueName); } + public function testDeleteVenue() + { + $this->be($this->getFakeUser()); + + /** @var Venue $venue */ + $venue = factory(Venue::class)->create(); + $venueId = $venue->id; + $venueName = $venue->venue; + + $this->seeInDatabase('venues', ['id' => $venueId, 'venue' => $venueName]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$venueId])) + ->isRedirect(route(self::BASE_ROUTE . '.index')); + $this->dontSeeInDatabase('venues', ['id' => $venueId]); + } } From e2d0a5919b31573d76b440d46c219f25fb728db0 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Mon, 9 May 2016 19:28:48 +0100 Subject: [PATCH 29/34] dev: Added rollback deployment files and renamed some unclearly named migration scripts --- ...ql => 2014_10_12_000000_create_users_table.sql} | 14 -------------- ...4_10_12_100000_create_password_resets_table.sql | 14 ++++++++++++++ ... => 2016_04_03_114310_create_seasons_table.sql} | 0 ...ql => 2016_04_12_194551_create_clubs_table.sql} | 0 ...l => 2016_04_12_200052_create_venues_table.sql} | 0 ...ql => 2016_04_13_190718_create_roles_table.sql} | 0 .../2014_10_12_000000_create_users_table.sql | 1 + ...4_10_12_100000_create_password_resets_table.sql | 1 + .../2016_04_03_114310_create_seasons_table.sql | 1 + .../2016_04_12_194551_create_clubs_table.sql | 1 + .../2016_04_12_200052_create_venues_table.sql | 1 + .../2016_04_13_190718_create_roles_table.sql | 1 + .../2016_04_13_193513_create_divisions_table.sql | 3 +++ .../2016_04_14_184813_create_teams_table.sql | 3 +++ .../2016_04_15_180829_create_fixtures_table.sql | 9 +++++++++ ..._144453_create_available_appointments_table.sql | 1 + .../2016_05_07_133457_make_season_unique.sql | 2 ++ ...05_07_172130_make_division_unique_in_season.sql | 6 ++++++ .../2016_05_09_183614_make_club_unique.sql | 2 ++ .../2016_05_09_185137_make_team_unique_in_club.sql | 6 ++++++ .../2016_05_09_190454_make_role_unique.sql | 2 ++ .../2016_05_09_191122_make_venue_unique.sql | 2 ++ 22 files changed, 56 insertions(+), 14 deletions(-) rename database/deployment/{2016_02_13.sql => 2014_10_12_000000_create_users_table.sql} (54%) create mode 100644 database/deployment/2014_10_12_100000_create_password_resets_table.sql rename database/deployment/{2016_04_03.sql => 2016_04_03_114310_create_seasons_table.sql} (100%) rename database/deployment/{2016_04_12.sql => 2016_04_12_194551_create_clubs_table.sql} (100%) rename database/deployment/{2016_04_12_b.sql => 2016_04_12_200052_create_venues_table.sql} (100%) rename database/deployment/{2016_04_13.sql => 2016_04_13_190718_create_roles_table.sql} (100%) create mode 100644 database/deployment/rollbacks/2014_10_12_000000_create_users_table.sql create mode 100644 database/deployment/rollbacks/2014_10_12_100000_create_password_resets_table.sql create mode 100644 database/deployment/rollbacks/2016_04_03_114310_create_seasons_table.sql create mode 100644 database/deployment/rollbacks/2016_04_12_194551_create_clubs_table.sql create mode 100644 database/deployment/rollbacks/2016_04_12_200052_create_venues_table.sql create mode 100644 database/deployment/rollbacks/2016_04_13_190718_create_roles_table.sql create mode 100644 database/deployment/rollbacks/2016_04_13_193513_create_divisions_table.sql create mode 100644 database/deployment/rollbacks/2016_04_14_184813_create_teams_table.sql create mode 100644 database/deployment/rollbacks/2016_04_15_180829_create_fixtures_table.sql create mode 100644 database/deployment/rollbacks/2016_04_23_144453_create_available_appointments_table.sql create mode 100644 database/deployment/rollbacks/2016_05_07_133457_make_season_unique.sql create mode 100644 database/deployment/rollbacks/2016_05_07_172130_make_division_unique_in_season.sql create mode 100644 database/deployment/rollbacks/2016_05_09_183614_make_club_unique.sql create mode 100644 database/deployment/rollbacks/2016_05_09_185137_make_team_unique_in_club.sql create mode 100644 database/deployment/rollbacks/2016_05_09_190454_make_role_unique.sql create mode 100644 database/deployment/rollbacks/2016_05_09_191122_make_venue_unique.sql diff --git a/database/deployment/2016_02_13.sql b/database/deployment/2014_10_12_000000_create_users_table.sql similarity index 54% rename from database/deployment/2016_02_13.sql rename to database/deployment/2014_10_12_000000_create_users_table.sql index a22fff25..8acdf39c 100644 --- a/database/deployment/2016_02_13.sql +++ b/database/deployment/2014_10_12_000000_create_users_table.sql @@ -13,17 +13,3 @@ CREATE TABLE `users` ( ALTER TABLE `users` ADD UNIQUE `users_email_unique`(`email`); - -CREATE TABLE `password_resets` ( - `email` VARCHAR(255) NOT NULL, - `token` VARCHAR(255) NOT NULL, - `created_at` TIMESTAMP NOT NULL -) - DEFAULT CHARACTER SET utf8 - COLLATE utf8_unicode_ci - ENGINE = InnoDB; - -ALTER TABLE `password_resets` - ADD INDEX `password_resets_email_index`(`email`); -ALTER TABLE `password_resets` - ADD INDEX `password_resets_token_index`(`token`); diff --git a/database/deployment/2014_10_12_100000_create_password_resets_table.sql b/database/deployment/2014_10_12_100000_create_password_resets_table.sql new file mode 100644 index 00000000..d8cb1274 --- /dev/null +++ b/database/deployment/2014_10_12_100000_create_password_resets_table.sql @@ -0,0 +1,14 @@ + +CREATE TABLE `password_resets` ( + `email` VARCHAR(255) NOT NULL, + `token` VARCHAR(255) NOT NULL, + `created_at` TIMESTAMP NOT NULL +) + DEFAULT CHARACTER SET utf8 + COLLATE utf8_unicode_ci + ENGINE = InnoDB; + +ALTER TABLE `password_resets` + ADD INDEX `password_resets_email_index`(`email`); +ALTER TABLE `password_resets` + ADD INDEX `password_resets_token_index`(`token`); diff --git a/database/deployment/2016_04_03.sql b/database/deployment/2016_04_03_114310_create_seasons_table.sql similarity index 100% rename from database/deployment/2016_04_03.sql rename to database/deployment/2016_04_03_114310_create_seasons_table.sql diff --git a/database/deployment/2016_04_12.sql b/database/deployment/2016_04_12_194551_create_clubs_table.sql similarity index 100% rename from database/deployment/2016_04_12.sql rename to database/deployment/2016_04_12_194551_create_clubs_table.sql diff --git a/database/deployment/2016_04_12_b.sql b/database/deployment/2016_04_12_200052_create_venues_table.sql similarity index 100% rename from database/deployment/2016_04_12_b.sql rename to database/deployment/2016_04_12_200052_create_venues_table.sql diff --git a/database/deployment/2016_04_13.sql b/database/deployment/2016_04_13_190718_create_roles_table.sql similarity index 100% rename from database/deployment/2016_04_13.sql rename to database/deployment/2016_04_13_190718_create_roles_table.sql diff --git a/database/deployment/rollbacks/2014_10_12_000000_create_users_table.sql b/database/deployment/rollbacks/2014_10_12_000000_create_users_table.sql new file mode 100644 index 00000000..9ac7cd44 --- /dev/null +++ b/database/deployment/rollbacks/2014_10_12_000000_create_users_table.sql @@ -0,0 +1 @@ +DROP TABLE `users`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2014_10_12_100000_create_password_resets_table.sql b/database/deployment/rollbacks/2014_10_12_100000_create_password_resets_table.sql new file mode 100644 index 00000000..5e9706fe --- /dev/null +++ b/database/deployment/rollbacks/2014_10_12_100000_create_password_resets_table.sql @@ -0,0 +1 @@ +DROP TABLE `password_resets`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_04_03_114310_create_seasons_table.sql b/database/deployment/rollbacks/2016_04_03_114310_create_seasons_table.sql new file mode 100644 index 00000000..2646b57f --- /dev/null +++ b/database/deployment/rollbacks/2016_04_03_114310_create_seasons_table.sql @@ -0,0 +1 @@ +DROP TABLE `seasons`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_04_12_194551_create_clubs_table.sql b/database/deployment/rollbacks/2016_04_12_194551_create_clubs_table.sql new file mode 100644 index 00000000..4892b9f4 --- /dev/null +++ b/database/deployment/rollbacks/2016_04_12_194551_create_clubs_table.sql @@ -0,0 +1 @@ +DROP TABLE `clubs`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_04_12_200052_create_venues_table.sql b/database/deployment/rollbacks/2016_04_12_200052_create_venues_table.sql new file mode 100644 index 00000000..88f61e4d --- /dev/null +++ b/database/deployment/rollbacks/2016_04_12_200052_create_venues_table.sql @@ -0,0 +1 @@ +DROP TABLE `venues`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_04_13_190718_create_roles_table.sql b/database/deployment/rollbacks/2016_04_13_190718_create_roles_table.sql new file mode 100644 index 00000000..b74faf3b --- /dev/null +++ b/database/deployment/rollbacks/2016_04_13_190718_create_roles_table.sql @@ -0,0 +1 @@ +DROP TABLE `roles`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_04_13_193513_create_divisions_table.sql b/database/deployment/rollbacks/2016_04_13_193513_create_divisions_table.sql new file mode 100644 index 00000000..ba9c97b2 --- /dev/null +++ b/database/deployment/rollbacks/2016_04_13_193513_create_divisions_table.sql @@ -0,0 +1,3 @@ +ALTER TABLE `divisions` + DROP FOREIGN KEY `divisions_season_id_foreign`; +DROP TABLE `divisions`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_04_14_184813_create_teams_table.sql b/database/deployment/rollbacks/2016_04_14_184813_create_teams_table.sql new file mode 100644 index 00000000..ca5280ea --- /dev/null +++ b/database/deployment/rollbacks/2016_04_14_184813_create_teams_table.sql @@ -0,0 +1,3 @@ +ALTER TABLE `teams` + DROP FOREIGN KEY `teams_club_id_foreign`; +DROP TABLE `teams`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_04_15_180829_create_fixtures_table.sql b/database/deployment/rollbacks/2016_04_15_180829_create_fixtures_table.sql new file mode 100644 index 00000000..0580c30b --- /dev/null +++ b/database/deployment/rollbacks/2016_04_15_180829_create_fixtures_table.sql @@ -0,0 +1,9 @@ +ALTER TABLE `fixtures` + DROP FOREIGN KEY `fixtures_division_id_foreign`; +ALTER TABLE `fixtures` + DROP FOREIGN KEY `fixtures_home_team_id_foreign`; +ALTER TABLE `fixtures` + DROP FOREIGN KEY `fixtures_away_team_id_foreign`; +ALTER TABLE `fixtures` + DROP FOREIGN KEY `fixtures_venue_id_foreign`; +DROP TABLE `fixtures`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_04_23_144453_create_available_appointments_table.sql b/database/deployment/rollbacks/2016_04_23_144453_create_available_appointments_table.sql new file mode 100644 index 00000000..e0e4051e --- /dev/null +++ b/database/deployment/rollbacks/2016_04_23_144453_create_available_appointments_table.sql @@ -0,0 +1 @@ +DROP TABLE `available_appointments`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_05_07_133457_make_season_unique.sql b/database/deployment/rollbacks/2016_05_07_133457_make_season_unique.sql new file mode 100644 index 00000000..e945ec30 --- /dev/null +++ b/database/deployment/rollbacks/2016_05_07_133457_make_season_unique.sql @@ -0,0 +1,2 @@ +ALTER TABLE `seasons` + DROP INDEX `seasons_season_unique`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_05_07_172130_make_division_unique_in_season.sql b/database/deployment/rollbacks/2016_05_07_172130_make_division_unique_in_season.sql new file mode 100644 index 00000000..d6d937df --- /dev/null +++ b/database/deployment/rollbacks/2016_05_07_172130_make_division_unique_in_season.sql @@ -0,0 +1,6 @@ +ALTER TABLE `divisions` + DROP FOREIGN KEY `divisions_season_id_foreign`; +ALTER TABLE `divisions` + DROP INDEX `unique_division`; +ALTER TABLE `divisions` + ADD CONSTRAINT `divisions_season_id_foreign` FOREIGN KEY (`season_id`) REFERENCES `seasons` (`id`); \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_05_09_183614_make_club_unique.sql b/database/deployment/rollbacks/2016_05_09_183614_make_club_unique.sql new file mode 100644 index 00000000..d8a13026 --- /dev/null +++ b/database/deployment/rollbacks/2016_05_09_183614_make_club_unique.sql @@ -0,0 +1,2 @@ +ALTER TABLE `clubs` + DROP INDEX `unique_club`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_05_09_185137_make_team_unique_in_club.sql b/database/deployment/rollbacks/2016_05_09_185137_make_team_unique_in_club.sql new file mode 100644 index 00000000..b0779f06 --- /dev/null +++ b/database/deployment/rollbacks/2016_05_09_185137_make_team_unique_in_club.sql @@ -0,0 +1,6 @@ +ALTER TABLE `teams` + DROP FOREIGN KEY `teams_club_id_foreign`; +ALTER TABLE `teams` + DROP INDEX `unique_team_in_club`; +ALTER TABLE `teams` + ADD CONSTRAINT `teams_club_id_foreign` FOREIGN KEY (`club_id`) REFERENCES `clubs` (`id`); diff --git a/database/deployment/rollbacks/2016_05_09_190454_make_role_unique.sql b/database/deployment/rollbacks/2016_05_09_190454_make_role_unique.sql new file mode 100644 index 00000000..caf6639e --- /dev/null +++ b/database/deployment/rollbacks/2016_05_09_190454_make_role_unique.sql @@ -0,0 +1,2 @@ +ALTER TABLE `roles` + DROP INDEX `unique_role`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_05_09_191122_make_venue_unique.sql b/database/deployment/rollbacks/2016_05_09_191122_make_venue_unique.sql new file mode 100644 index 00000000..3a2bd46f --- /dev/null +++ b/database/deployment/rollbacks/2016_05_09_191122_make_venue_unique.sql @@ -0,0 +1,2 @@ +ALTER TABLE `venues` + DROP INDEX `unique_venue`; \ No newline at end of file From b73fe594a8f163022b0ed323dc04593a4a479352 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Mon, 9 May 2016 23:36:20 +0100 Subject: [PATCH 30/34] dev: finished test for the Available Appointments CRUD --- database/factories/ModelFactory.php | 48 +++- .../AvailableAppointmentsTableTest.php | 230 +++++++++++++++++- 2 files changed, 267 insertions(+), 11 deletions(-) diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 9403fcd8..11d1e095 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -13,8 +13,8 @@ $factory->define(App\User::class, function (Faker\Generator $faker) { return [ - 'name' => $faker->name, - 'email' => $faker->email, + 'name' => $faker->unique()->name, + 'email' => $faker->unique()->email, 'password' => bcrypt(str_random(10)), 'remember_token' => str_random(10), ]; @@ -22,13 +22,13 @@ $factory->define(\App\Models\Season::class, function (\Faker\Generator $faker) { return [ - 'season' => $faker->word, + 'season' => $faker->unique()->word, ]; }); $factory->define(App\Models\Division::class, function (\Faker\Generator $faker) { return [ - 'division' => $faker->word, + 'division' => $faker->unique()->word, 'season_id' => function () { return factory(App\Models\Season::class)->create()->id; }, @@ -37,13 +37,13 @@ $factory->define(\App\Models\Club::class, function (\Faker\Generator $faker) { return [ - 'club' => $faker->word, + 'club' => $faker->unique()->word, ]; }); $factory->define(App\Models\Team::class, function (\Faker\Generator $faker) { return [ - 'team' => $faker->word, + 'team' => $faker->unique()->word, 'club_id' => function () { return factory(App\Models\Club::class)->create()->id; }, @@ -52,12 +52,44 @@ $factory->define(\App\Models\Role::class, function (\Faker\Generator $faker) { return [ - 'role' => $faker->word, + 'role' => $faker->unique()->word, ]; }); $factory->define(\App\Models\Venue::class, function (\Faker\Generator $faker) { return [ - 'venue' => $faker->word, + 'venue' => $faker->unique()->word, + ]; +}); + +$factory->define(\App\Models\Fixture::class, function (\Faker\Generator $faker) { + return [ + 'division_id' => function () { + return factory(\App\Models\Division::class)->create()->id; + }, + 'home_team_id' => function () { + return factory(\App\Models\Team::class)->create()->id; + }, + 'away_team_id' => function () { + return factory(\App\Models\Team::class)->create()->id; + }, + 'venue_id' => function () { + return factory(\App\Models\Venue::class)->create()->id; + }, + 'match_number' => $faker->numberBetween(1, 100), + 'match_date' => $faker->date(), + 'warm_up_time' => $faker->time(), + 'start_time' => $faker->time(), + ]; +}); + +$factory->define(\App\Models\AvailableAppointment::class, function (\Faker\Generator $faker) { + return [ + 'fixture_id' => function () { + return factory(\App\Models\Fixture::class)->create()->id; + }, + 'role_id' => function () { + return factory(\App\Models\Role::class)->create()->id; + }, ]; }); \ No newline at end of file diff --git a/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php b/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php index 425b144a..97d3824b 100644 --- a/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php +++ b/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php @@ -9,19 +9,243 @@ namespace Admin\DataManagement; use Tests\TestCase; +use App\Models\AvailableAppointment; +use App\Models\Fixture; +use App\Models\Role; class AvailableAppointmentsTableTest extends TestCase { - public function testRedirectToLoginIfNotAdmin() + const BASE_ROUTE = 'admin.data-management.available-appointments'; + + public function testRedirectIfNotAdmin() { - $this->visit(route('admin.data-management.available-appointments.index')) + $this->visit(route(self::BASE_ROUTE . '.index')) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.create')) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.show', [1])) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.edit', [1])) ->seePageIs(route('login')); + + $this->call('POST', route(self::BASE_ROUTE . '.store')); + $this->assertResponseStatus(302); + + $this->call('DELETE', route(self::BASE_ROUTE . '.destroy', [1])); + $this->assertResponseStatus(302); + + $this->call('PUT', route(self::BASE_ROUTE . '.update', [1])); + $this->assertResponseStatus(302); } public function testBreadcrumbs() { $this->be($this->getFakeUser()); - $this->breadcrumbsTests('admin.data-management.available-appointments.index', 'Available appointments'); + $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Available appointments'); + } + + public function testAddAvailableAppointment() + { + $this->be($this->getFakeUser()); + + /** @var AvailableAppointment $availableAppointment */ + $availableAppointment = factory(AvailableAppointment::class)->create(); + $availableAppointmentId = $availableAppointment->id; + $fixtureId = $availableAppointment->fixture_id; + $roleId = $availableAppointment->role_id; + + $otherFixtureId = factory(Fixture::class)->create()->id; + $otherRoleId = factory(Role::class)->create()->id; + + // Brand new appointment + $this->visit(route(self::BASE_ROUTE . '.create')) + ->select($otherFixtureId, 'fixture_id') + ->select($otherRoleId, 'role_id') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Appointment added!') + ->seeInDatabase('available_appointments', [ + 'id' => $availableAppointmentId + 1, + 'fixture_id' => $otherFixtureId, + 'role_id' => $otherRoleId, + ]); + + // Already existing appointment in the same fixture with different role + $this->visit(route(self::BASE_ROUTE . '.create')) + ->select($fixtureId, 'fixture_id') + ->select($otherRoleId, 'role_id') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Appointment added!') + ->seeInDatabase('available_appointments', [ + 'id' => $availableAppointmentId + 2, + 'fixture_id' => $fixtureId, + 'role_id' => $otherRoleId, + ]); + + // Already existing appointment in the same role with different fixture + $this->visit(route(self::BASE_ROUTE . '.create')) + ->select($otherFixtureId, 'fixture_id') + ->select($roleId, 'role_id') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Appointment added!') + ->seeInDatabase('available_appointments', [ + 'id' => $availableAppointmentId + 3, + 'fixture_id' => $otherFixtureId, + 'role_id' => $roleId, + ]); + + // Already existing appointment + $this->visit(route(self::BASE_ROUTE . '.create')) + ->select($fixtureId, 'fixture_id') + ->select($roleId, 'role_id') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.create')) + ->seeInElement('.alert.alert-danger', 'Appointment already added.') + ->seeInDatabase('available_appointments', [ + 'id' => $availableAppointmentId, + 'fixture_id' => $fixtureId, + 'role_id' => $roleId, + ]); + } + + public function testEditAvailableAppointment() + { + $this->be($this->getFakeUser()); + + /** @var AvailableAppointment $availableAppointment */ + $availableAppointment = factory(AvailableAppointment::class)->create(); + $availableAppointmentId = $availableAppointment->id; + $fixtureId = $availableAppointment->fixture_id; + $roleId = $availableAppointment->role_id; + + $otherFixtureId = factory(Fixture::class)->create()->id; + $otherRoleId = factory(Role::class)->create()->id; + + // Change the role of the existing appointment + $this->seeInDatabase('available_appointments', [ + 'id' => $availableAppointmentId, + 'fixture_id' => $fixtureId, + 'role_id' => $roleId, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$availableAppointmentId])) + ->select($otherRoleId, 'role_id') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Appointment updated!') + ->seeInDatabase('available_appointments', [ + 'id' => $availableAppointmentId, + 'fixture_id' => $fixtureId, + 'role_id' => $otherRoleId, + ]); + $roleId = $otherRoleId; + + // Change the fixture of the existing appointment + $this->seeInDatabase('available_appointments', [ + 'id' => $availableAppointmentId, + 'fixture_id' => $fixtureId, + 'role_id' => $roleId, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$availableAppointmentId])) + ->select($otherFixtureId, 'fixture_id') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Appointment updated!') + ->seeInDatabase('available_appointments', [ + 'id' => $availableAppointmentId, + 'fixture_id' => $otherFixtureId, + 'role_id' => $roleId, + ]); + $fixtureId = $otherFixtureId; + + // Already existing availableAppointment in the same fixture + /** @var AvailableAppointment $anotherAvailableAppointment */ + $anotherAvailableAppointment = factory(AvailableAppointment::class)->create(['fixture_id' => $fixtureId]); + $anotherAvailableAppointmentRoleId = $anotherAvailableAppointment->role_id; + + $this->seeInDatabase('available_appointments', [ + 'id' => $availableAppointmentId, + 'fixture_id' => $fixtureId, + 'role_id' => $roleId, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$availableAppointmentId])) + ->select($anotherAvailableAppointmentRoleId, 'role_id') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$availableAppointmentId])) + ->seeInElement('.alert.alert-danger', 'Appointment already added.') + ->seeInDatabase('available_appointments', [ + 'id' => $availableAppointmentId, + 'fixture_id' => $fixtureId, + 'role_id' => $roleId, + ]); + + // Already existing availableAppointment in the same role + /** @var AvailableAppointment $yetAnotherAvailableAppointment */ + $yetAnotherAvailableAppointment = factory(AvailableAppointment::class)->create(['role_id' => $roleId]); + $yetAnotherAvailableAppointmentFixtureId = $yetAnotherAvailableAppointment->fixture_id; + + $this->seeInDatabase('available_appointments', [ + 'id' => $availableAppointmentId, + 'fixture_id' => $fixtureId, + 'role_id' => $roleId, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$availableAppointmentId])) + ->select($yetAnotherAvailableAppointmentFixtureId, 'fixture_id') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$availableAppointmentId])) + ->seeInElement('.alert.alert-danger', 'Appointment already added.') + ->seeInDatabase('available_appointments', [ + 'id' => $availableAppointmentId, + 'fixture_id' => $fixtureId, + 'role_id' => $roleId, + ]); } + public function testShowAvailableAppointment() + { + $this->be($this->getFakeUser()); + + /** @var AvailableAppointment $availableAppointment */ + $availableAppointment = factory(AvailableAppointment::class)->create(); + $availableAppointmentId = $availableAppointment->id; + $fixtureId = $availableAppointment->fixture_id; + $roleId = $availableAppointment->role_id; + + /** @var Fixture $fixture */ + $fixture = Fixture::find($fixtureId); + $fixtureName = $fixture->fixture; + + /** @var Role $role */ + $role = Role::find($roleId); + $roleName = $role->role; + + $this->visit(route(self::BASE_ROUTE . '.show', [$availableAppointmentId])) + ->seeInElement('tbody tr td:nth-child(1)', $availableAppointmentId) + ->seeInElement('tbody tr td:nth-child(2)', $fixtureName) + ->seeInElement('tbody tr td:nth-child(3)', $roleName); + } + + public function testDeleteAvailableAppointment() + { + $this->be($this->getFakeUser()); + + /** @var AvailableAppointment $availableAppointment */ + $availableAppointment = factory(AvailableAppointment::class)->create(); + $availableAppointmentId = $availableAppointment->id; + $fixtureId = $availableAppointment->fixture_id; + $roleId = $availableAppointment->role_id; + + $this->seeInDatabase('available_appointments', [ + 'id' => $availableAppointmentId, + 'fixture_id' => $fixtureId, + 'role_id' => $roleId]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$availableAppointmentId])) + ->isRedirect(route(self::BASE_ROUTE . '.index')); + + $this->dontSeeInDatabase('available_appointments', ['id' => $availableAppointmentId]); + } } From a4ce72a716fde82c5f88671fe867ccce22a24e3a Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Wed, 11 May 2016 19:47:30 +0100 Subject: [PATCH 31/34] dev: added the tests for adding a fixture (part for the tests for the Fixture CRUD) --- .../DataManagement/FixturesController.php | 68 ++++++---- ..._division_and_teams_unique_in_fixtures.sql | 2 + ..._division_and_teams_unique_in_fixtures.sql | 6 + database/factories/ModelFactory.php | 6 +- ..._division_and_teams_unique_in_fixtures.php | 36 ++++++ resources/lang/en/validation.php | 2 +- .../DataManagement/FixturesTableTest.php | 117 +++++++++++++++++- 7 files changed, 207 insertions(+), 30 deletions(-) create mode 100644 database/deployment/2016_05_11_190337_make_division_and_teams_unique_in_fixtures.sql create mode 100644 database/deployment/rollbacks/2016_05_11_190337_make_division_and_teams_unique_in_fixtures.sql create mode 100644 database/migrations/2016_05_11_190337_make_division_and_teams_unique_in_fixtures.php diff --git a/app/Http/Controllers/Admin/DataManagement/FixturesController.php b/app/Http/Controllers/Admin/DataManagement/FixturesController.php index e0ae47be..b358d41a 100644 --- a/app/Http/Controllers/Admin/DataManagement/FixturesController.php +++ b/app/Http/Controllers/Admin/DataManagement/FixturesController.php @@ -48,16 +48,28 @@ public function create() */ public function store(Request $request) { - $this->validate($request, [ - 'division_id' => 'required', - 'match_number' => 'required', - 'match_date' => 'required', - 'warm_up_time' => 'required', - 'start_time' => 'required', - 'home_team_id' => 'required', - 'away_team_id' => 'required', - 'venue_id' => 'required', - ]); + $this->validate($request, + [ + 'division_id' => + 'required|' . + 'exists:divisions,id|' . + 'unique:fixtures,division_id,NULL,id' . + ',home_team_id,' . $request->get('home_team_id') . + ',away_team_id,' . $request->get('away_team_id'), + 'match_number' => 'required|unique:fixtures,match_number,NULL,id,division_id,' . $request->get('division_id'), + 'match_date' => 'required', + 'warm_up_time' => 'required', + 'start_time' => 'required', + 'home_team_id' => 'required|exists:teams,id', + 'away_team_id' => 'required|exists:teams,id|different:home_team_id', + 'venue_id' => 'required|exists:venues,id', + ], + [ + 'away_team_id.different' => 'The away team cannot be the same as the home team.', + 'division_id.unique' => 'The fixture for these two teams have already been added in this division.', + 'match_number.unique' => 'There is already a match with the same number in this division.', + ] + ); Fixture::create($request->all()); @@ -93,7 +105,7 @@ public function edit($id) $divisions = Division::all(); $teams = Team::all(); $venues = Venue::all(); - + return view('admin.data-management.fixtures.edit', compact('fixture', 'divisions', 'teams', 'venues')); } @@ -107,17 +119,29 @@ public function edit($id) */ public function update(Request $request, $id) { - $this->validate($request, [ - 'division_id' => 'required', - 'match_number' => 'required', - 'match_date' => 'required', - 'warm_up_time' => 'required', - 'start_time' => 'required', - 'home_team_id' => 'required', - 'away_team_id' => 'required', - 'venue_id' => 'required', - ]); - + $this->validate($request, + [ + 'division_id' => + 'required|' . + 'exists:divisions,id|' . + 'unique:fixtures,division_id,NULL,id' . + ',home_team_id,' . $request->get('home_team_id') . + ',away_team_id,' . $request->get('away_team_id'), + 'match_number' => 'required|unique:fixtures,match_number,NULL,id,division_id,' . $request->get('division_id'), + 'match_date' => 'required', + 'warm_up_time' => 'required', + 'start_time' => 'required', + 'home_team_id' => 'required|exists:teams,id', + 'away_team_id' => 'required|exists:teams,id|different:home_team_id', + 'venue_id' => 'required|exists:venues,id', + ], + [ + 'away_team_id.different' => 'The away team cannot be the same as the home team.', + 'division_id.unique' => 'The fixture for these two teams have already been added in this division.', + 'match_number.unique' => 'There is already a match with the same number in this division.', + ] + ); + $fixture = Fixture::findOrFail($id); $fixture->update($request->all()); diff --git a/database/deployment/2016_05_11_190337_make_division_and_teams_unique_in_fixtures.sql b/database/deployment/2016_05_11_190337_make_division_and_teams_unique_in_fixtures.sql new file mode 100644 index 00000000..a6240952 --- /dev/null +++ b/database/deployment/2016_05_11_190337_make_division_and_teams_unique_in_fixtures.sql @@ -0,0 +1,2 @@ +ALTER TABLE `fixtures` + ADD UNIQUE `unique_division_and_teams`(`division_id`, `home_team_id`, `away_team_id`); \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_05_11_190337_make_division_and_teams_unique_in_fixtures.sql b/database/deployment/rollbacks/2016_05_11_190337_make_division_and_teams_unique_in_fixtures.sql new file mode 100644 index 00000000..568b12c5 --- /dev/null +++ b/database/deployment/rollbacks/2016_05_11_190337_make_division_and_teams_unique_in_fixtures.sql @@ -0,0 +1,6 @@ +ALTER TABLE `fixtures` + DROP FOREIGN KEY `fixtures_division_id_foreign`; +ALTER TABLE `fixtures` + DROP INDEX `unique_division_and_teams`; +ALTER TABLE `fixtures` + ADD CONSTRAINT `fixtures_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`); \ No newline at end of file diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 11d1e095..89ba79b3 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -77,9 +77,9 @@ return factory(\App\Models\Venue::class)->create()->id; }, 'match_number' => $faker->numberBetween(1, 100), - 'match_date' => $faker->date(), - 'warm_up_time' => $faker->time(), - 'start_time' => $faker->time(), + 'match_date' => $faker->date('Y-m-d'), + 'warm_up_time' => $faker->time('H:i:s'), + 'start_time' => $faker->time('H:i:s'), ]; }); diff --git a/database/migrations/2016_05_11_190337_make_division_and_teams_unique_in_fixtures.php b/database/migrations/2016_05_11_190337_make_division_and_teams_unique_in_fixtures.php new file mode 100644 index 00000000..99fff318 --- /dev/null +++ b/database/migrations/2016_05_11_190337_make_division_and_teams_unique_in_fixtures.php @@ -0,0 +1,36 @@ +unique(['division_id', 'home_team_id', 'away_team_id'], 'unique_division_and_teams'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // Adding the unique index deleted the index on season_id necessary for the foreign key + // MySQL would also complain if we try to just drop the unique index saying that it's + // necessary for the foreign key (sigh). This is why we drop the foreign key and add it again + Schema::table('fixtures', function (Blueprint $table) { + $table->dropForeign(['division_id']); + $table->dropIndex('unique_division_and_teams'); + $table->foreign('division_id')->references('id')->on('divisions'); + }); + } +} diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index cf5cc4aa..2649f435 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -106,7 +106,7 @@ ], 'venue' => [ 'unique' => 'The venue already exists.', - ], + ] ], /* diff --git a/tests/Admin/DataManagement/FixturesTableTest.php b/tests/Admin/DataManagement/FixturesTableTest.php index 56abe65a..7ac3a7de 100644 --- a/tests/Admin/DataManagement/FixturesTableTest.php +++ b/tests/Admin/DataManagement/FixturesTableTest.php @@ -8,20 +8,129 @@ namespace Admin\DataManagement; +use Faker\Generator; use Tests\TestCase; +use App\Models\Fixture; +use App\Models\Division; +use App\Models\Team; +use App\Models\Venue; class FixturesTableTest extends TestCase { - public function testRedirectToLoginIfNotAdmin() + const BASE_ROUTE = 'admin.data-management.fixtures'; + + /** @var Generator */ + private $faker; + + public function setUp() { - $this->visit(route('admin.data-management.fixtures.index')) - ->seePageIs(route('login')); + parent::setUp(); + + $this->faker = new Generator(); } + public function testRedirectIfNotAdmin() + { + $this->visit(route(self::BASE_ROUTE . '.index')) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.create')) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.show', [1])) + ->seePageIs(route('login')); + + $this->visit(route(self::BASE_ROUTE . '.edit', [1])) + ->seePageIs(route('login')); + + $this->call('POST', route(self::BASE_ROUTE . '.store')); + $this->assertResponseStatus(302); + + $this->call('DELETE', route(self::BASE_ROUTE . '.destroy', [1])); + $this->assertResponseStatus(302); + + $this->call('PUT', route(self::BASE_ROUTE . '.update', [1])); + $this->assertResponseStatus(302); + } + public function testBreadcrumbs() { $this->be($this->getFakeUser()); - $this->breadcrumbsTests('admin.data-management.fixtures.index', 'Fixtures'); + $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Fixtures'); } + public function testAddFixture() + { + $this->be($this->getFakeUser()); + + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->make(); + + // Brand new fixture + $this->visit(route(self::BASE_ROUTE . '.create')) + ->select($fixture->division_id, 'division_id') + ->select($fixture->home_team_id, 'home_team_id') + ->select($fixture->away_team_id, 'away_team_id') + ->select($fixture->venue_id, 'venue_id') + ->type($fixture->match_number, 'match_number') + ->type($fixture->match_date, 'match_date') + ->type($fixture->warm_up_time, 'warm_up_time') + ->type($fixture->start_time, 'start_time') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Fixture added!') + ->seeInDatabase('fixtures', [ + 'id' => 1, + 'division_id' => $fixture->division_id, + 'home_team_id' => $fixture->home_team_id, + 'away_team_id' => $fixture->away_team_id, + 'venue_id' => $fixture->venue_id, + 'match_number' => $fixture->match_number, + 'match_date' => $fixture->match_date->format('Y-m-d'), + 'warm_up_time' => $fixture->warm_up_time, + 'start_time' => $fixture->start_time, + ]); + + // New fixture with same home and away team + $this->visit(route(self::BASE_ROUTE . '.create')) + ->select($fixture->division_id, 'division_id') + ->select($fixture->home_team_id, 'home_team_id') + ->select($fixture->home_team_id, 'away_team_id') + ->select($fixture->venue_id, 'venue_id') + ->type($fixture->match_number, 'match_number') + ->type($fixture->match_date, 'match_date') + ->type($fixture->warm_up_time, 'warm_up_time') + ->type($fixture->start_time, 'start_time') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.create')) + ->seeInElement('.alert.alert-danger', 'The away team cannot be the same as the home team.'); + + // New fixture with same division, home and away teams of existing one + $this->visit(route(self::BASE_ROUTE . '.create')) + ->select($fixture->division_id, 'division_id') + ->select($fixture->home_team_id, 'home_team_id') + ->select($fixture->away_team_id, 'away_team_id') + ->select($fixture->venue_id, 'venue_id') + ->type($fixture->match_number, 'match_number') + ->type($fixture->match_date, 'match_date') + ->type($fixture->warm_up_time, 'warm_up_time') + ->type($fixture->start_time, 'start_time') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.create')) + ->seeInElement('.alert.alert-danger', 'The fixture for these two teams have already been added in this division.'); + + // New fixture with same division and match number of existing one + $this->visit(route(self::BASE_ROUTE . '.create')) + ->select($fixture->division_id, 'division_id') + ->select($fixture->home_team_id, 'home_team_id') + ->select($fixture->away_team_id, 'away_team_id') + ->select($fixture->venue_id, 'venue_id') + ->type($fixture->match_number, 'match_number') + ->type($fixture->match_date, 'match_date') + ->type($fixture->warm_up_time, 'warm_up_time') + ->type($fixture->start_time, 'start_time') + ->press('Add') + ->seePageIs(route(self::BASE_ROUTE . '.create')) + ->seeInElement('.alert.alert-danger', 'There is already a match with the same number in this division.'); + } } From bbd11b5036d9820b79ec352f99db02cbd6bfb455 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Thu, 12 May 2016 19:29:41 +0100 Subject: [PATCH 32/34] dev: finished tests for the Fixture CRUD) --- database/factories/ModelFactory.php | 12 +- .../DataManagement/FixturesTableTest.php | 148 ++++++++++++++++-- 2 files changed, 137 insertions(+), 23 deletions(-) diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 89ba79b3..c3334a46 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -15,8 +15,8 @@ return [ 'name' => $faker->unique()->name, 'email' => $faker->unique()->email, - 'password' => bcrypt(str_random(10)), - 'remember_token' => str_random(10), + 'password' => bcrypt($faker->unique()->password()), + 'remember_token' => $faker->unique()->md5, ]; }); @@ -76,10 +76,10 @@ 'venue_id' => function () { return factory(\App\Models\Venue::class)->create()->id; }, - 'match_number' => $faker->numberBetween(1, 100), - 'match_date' => $faker->date('Y-m-d'), - 'warm_up_time' => $faker->time('H:i:s'), - 'start_time' => $faker->time('H:i:s'), + 'match_number' => $faker->unique()->numberBetween(1, 100), + 'match_date' => $faker->unique()->date('Y-m-d'), + 'warm_up_time' => $faker->unique()->time('H:i:s'), + 'start_time' => $faker->unique()->time('H:i:s'), ]; }); diff --git a/tests/Admin/DataManagement/FixturesTableTest.php b/tests/Admin/DataManagement/FixturesTableTest.php index 7ac3a7de..9411b555 100644 --- a/tests/Admin/DataManagement/FixturesTableTest.php +++ b/tests/Admin/DataManagement/FixturesTableTest.php @@ -11,24 +11,11 @@ use Faker\Generator; use Tests\TestCase; use App\Models\Fixture; -use App\Models\Division; -use App\Models\Team; -use App\Models\Venue; class FixturesTableTest extends TestCase { const BASE_ROUTE = 'admin.data-management.fixtures'; - /** @var Generator */ - private $faker; - - public function setUp() - { - parent::setUp(); - - $this->faker = new Generator(); - } - public function testRedirectIfNotAdmin() { $this->visit(route(self::BASE_ROUTE . '.index')) @@ -52,7 +39,7 @@ public function testRedirectIfNotAdmin() $this->call('PUT', route(self::BASE_ROUTE . '.update', [1])); $this->assertResponseStatus(302); } - + public function testBreadcrumbs() { $this->be($this->getFakeUser()); @@ -103,7 +90,8 @@ public function testAddFixture() ->type($fixture->start_time, 'start_time') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.create')) - ->seeInElement('.alert.alert-danger', 'The away team cannot be the same as the home team.'); + ->seeInElement('.alert.alert-danger', 'The away team cannot be the same as the home team.') + ->dontSeeInDatabase('fixtures', ['id' => 2]); // New fixture with same division, home and away teams of existing one $this->visit(route(self::BASE_ROUTE . '.create')) @@ -117,7 +105,8 @@ public function testAddFixture() ->type($fixture->start_time, 'start_time') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.create')) - ->seeInElement('.alert.alert-danger', 'The fixture for these two teams have already been added in this division.'); + ->seeInElement('.alert.alert-danger', 'The fixture for these two teams have already been added in this division.') + ->dontSeeInDatabase('fixtures', ['id' => 2]); // New fixture with same division and match number of existing one $this->visit(route(self::BASE_ROUTE . '.create')) @@ -131,6 +120,131 @@ public function testAddFixture() ->type($fixture->start_time, 'start_time') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.create')) - ->seeInElement('.alert.alert-danger', 'There is already a match with the same number in this division.'); + ->seeInElement('.alert.alert-danger', 'There is already a match with the same number in this division.') + ->dontSeeInDatabase('fixtures', ['id' => 2]); + } + + public function testEditFixture() + { + $this->be($this->getFakeUser()); + + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + $fixtureId = $fixture->id; + + $newFixture = factory(Fixture::class)->make(); + + // Edit all details + $this->visit(route(self::BASE_ROUTE . '.edit', $fixtureId)) + ->select($newFixture->division_id, 'division_id') + ->select($newFixture->home_team_id, 'home_team_id') + ->select($newFixture->away_team_id, 'away_team_id') + ->select($newFixture->venue_id, 'venue_id') + ->type($newFixture->match_number, 'match_number') + ->type($newFixture->match_date, 'match_date') + ->type($newFixture->warm_up_time, 'warm_up_time') + ->type($newFixture->start_time, 'start_time') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Fixture updated!') + ->seeInDatabase('fixtures', [ + 'id' => $fixture->id, + 'division_id' => $newFixture->division_id, + 'home_team_id' => $newFixture->home_team_id, + 'away_team_id' => $newFixture->away_team_id, + 'venue_id' => $newFixture->venue_id, + 'match_number' => $newFixture->match_number, + 'match_date' => $newFixture->match_date->format('Y-m-d'), + 'warm_up_time' => $newFixture->warm_up_time, + 'start_time' => $newFixture->start_time, + ]); + $fixture = $newFixture; + + // Use the same team for home and away + $this->visit(route(self::BASE_ROUTE . '.edit', $fixtureId)) + ->select($fixture->home_team_id, 'home_team_id') + ->select($fixture->home_team_id, 'away_team_id') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.edit', $fixtureId)) + ->seeInElement('.alert.alert-danger', 'The away team cannot be the same as the home team.') + ->seeInDatabase('fixtures', [ + 'id' => $fixtureId, + 'home_team_id' => $fixture->home_team_id, + 'away_team_id' => $fixture->away_team_id, + ]); + + $newFixture = factory(Fixture::class)->create(); + + // Use the same division, home and away teams of an existing fixture + $this->visit(route(self::BASE_ROUTE . '.edit', $fixtureId)) + ->select($newFixture->division_id, 'division_id') + ->select($newFixture->home_team_id, 'home_team_id') + ->select($newFixture->away_team_id, 'away_team_id') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.edit', $fixtureId)) + ->seeInElement('.alert.alert-danger', 'The fixture for these two teams have already been added in this division.') + ->seeInDatabase('fixtures', [ + 'id' => $fixtureId, + 'division_id' => $fixture->division_id, + 'home_team_id' => $fixture->home_team_id, + 'away_team_id' => $fixture->away_team_id, + ]); + + // Use the same division and match number of an existing fixture + $this->visit(route(self::BASE_ROUTE . '.edit', $fixtureId)) + ->select($newFixture->division_id, 'division_id') + ->type($newFixture->match_number, 'match_number') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.edit', $fixtureId)) + ->seeInElement('.alert.alert-danger', 'There is already a match with the same number in this division.') + ->seeInDatabase('fixtures', [ + 'id' => $fixtureId, + 'division_id' => $fixture->division_id, + 'match_number' => $fixture->match_number, + ]); + } + + public function testShowFixture() + { + $this->be($this->getFakeUser()); + + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + $this->visit(route(self::BASE_ROUTE . '.show', $fixture->id)) + ->seeInElement('tbody tr td:nth-child(1)', $fixture->division->season) + ->seeInElement('tbody tr td:nth-child(2)', $fixture->division->division) + ->seeInElement('tbody tr td:nth-child(3)', $fixture->match_number) + ->seeInElement('tbody tr td:nth-child(4)', $fixture->match_date->format('j M Y')) + ->seeInElement('tbody tr td:nth-child(5)', $fixture->warm_up_time->format('H:i')) + ->seeInElement('tbody tr td:nth-child(6)', $fixture->start_time->format('H:i')) + ->seeInElement('tbody tr td:nth-child(7)', $fixture->home_team) + ->seeInElement('tbody tr td:nth-child(8)', $fixture->away_team) + ->seeInElement('tbody tr td:nth-child(9)', $fixture->venue); + } + + public function testDeleteFixture() + { + $this->be($this->getFakeUser()); + + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + $fixtureId = $fixture->id; + + $this->seeInDatabase('fixtures', [ + 'id' => $fixture->id, + 'division_id' => $fixture->division_id, + 'home_team_id' => $fixture->home_team_id, + 'away_team_id' => $fixture->away_team_id, + 'venue_id' => $fixture->venue_id, + 'match_number' => $fixture->match_number, + 'match_date' => $fixture->match_date->format('Y-m-d'), + 'warm_up_time' => $fixture->warm_up_time, + 'start_time' => $fixture->start_time, + ]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', $fixtureId)) + ->isRedirect(route(self::BASE_ROUTE . '.index')); + + $this->dontSeeInDatabase('fixtures', ['id' => $fixtureId]); } } From bdbf501806a845b5d4b85065a81e20727300b2e5 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sat, 14 May 2016 14:48:46 +0100 Subject: [PATCH 33/34] dev: tidy up the test for CRUD tables --- .../AvailableAppointmentsTableTest.php | 190 ++++++++---------- tests/Admin/DataManagement/ClubsTableTest.php | 79 +++++--- .../DataManagement/DivisionsTableTest.php | 137 +++++++------ .../DataManagement/FixturesTableTest.php | 31 +-- tests/Admin/DataManagement/RolesTableTest.php | 79 +++++--- .../Admin/DataManagement/SeasonsTableTest.php | 81 +++++--- tests/Admin/DataManagement/TeamsTableTest.php | 125 +++++++----- .../Admin/DataManagement/VenuesTableTest.php | 79 +++++--- tests/Admin/DataManagementTest.php | 27 +-- 9 files changed, 456 insertions(+), 372 deletions(-) diff --git a/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php b/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php index 97d3824b..4c8e665e 100644 --- a/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php +++ b/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php @@ -51,157 +51,149 @@ public function testAddAvailableAppointment() { $this->be($this->getFakeUser()); - /** @var AvailableAppointment $availableAppointment */ - $availableAppointment = factory(AvailableAppointment::class)->create(); - $availableAppointmentId = $availableAppointment->id; - $fixtureId = $availableAppointment->fixture_id; - $roleId = $availableAppointment->role_id; + /** @var AvailableAppointment $appointment */ + $appointment = factory(AvailableAppointment::class)->make(); - $otherFixtureId = factory(Fixture::class)->create()->id; - $otherRoleId = factory(Role::class)->create()->id; + /** @var Fixture $newFixture */ + $newFixture = factory(Fixture::class)->create(); + /** @var Role $newRole */ + $newRole = factory(Role::class)->create(); // Brand new appointment $this->visit(route(self::BASE_ROUTE . '.create')) - ->select($otherFixtureId, 'fixture_id') - ->select($otherRoleId, 'role_id') + ->select($appointment->fixture_id, 'fixture_id') + ->select($appointment->role_id, 'role_id') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Appointment added!') ->seeInDatabase('available_appointments', [ - 'id' => $availableAppointmentId + 1, - 'fixture_id' => $otherFixtureId, - 'role_id' => $otherRoleId, + 'id' => 1, + 'fixture_id' => $appointment->fixture_id, + 'role_id' => $appointment->role_id, ]); // Already existing appointment in the same fixture with different role $this->visit(route(self::BASE_ROUTE . '.create')) - ->select($fixtureId, 'fixture_id') - ->select($otherRoleId, 'role_id') + ->select($appointment->fixture_id, 'fixture_id') + ->select($newRole->id, 'role_id') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Appointment added!') ->seeInDatabase('available_appointments', [ - 'id' => $availableAppointmentId + 2, - 'fixture_id' => $fixtureId, - 'role_id' => $otherRoleId, + 'id' => 2, + 'fixture_id' => $appointment->fixture_id, + 'role_id' => $newRole->id, ]); // Already existing appointment in the same role with different fixture $this->visit(route(self::BASE_ROUTE . '.create')) - ->select($otherFixtureId, 'fixture_id') - ->select($roleId, 'role_id') + ->select($newFixture->id, 'fixture_id') + ->select($appointment->role_id, 'role_id') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Appointment added!') ->seeInDatabase('available_appointments', [ - 'id' => $availableAppointmentId + 3, - 'fixture_id' => $otherFixtureId, - 'role_id' => $roleId, + 'id' => 3, + 'fixture_id' => $newFixture->id, + 'role_id' => $appointment->role_id, ]); // Already existing appointment $this->visit(route(self::BASE_ROUTE . '.create')) - ->select($fixtureId, 'fixture_id') - ->select($roleId, 'role_id') + ->select($appointment->fixture_id, 'fixture_id') + ->select($appointment->role_id, 'role_id') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.create')) ->seeInElement('.alert.alert-danger', 'Appointment already added.') - ->seeInDatabase('available_appointments', [ - 'id' => $availableAppointmentId, - 'fixture_id' => $fixtureId, - 'role_id' => $roleId, - ]); + ->dontSeeInDatabase('available_appointments', ['id' => 4]); } public function testEditAvailableAppointment() { $this->be($this->getFakeUser()); - /** @var AvailableAppointment $availableAppointment */ - $availableAppointment = factory(AvailableAppointment::class)->create(); - $availableAppointmentId = $availableAppointment->id; - $fixtureId = $availableAppointment->fixture_id; - $roleId = $availableAppointment->role_id; + /** @var AvailableAppointment $appointment */ + $appointment = factory(AvailableAppointment::class)->create(); - $otherFixtureId = factory(Fixture::class)->create()->id; - $otherRoleId = factory(Role::class)->create()->id; + /** @var Fixture $newFixture */ + $newFixture = factory(Fixture::class)->create(); + /** @var Role $newRole */ + $newRole = factory(Role::class)->create(); // Change the role of the existing appointment $this->seeInDatabase('available_appointments', [ - 'id' => $availableAppointmentId, - 'fixture_id' => $fixtureId, - 'role_id' => $roleId, + 'id' => $appointment->id, + 'fixture_id' => $appointment->fixture_id, + 'role_id' => $appointment->role_id, ]) - ->visit(route(self::BASE_ROUTE . '.edit', [$availableAppointmentId])) - ->select($otherRoleId, 'role_id') + ->visit(route(self::BASE_ROUTE . '.edit', [$appointment->id])) + ->select($newRole->id, 'role_id') ->press('Update') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Appointment updated!') ->seeInDatabase('available_appointments', [ - 'id' => $availableAppointmentId, - 'fixture_id' => $fixtureId, - 'role_id' => $otherRoleId, + 'id' => $appointment->id, + 'fixture_id' => $appointment->fixture_id, + 'role_id' => $newRole->id, ]); - $roleId = $otherRoleId; + $appointment->role_id = $newRole->id; // Change the fixture of the existing appointment $this->seeInDatabase('available_appointments', [ - 'id' => $availableAppointmentId, - 'fixture_id' => $fixtureId, - 'role_id' => $roleId, + 'id' => $appointment->id, + 'fixture_id' => $appointment->fixture_id, + 'role_id' => $appointment->role_id, ]) - ->visit(route(self::BASE_ROUTE . '.edit', [$availableAppointmentId])) - ->select($otherFixtureId, 'fixture_id') + ->visit(route(self::BASE_ROUTE . '.edit', [$appointment->id])) + ->select($newFixture->id, 'fixture_id') ->press('Update') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Appointment updated!') ->seeInDatabase('available_appointments', [ - 'id' => $availableAppointmentId, - 'fixture_id' => $otherFixtureId, - 'role_id' => $roleId, + 'id' => $appointment->id, + 'fixture_id' => $newFixture->id, + 'role_id' => $appointment->role_id, ]); - $fixtureId = $otherFixtureId; + $appointment->fixture_id = $newFixture->id; // Already existing availableAppointment in the same fixture - /** @var AvailableAppointment $anotherAvailableAppointment */ - $anotherAvailableAppointment = factory(AvailableAppointment::class)->create(['fixture_id' => $fixtureId]); - $anotherAvailableAppointmentRoleId = $anotherAvailableAppointment->role_id; + /** @var AvailableAppointment $newAppointment */ + $newAppointment = factory(AvailableAppointment::class)->create(['fixture_id' => $appointment->fixture_id]); $this->seeInDatabase('available_appointments', [ - 'id' => $availableAppointmentId, - 'fixture_id' => $fixtureId, - 'role_id' => $roleId, + 'id' => $appointment->id, + 'fixture_id' => $appointment->fixture_id, + 'role_id' => $appointment->role_id, ]) - ->visit(route(self::BASE_ROUTE . '.edit', [$availableAppointmentId])) - ->select($anotherAvailableAppointmentRoleId, 'role_id') + ->visit(route(self::BASE_ROUTE . '.edit', [$appointment->id])) + ->select($newAppointment->role_id, 'role_id') ->press('Update') - ->seePageIs(route(self::BASE_ROUTE . '.edit', [$availableAppointmentId])) + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$appointment->id])) ->seeInElement('.alert.alert-danger', 'Appointment already added.') ->seeInDatabase('available_appointments', [ - 'id' => $availableAppointmentId, - 'fixture_id' => $fixtureId, - 'role_id' => $roleId, + 'id' => $appointment->id, + 'fixture_id' => $appointment->fixture_id, + 'role_id' => $appointment->role_id, ]); // Already existing availableAppointment in the same role - /** @var AvailableAppointment $yetAnotherAvailableAppointment */ - $yetAnotherAvailableAppointment = factory(AvailableAppointment::class)->create(['role_id' => $roleId]); - $yetAnotherAvailableAppointmentFixtureId = $yetAnotherAvailableAppointment->fixture_id; + /** @var AvailableAppointment $anotherAppointment */ + $anotherAppointment = factory(AvailableAppointment::class)->create(['role_id' => $appointment->role_id]); $this->seeInDatabase('available_appointments', [ - 'id' => $availableAppointmentId, - 'fixture_id' => $fixtureId, - 'role_id' => $roleId, + 'id' => $appointment->id, + 'fixture_id' => $appointment->fixture_id, + 'role_id' => $appointment->role_id, ]) - ->visit(route(self::BASE_ROUTE . '.edit', [$availableAppointmentId])) - ->select($yetAnotherAvailableAppointmentFixtureId, 'fixture_id') + ->visit(route(self::BASE_ROUTE . '.edit', [$appointment->id])) + ->select($anotherAppointment->fixture_id, 'fixture_id') ->press('Update') - ->seePageIs(route(self::BASE_ROUTE . '.edit', [$availableAppointmentId])) + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$appointment->id])) ->seeInElement('.alert.alert-danger', 'Appointment already added.') ->seeInDatabase('available_appointments', [ - 'id' => $availableAppointmentId, - 'fixture_id' => $fixtureId, - 'role_id' => $roleId, + 'id' => $appointment->id, + 'fixture_id' => $appointment->fixture_id, + 'role_id' => $appointment->role_id, ]); } @@ -209,43 +201,31 @@ public function testShowAvailableAppointment() { $this->be($this->getFakeUser()); - /** @var AvailableAppointment $availableAppointment */ - $availableAppointment = factory(AvailableAppointment::class)->create(); - $availableAppointmentId = $availableAppointment->id; - $fixtureId = $availableAppointment->fixture_id; - $roleId = $availableAppointment->role_id; - - /** @var Fixture $fixture */ - $fixture = Fixture::find($fixtureId); - $fixtureName = $fixture->fixture; + /** @var AvailableAppointment $appointment */ + $appointment = factory(AvailableAppointment::class)->create(); - /** @var Role $role */ - $role = Role::find($roleId); - $roleName = $role->role; - - $this->visit(route(self::BASE_ROUTE . '.show', [$availableAppointmentId])) - ->seeInElement('tbody tr td:nth-child(1)', $availableAppointmentId) - ->seeInElement('tbody tr td:nth-child(2)', $fixtureName) - ->seeInElement('tbody tr td:nth-child(3)', $roleName); + $this->visit(route(self::BASE_ROUTE . '.show', [$appointment->id])) + ->seeInElement('tbody tr td:nth-child(1)', $appointment->id) + ->seeInElement('tbody tr td:nth-child(2)', $appointment->fixture) + ->seeInElement('tbody tr td:nth-child(3)', $appointment->role); } public function testDeleteAvailableAppointment() { $this->be($this->getFakeUser()); - /** @var AvailableAppointment $availableAppointment */ - $availableAppointment = factory(AvailableAppointment::class)->create(); - $availableAppointmentId = $availableAppointment->id; - $fixtureId = $availableAppointment->fixture_id; - $roleId = $availableAppointment->role_id; + /** @var AvailableAppointment $appointment */ + $appointment = factory(AvailableAppointment::class)->create(); + $appointmentId = $appointment->id; $this->seeInDatabase('available_appointments', [ - 'id' => $availableAppointmentId, - 'fixture_id' => $fixtureId, - 'role_id' => $roleId]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$availableAppointmentId])) + 'id' => $appointment->id, + 'fixture_id' => $appointment->fixture_id, + 'role_id' => $appointment->role_id, + ]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$appointment->id])) ->isRedirect(route(self::BASE_ROUTE . '.index')); - $this->dontSeeInDatabase('available_appointments', ['id' => $availableAppointmentId]); + $this->dontSeeInDatabase('available_appointments', ['id' => $appointmentId]); } } diff --git a/tests/Admin/DataManagement/ClubsTableTest.php b/tests/Admin/DataManagement/ClubsTableTest.php index b08df1d5..dbe9fe81 100644 --- a/tests/Admin/DataManagement/ClubsTableTest.php +++ b/tests/Admin/DataManagement/ClubsTableTest.php @@ -50,26 +50,29 @@ public function testAddClub() $this->be($this->getFakeUser()); /** @var Club $club */ - $club = factory(Club::class)->create(); - $clubId = $club->id; - $clubName = $club->club; + $club = factory(Club::class)->make(); // Brand new club - $newClubName = 'New ' . $clubName; $this->visit(route(self::BASE_ROUTE . '.create')) - ->type($newClubName, 'club') + ->type($club->club, 'club') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Club added!') - ->seeInDatabase('clubs', ['id' => $clubId + 1, 'club' => $newClubName]); + ->seeInDatabase('clubs', [ + 'id' => 1, + 'club' => $club->club, + ]); // Already existing club $this->visit(route(self::BASE_ROUTE . '.create')) - ->type($clubName, 'club') + ->type($club->club, 'club') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.create')) ->seeInElement('.alert.alert-danger', 'The club already exists.') - ->seeInDatabase('clubs', ['id' => $clubId, 'club' => $clubName]); + ->seeInDatabase('clubs', [ + 'id' => 1, + 'club' => $club->club, + ]); } public function testEditClub() @@ -78,30 +81,43 @@ public function testEditClub() /** @var Club $club */ $club = factory(Club::class)->create(); - $clubId = $club->id; - $clubName = $club->club; - $newClubName = 'New ' . $clubName; - $this->seeInDatabase('clubs', ['id' => $clubId, 'club' => $clubName]) - ->visit(route(self::BASE_ROUTE . '.edit', [$clubId])) - ->type($newClubName, 'club') + /** @var Club $newClub */ + $newClub = factory(Club::class)->make(); + + $this->seeInDatabase('clubs', [ + 'id' => $club->id, + 'club' => $club->club, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$club->id])) + ->type($newClub->club, 'club') ->press('Update') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Club updated!') - ->seeInDatabase('clubs', ['id' => $clubId, 'club' => $newClubName]); - $clubName = $newClubName; + ->seeInDatabase('clubs', [ + 'id' => $club->id, + 'club' => $newClub->club, + ]); + $club->club = $newClub->club; + unset($newClub); - $anotherClub = factory(Club::class)->create(); - $anotherClubName = $anotherClub->club; + /** @var Club $newClub */ + $newClub = factory(Club::class)->create(); // Already existing club - $this->seeInDatabase('clubs', ['id' => $clubId, 'club' => $clubName]) - ->visit(route(self::BASE_ROUTE . '.edit', [$clubId])) - ->type($anotherClubName, 'club') + $this->seeInDatabase('clubs', [ + 'id' => $club->id, + 'club' => $club->club, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$club->id])) + ->type($newClub->club, 'club') ->press('Update') - ->seePageIs(route(self::BASE_ROUTE . '.edit', [$clubId])) + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$club->id])) ->seeInElement('.alert.alert-danger', 'The club already exists.') - ->seeInDatabase('clubs', ['id' => $clubId, 'club' => $clubName]); + ->seeInDatabase('clubs', [ + 'id' => $club->id, + 'club' => $club->club, + ]); } public function testShowClub() @@ -110,12 +126,10 @@ public function testShowClub() /** @var Club $club */ $club = factory(Club::class)->create(); - $clubId = $club->id; - $clubName = $club->club; - $this->visit(route(self::BASE_ROUTE . '.show', [$clubId])) - ->seeInElement('tbody tr td:nth-child(1)', $clubId) - ->seeInElement('tbody tr td:nth-child(2)', $clubName); + $this->visit(route(self::BASE_ROUTE . '.show', [$club->id])) + ->seeInElement('tbody tr td:nth-child(1)', $club->id) + ->seeInElement('tbody tr td:nth-child(2)', $club->club); } public function testDeleteClub() @@ -125,11 +139,14 @@ public function testDeleteClub() /** @var Club $club */ $club = factory(Club::class)->create(); $clubId = $club->id; - $clubName = $club->club; - $this->seeInDatabase('clubs', ['id' => $clubId, 'club' => $clubName]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$clubId])) + $this->seeInDatabase('clubs', [ + 'id' => $club->id, + 'club' => $club->club, + ]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$club->id])) ->isRedirect(route(self::BASE_ROUTE . '.index')); + $this->dontSeeInDatabase('clubs', ['id' => $clubId]); } } diff --git a/tests/Admin/DataManagement/DivisionsTableTest.php b/tests/Admin/DataManagement/DivisionsTableTest.php index b8859d96..32696499 100644 --- a/tests/Admin/DataManagement/DivisionsTableTest.php +++ b/tests/Admin/DataManagement/DivisionsTableTest.php @@ -8,9 +8,9 @@ namespace Admin\DataManagement; +use Tests\TestCase; use App\Models\Division; use App\Models\Season; -use Tests\TestCase; class DivisionsTableTest extends TestCase { @@ -51,29 +51,33 @@ public function testAddDivision() $this->be($this->getFakeUser()); /** @var Division $division */ - $division = factory(Division::class)->create(); - $divisionId = $division->id; - $seasonId = $division->season_id; - $divisionName = $division->division; + $division = factory(Division::class)->make(); // Brand new division - $newDivisionName = 'New ' . $divisionName; $this->visit(route(self::BASE_ROUTE . '.create')) - ->select($seasonId, 'season_id') - ->type($newDivisionName, 'division') + ->select($division->season_id, 'season_id') + ->type($division->division, 'division') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Division added!') - ->seeInDatabase('divisions', ['id' => $divisionId + 1, 'season_id' => $seasonId, 'division' => $newDivisionName]); + ->seeInDatabase('divisions', [ + 'id' => 1, + 'season_id' => $division->season_id, + 'division' => $division->division, + ]); // Already existing division in the same season $this->visit(route(self::BASE_ROUTE . '.create')) - ->select($seasonId, 'season_id') - ->type($divisionName, 'division') + ->select($division->season_id, 'season_id') + ->type($division->division, 'division') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.create')) ->seeInElement('.alert.alert-danger', 'The division already exists in the same season.') - ->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $seasonId, 'division' => $divisionName]); + ->seeInDatabase('divisions', [ + 'id' => 1, + 'season_id' => $division->season_id, + 'division' => $division->division, + ]); } public function testEditDivision() @@ -82,46 +86,69 @@ public function testEditDivision() /** @var Division $division */ $division = factory(Division::class)->create(); - $divisionId = $division->id; - $seasonId = $division->season_id; - $divisionName = $division->division; + + /** @var Division $newDivision */ + $newDivision = factory(Division::class)->make(); // Change the name of the division - $newDivisionName = 'New ' . $divisionName; - $this->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $seasonId, 'division' => $divisionName]) - ->visit(route(self::BASE_ROUTE . '.edit', [$divisionId])) - ->type($newDivisionName, 'division') + $this->seeInDatabase('divisions', [ + 'id' => $division->id, + 'season_id' => $division->season_id, + 'division' => $division->division, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$division->id])) + ->type($newDivision->division, 'division') ->press('Update') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Division updated!') - ->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $seasonId, 'division' => $newDivisionName]); - $divisionName = $newDivisionName; - - // Already existing division in the same season - /** @var Division $anotherDivision */ - $anotherDivision = factory(Division::class)->create(['season_id' => $seasonId]); - $anotherDivisionName = $anotherDivision->division; - - $this->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $seasonId, 'division' => $divisionName]) - ->visit(route(self::BASE_ROUTE . '.edit', [$divisionId])) - ->type($anotherDivisionName, 'division') - ->press('Update') - ->seePageIs(route(self::BASE_ROUTE . '.edit', [$divisionId])) - ->seeInElement('.alert.alert-danger', 'The division already exists in the same season.') - ->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $seasonId, 'division' => $divisionName]); + ->seeInDatabase('divisions', [ + 'id' => $division->id, + 'season_id' => $division->season_id, + 'division' => $newDivision->division, + ]); + $division->division = $newDivision->division; + unset($newDivision); // Move division to a different season - $anotherSeason = factory(Season::class)->create(); - $anotherSeasonId = $anotherSeason->id; - - $this->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $seasonId, 'division' => $divisionName]) - ->visit(route(self::BASE_ROUTE . '.edit', [$divisionId])) - ->select($anotherSeasonId, 'season_id') - ->type($divisionName, 'division') + $season = factory(Season::class)->create(); + + $this->seeInDatabase('divisions', [ + 'id' => $division->id, + 'season_id' => $division->season_id, + 'division' => $division->division, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$division->id])) + ->select($season->id, 'season_id') ->press('Update') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Division updated!') - ->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $anotherSeasonId, 'division' => $newDivisionName]); + ->seeInDatabase('divisions', [ + 'id' => $division->id, + 'season_id' => $season->id, + 'division' => $division->division, + ]); + $division->season_id = $season->id; + unset($season); + + // Already existing division in the same season + /** @var Division $newDivision */ + $newDivision = factory(Division::class)->create(['season_id' => $division->season_id]); + + $this->seeInDatabase('divisions', [ + 'id' => $division->id, + 'season_id' => $division->season_id, + 'division' => $division->division, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$division->id])) + ->type($newDivision->division, 'division') + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$division->id])) + ->seeInElement('.alert.alert-danger', 'The division already exists in the same season.') + ->seeInDatabase('divisions', [ + 'id' => $division->id, + 'season_id' => $division->season_id, + 'division' => $division->division, + ]); } public function testShowDivision() @@ -130,18 +157,11 @@ public function testShowDivision() /** @var Division $division */ $division = factory(Division::class)->create(); - $divisionId = $division->id; - $seasonId = $division->season_id; - $divisionName = $division->division; - /** @var Season $season */ - $season = Season::find($seasonId); - $seasonName = $season->season; - - $this->visit(route(self::BASE_ROUTE . '.show', [$divisionId])) - ->seeInElement('tbody tr td:nth-child(1)', $divisionId) - ->seeInElement('tbody tr td:nth-child(2)', $seasonName) - ->seeInElement('tbody tr td:nth-child(3)', $divisionName); + $this->visit(route(self::BASE_ROUTE . '.show', [$division->id])) + ->seeInElement('tbody tr td:nth-child(1)', $division->id) + ->seeInElement('tbody tr td:nth-child(2)', $division->season) + ->seeInElement('tbody tr td:nth-child(3)', $division->division); } public function testDeleteDivision() @@ -151,12 +171,15 @@ public function testDeleteDivision() /** @var Division $division */ $division = factory(Division::class)->create(); $divisionId = $division->id; - $seasonId = $division->season_id; - $divisionName = $division->division; - $this->seeInDatabase('divisions', ['id' => $divisionId, 'season_id' => $seasonId, 'division' => $divisionName]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$divisionId])) + $this->seeInDatabase('divisions', [ + 'id' => $division->id, + 'season_id' => $division->season_id, + 'division' => $division->division, + ]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$division->id])) ->isRedirect(route(self::BASE_ROUTE . '.index')); + $this->dontSeeInDatabase('divisions', ['id' => $divisionId]); } } diff --git a/tests/Admin/DataManagement/FixturesTableTest.php b/tests/Admin/DataManagement/FixturesTableTest.php index 9411b555..a4ab2a4f 100644 --- a/tests/Admin/DataManagement/FixturesTableTest.php +++ b/tests/Admin/DataManagement/FixturesTableTest.php @@ -8,7 +8,6 @@ namespace Admin\DataManagement; -use Faker\Generator; use Tests\TestCase; use App\Models\Fixture; @@ -130,12 +129,12 @@ public function testEditFixture() /** @var Fixture $fixture */ $fixture = factory(Fixture::class)->create(); - $fixtureId = $fixture->id; - $newFixture = factory(Fixture::class)->make(); + /** @var Fixture $newFixture */ + $newFixture = factory(Fixture::class)->make(['id' => $fixture->id]); // Edit all details - $this->visit(route(self::BASE_ROUTE . '.edit', $fixtureId)) + $this->visit(route(self::BASE_ROUTE . '.edit', [$fixture->id])) ->select($newFixture->division_id, 'division_id') ->select($newFixture->home_team_id, 'home_team_id') ->select($newFixture->away_team_id, 'away_team_id') @@ -159,46 +158,48 @@ public function testEditFixture() 'start_time' => $newFixture->start_time, ]); $fixture = $newFixture; + unset($newFixture); // Use the same team for home and away - $this->visit(route(self::BASE_ROUTE . '.edit', $fixtureId)) + $this->visit(route(self::BASE_ROUTE . '.edit', [$fixture->id])) ->select($fixture->home_team_id, 'home_team_id') ->select($fixture->home_team_id, 'away_team_id') ->press('Update') - ->seePageIs(route(self::BASE_ROUTE . '.edit', $fixtureId)) + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$fixture->id])) ->seeInElement('.alert.alert-danger', 'The away team cannot be the same as the home team.') ->seeInDatabase('fixtures', [ - 'id' => $fixtureId, + 'id' => $fixture->id, 'home_team_id' => $fixture->home_team_id, 'away_team_id' => $fixture->away_team_id, ]); + /** @var Fixture $newFixture */ $newFixture = factory(Fixture::class)->create(); // Use the same division, home and away teams of an existing fixture - $this->visit(route(self::BASE_ROUTE . '.edit', $fixtureId)) + $this->visit(route(self::BASE_ROUTE . '.edit', [$fixture->id])) ->select($newFixture->division_id, 'division_id') ->select($newFixture->home_team_id, 'home_team_id') ->select($newFixture->away_team_id, 'away_team_id') ->press('Update') - ->seePageIs(route(self::BASE_ROUTE . '.edit', $fixtureId)) + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$fixture->id])) ->seeInElement('.alert.alert-danger', 'The fixture for these two teams have already been added in this division.') ->seeInDatabase('fixtures', [ - 'id' => $fixtureId, + 'id' => $fixture->id, 'division_id' => $fixture->division_id, 'home_team_id' => $fixture->home_team_id, 'away_team_id' => $fixture->away_team_id, ]); // Use the same division and match number of an existing fixture - $this->visit(route(self::BASE_ROUTE . '.edit', $fixtureId)) + $this->visit(route(self::BASE_ROUTE . '.edit', [$fixture->id])) ->select($newFixture->division_id, 'division_id') ->type($newFixture->match_number, 'match_number') ->press('Update') - ->seePageIs(route(self::BASE_ROUTE . '.edit', $fixtureId)) + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$fixture->id])) ->seeInElement('.alert.alert-danger', 'There is already a match with the same number in this division.') ->seeInDatabase('fixtures', [ - 'id' => $fixtureId, + 'id' => $fixture->id, 'division_id' => $fixture->division_id, 'match_number' => $fixture->match_number, ]); @@ -211,7 +212,7 @@ public function testShowFixture() /** @var Fixture $fixture */ $fixture = factory(Fixture::class)->create(); - $this->visit(route(self::BASE_ROUTE . '.show', $fixture->id)) + $this->visit(route(self::BASE_ROUTE . '.show', [$fixture->id])) ->seeInElement('tbody tr td:nth-child(1)', $fixture->division->season) ->seeInElement('tbody tr td:nth-child(2)', $fixture->division->division) ->seeInElement('tbody tr td:nth-child(3)', $fixture->match_number) @@ -242,7 +243,7 @@ public function testDeleteFixture() 'warm_up_time' => $fixture->warm_up_time, 'start_time' => $fixture->start_time, ]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', $fixtureId)) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$fixture->id])) ->isRedirect(route(self::BASE_ROUTE . '.index')); $this->dontSeeInDatabase('fixtures', ['id' => $fixtureId]); diff --git a/tests/Admin/DataManagement/RolesTableTest.php b/tests/Admin/DataManagement/RolesTableTest.php index 27267ca1..ea705dfc 100644 --- a/tests/Admin/DataManagement/RolesTableTest.php +++ b/tests/Admin/DataManagement/RolesTableTest.php @@ -50,26 +50,29 @@ public function testAddRole() $this->be($this->getFakeUser()); /** @var Role $role */ - $role = factory(Role::class)->create(); - $roleId = $role->id; - $roleName = $role->role; + $role = factory(Role::class)->make(); // Brand new role - $newRoleName = 'New ' . $roleName; $this->visit(route(self::BASE_ROUTE . '.create')) - ->type($newRoleName, 'role') + ->type($role->role, 'role') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Role added!') - ->seeInDatabase('roles', ['id' => $roleId + 1, 'role' => $newRoleName]); + ->seeInDatabase('roles', [ + 'id' => 1, + 'role' => $role->role, + ]); // Already existing role $this->visit(route(self::BASE_ROUTE . '.create')) - ->type($roleName, 'role') + ->type($role->role, 'role') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.create')) ->seeInElement('.alert.alert-danger', 'The role already exists.') - ->seeInDatabase('roles', ['id' => $roleId, 'role' => $roleName]); + ->seeInDatabase('roles', [ + 'id' => 1, + 'role' => $role->role, + ]); } public function testEditRole() @@ -78,30 +81,43 @@ public function testEditRole() /** @var Role $role */ $role = factory(Role::class)->create(); - $roleId = $role->id; - $roleName = $role->role; - $newRoleName = 'New ' . $roleName; - $this->seeInDatabase('roles', ['id' => $roleId, 'role' => $roleName]) - ->visit(route(self::BASE_ROUTE . '.edit', [$roleId])) - ->type($newRoleName, 'role') + /** @var Role $newRole */ + $newRole = factory(Role::class)->make(); + + + $this->seeInDatabase('roles', [ + 'id' => 1, + 'role' => $role->role, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$role->id])) + ->type($newRole->role, 'role') ->press('Update') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Role updated!') - ->seeInDatabase('roles', ['id' => $roleId, 'role' => $newRoleName]); - $roleName = $newRoleName; + ->seeInDatabase('roles', [ + 'id' => 1, + 'role' => $newRole->role, + ]); + $role->role = $newRole->role; + unset($newRole); - $anotherRole = factory(Role::class)->create(); - $anotherRoleName = $anotherRole->role; + /** @var Role $newRole */ + $newRole = factory(Role::class)->create(); // Already existing role - $this->seeInDatabase('roles', ['id' => $roleId, 'role' => $roleName]) - ->visit(route(self::BASE_ROUTE . '.edit', [$roleId])) - ->type($anotherRoleName, 'role') + $this->seeInDatabase('roles', [ + 'id' => $role->id, + 'role' => $role->role, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$role->id])) + ->type($newRole->role, 'role') ->press('Update') - ->seePageIs(route(self::BASE_ROUTE . '.edit', [$roleId])) + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$role->id])) ->seeInElement('.alert.alert-danger', 'The role already exists.') - ->seeInDatabase('roles', ['id' => $roleId, 'role' => $roleName]); + ->seeInDatabase('roles', [ + 'id' => $role->id, + 'role' => $role->role]); } public function testShowRole() @@ -110,12 +126,10 @@ public function testShowRole() /** @var Role $role */ $role = factory(Role::class)->create(); - $roleId = $role->id; - $roleName = $role->role; - $this->visit(route(self::BASE_ROUTE . '.show', [$roleId])) - ->seeInElement('tbody tr td:nth-child(1)', $roleId) - ->seeInElement('tbody tr td:nth-child(2)', $roleName); + $this->visit(route(self::BASE_ROUTE . '.show', [$role->id])) + ->seeInElement('tbody tr td:nth-child(1)', $role->id) + ->seeInElement('tbody tr td:nth-child(2)', $role->role); } public function testDeleteRole() @@ -125,11 +139,14 @@ public function testDeleteRole() /** @var Role $role */ $role = factory(Role::class)->create(); $roleId = $role->id; - $roleName = $role->role; - $this->seeInDatabase('roles', ['id' => $roleId, 'role' => $roleName]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$roleId])) + $this->seeInDatabase('roles', [ + 'id' => $role->id, + 'role' => $role->role, + ]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$role->id])) ->isRedirect(route(self::BASE_ROUTE . '.index')); + $this->dontSeeInDatabase('roles', ['id' => $roleId]); } } diff --git a/tests/Admin/DataManagement/SeasonsTableTest.php b/tests/Admin/DataManagement/SeasonsTableTest.php index 00db8a6c..a003026b 100644 --- a/tests/Admin/DataManagement/SeasonsTableTest.php +++ b/tests/Admin/DataManagement/SeasonsTableTest.php @@ -8,8 +8,8 @@ namespace Admin\DataManagement; -use App\Models\Season; use Tests\TestCase; +use App\Models\Season; class SeasonsTableTest extends TestCase { @@ -50,26 +50,29 @@ public function testAddSeason() $this->be($this->getFakeUser()); /** @var Season $season */ - $season = factory(Season::class)->create(); - $seasonId = $season->id; - $seasonName = $season->season; + $season = factory(Season::class)->make(); // Brand new season - $newSeasonName = 'New ' . $seasonName; $this->visit(route(self::BASE_ROUTE . '.create')) - ->type($newSeasonName, 'season') + ->type($season->season, 'season') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Season added!') - ->seeInDatabase('seasons', ['id' => $seasonId + 1, 'season' => $newSeasonName]); + ->seeInDatabase('seasons', [ + 'id' => 1, + 'season' => $season->season, + ]); // Already existing season $this->visit(route(self::BASE_ROUTE . '.create')) - ->type($seasonName, 'season') + ->type($season->season, 'season') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.create')) ->seeInElement('.alert.alert-danger', 'The season already exists.') - ->seeInDatabase('seasons', ['id' => $seasonId, 'season' => $seasonName]); + ->seeInDatabase('seasons', [ + 'id' => 1, + 'season' => $season->season, + ]); } public function testEditSeason() @@ -78,30 +81,43 @@ public function testEditSeason() /** @var Season $season */ $season = factory(Season::class)->create(); - $seasonId = $season->id; - $seasonName = $season->season; - $newSeasonName = 'New ' . $seasonName; - $this->seeInDatabase('seasons', ['id' => $seasonId, 'season' => $seasonName]) - ->visit(route(self::BASE_ROUTE . '.edit', [$seasonId])) - ->type($newSeasonName, 'season') + /** @var Season $newSeason */ + $newSeason = factory(Season::class)->make(); + + $this->seeInDatabase('seasons', [ + 'id' => $season->id, + 'season' => $season->season, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$season->id])) + ->type($newSeason->season, 'season') ->press('Update') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Season updated!') - ->seeInDatabase('seasons', ['id' => $seasonId, 'season' => $newSeasonName]); - $seasonName = $newSeasonName; + ->seeInDatabase('seasons', [ + 'id' => $season->id, + 'season' => $newSeason->season, + ]); + $season->season = $newSeason->season; + unset($newSeason); - $anotherSeason = factory(Season::class)->create(); - $anotherSeasonName = $anotherSeason->season; + /** @var Season $newSeason */ + $newSeason = factory(Season::class)->create(); // Already existing season - $this->seeInDatabase('seasons', ['id' => $seasonId, 'season' => $seasonName]) - ->visit(route(self::BASE_ROUTE . '.edit', [$seasonId])) - ->type($anotherSeasonName, 'season') + $this->seeInDatabase('seasons', [ + 'id' => $season->id, + 'season' => $season->season, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$season->id])) + ->type($newSeason->season, 'season') ->press('Update') - ->seePageIs(route(self::BASE_ROUTE . '.edit', [$seasonId])) + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$season->id])) ->seeInElement('.alert.alert-danger', 'The season already exists.') - ->seeInDatabase('seasons', ['id' => $seasonId, 'season' => $seasonName]); + ->seeInDatabase('seasons', [ + 'id' => $season->id, + 'season' => $season->season, + ]); } public function testShowSeason() @@ -110,12 +126,10 @@ public function testShowSeason() /** @var Season $season */ $season = factory(Season::class)->create(); - $seasonId = $season->id; - $seasonName = $season->season; - $this->visit(route(self::BASE_ROUTE . '.show', [$seasonId])) - ->seeInElement('tbody tr td:nth-child(1)', $seasonId) - ->seeInElement('tbody tr td:nth-child(2)', $seasonName); + $this->visit(route(self::BASE_ROUTE . '.show', [$season->id])) + ->seeInElement('tbody tr td:nth-child(1)', $season->id) + ->seeInElement('tbody tr td:nth-child(2)', $season->season); } public function testDeleteSeason() @@ -125,11 +139,14 @@ public function testDeleteSeason() /** @var Season $season */ $season = factory(Season::class)->create(); $seasonId = $season->id; - $seasonName = $season->season; - $this->seeInDatabase('seasons', ['id' => $seasonId, 'season' => $seasonName]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$seasonId])) + $this->seeInDatabase('seasons', [ + 'id' => $season->id, + 'season' => $season->season, + ]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$season->id])) ->isRedirect(route(self::BASE_ROUTE . '.index')); + $this->dontSeeInDatabase('seasons', ['id' => $seasonId]); } } diff --git a/tests/Admin/DataManagement/TeamsTableTest.php b/tests/Admin/DataManagement/TeamsTableTest.php index 2dec3a38..20cf835d 100644 --- a/tests/Admin/DataManagement/TeamsTableTest.php +++ b/tests/Admin/DataManagement/TeamsTableTest.php @@ -51,29 +51,33 @@ public function testAddTeam() $this->be($this->getFakeUser()); /** @var Team $team */ - $team = factory(Team::class)->create(); - $teamId = $team->id; - $clubId = $team->club_id; - $teamName = $team->team; + $team = factory(Team::class)->make(); // Brand new team - $newTeamName = 'New ' . $teamName; $this->visit(route(self::BASE_ROUTE . '.create')) - ->select($clubId, 'club_id') - ->type($newTeamName, 'team') + ->select($team->club_id, 'club_id') + ->type($team->team, 'team') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Team added!') - ->seeInDatabase('teams', ['id' => $teamId + 1, 'club_id' => $clubId, 'team' => $newTeamName]); + ->seeInDatabase('teams', [ + 'id' => 1, + 'club_id' => $team->club_id, + 'team' => $team->team, + ]); // Already existing team in the same club $this->visit(route(self::BASE_ROUTE . '.create')) - ->select($clubId, 'club_id') - ->type($teamName, 'team') + ->select($team->club_id, 'club_id') + ->type($team->team, 'team') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.create')) ->seeInElement('.alert.alert-danger', 'The team already exists in the same club.') - ->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $clubId, 'team' => $teamName]); + ->seeInDatabase('teams', [ + 'id' => 1, + 'club_id' => $team->club_id, + 'team' => $team->team, + ]); } public function testEditTeam() @@ -82,46 +86,67 @@ public function testEditTeam() /** @var Team $team */ $team = factory(Team::class)->create(); - $teamId = $team->id; - $clubId = $team->club_id; - $teamName = $team->team; + + /** @var Team $newTeam */ + $newTeam = factory(Team::class)->make(); // Change the name of the team - $newTeamName = 'New ' . $teamName; - $this->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $clubId, 'team' => $teamName]) - ->visit(route(self::BASE_ROUTE . '.edit', [$teamId])) - ->type($newTeamName, 'team') + $this->seeInDatabase('teams', [ + 'id' => $team->id, + 'club_id' => $team->club_id, + 'team' => $team->team, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$team->id])) + ->type($newTeam->team, 'team') ->press('Update') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Team updated!') - ->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $clubId, 'team' => $newTeamName]); - $teamName = $newTeamName; + ->seeInDatabase('teams', [ + 'id' => $team->id, + 'club_id' => $team->club_id, + 'team' => $newTeam->team, + ]); + $team->team = $newTeam->team; + unset($newTeam); // Already existing team in the same club - /** @var Team $anotherTeam */ - $anotherTeam = factory(Team::class)->create(['club_id' => $clubId]); - $anotherTeamName = $anotherTeam->team; - - $this->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $clubId, 'team' => $teamName]) - ->visit(route(self::BASE_ROUTE . '.edit', [$teamId])) - ->type($anotherTeamName, 'team') + /** @var Team $newTeam */ + $newTeam = factory(Team::class)->create(['club_id' => $team->club_id]); + + $this->seeInDatabase('teams', [ + 'id' => $team->id, + 'club_id' => $team->club_id, + 'team' => $team->team, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$team->id])) + ->type($newTeam->team, 'team') ->press('Update') - ->seePageIs(route(self::BASE_ROUTE . '.edit', [$teamId])) + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$team->id])) ->seeInElement('.alert.alert-danger', 'The team already exists in the same club.') - ->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $clubId, 'team' => $teamName]); + ->seeInDatabase('teams', [ + 'id' => $team->id, + 'club_id' => $team->club_id, + 'team' => $team->team, + ]); // Move team to a different club - $anotherClub = factory(Club::class)->create(); - $anotherClubId = $anotherClub->id; - - $this->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $clubId, 'team' => $teamName]) - ->visit(route(self::BASE_ROUTE . '.edit', [$teamId])) - ->select($anotherClubId, 'club_id') - ->type($teamName, 'team') + $club = factory(Club::class)->create(); + + $this->seeInDatabase('teams', [ + 'id' => $team->id, + 'club_id' => $team->club_id, + 'team' => $team->team, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$team->id])) + ->select($club->id, 'club_id') ->press('Update') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Team updated!') - ->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $anotherClubId, 'team' => $newTeamName]); + ->seeInDatabase('teams', [ + 'id' => $team->id, + 'club_id' => $club->id, + 'team' => $team->team, + ]); } public function testShowTeam() @@ -130,18 +155,11 @@ public function testShowTeam() /** @var Team $team */ $team = factory(Team::class)->create(); - $teamId = $team->id; - $clubId = $team->club_id; - $teamName = $team->team; - - /** @var Club $club */ - $club = Club::find($clubId); - $clubName = $club->club; - $this->visit(route(self::BASE_ROUTE . '.show', [$teamId])) - ->seeInElement('tbody tr td:nth-child(1)', $teamId) - ->seeInElement('tbody tr td:nth-child(2)', $clubName) - ->seeInElement('tbody tr td:nth-child(3)', $teamName); + $this->visit(route(self::BASE_ROUTE . '.show', [$team->id])) + ->seeInElement('tbody tr td:nth-child(1)', $team->id) + ->seeInElement('tbody tr td:nth-child(2)', $team->club) + ->seeInElement('tbody tr td:nth-child(3)', $team->team); } public function testDeleteTeam() @@ -151,12 +169,15 @@ public function testDeleteTeam() /** @var Team $team */ $team = factory(Team::class)->create(); $teamId = $team->id; - $clubId = $team->club_id; - $teamName = $team->team; - $this->seeInDatabase('teams', ['id' => $teamId, 'club_id' => $clubId, 'team' => $teamName]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$teamId])) + $this->seeInDatabase('teams', [ + 'id' => $team->id, + 'club_id' => $team->club_id, + 'team' => $team->team, + ]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$team->id])) ->isRedirect(route(self::BASE_ROUTE . '.index')); + $this->dontSeeInDatabase('teams', ['id' => $teamId]); } } diff --git a/tests/Admin/DataManagement/VenuesTableTest.php b/tests/Admin/DataManagement/VenuesTableTest.php index defd5cbc..397da480 100644 --- a/tests/Admin/DataManagement/VenuesTableTest.php +++ b/tests/Admin/DataManagement/VenuesTableTest.php @@ -50,26 +50,29 @@ public function testAddVenue() $this->be($this->getFakeUser()); /** @var Venue $venue */ - $venue = factory(Venue::class)->create(); - $venueId = $venue->id; - $venueName = $venue->venue; + $venue = factory(Venue::class)->make(); // Brand new venue - $newVenueName = 'New ' . $venueName; $this->visit(route(self::BASE_ROUTE . '.create')) - ->type($newVenueName, 'venue') + ->type($venue->venue, 'venue') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Venue added!') - ->seeInDatabase('venues', ['id' => $venueId + 1, 'venue' => $newVenueName]); + ->seeInDatabase('venues', [ + 'id' => 1, + 'venue' => $venue->venue, + ]); // Already existing venue $this->visit(route(self::BASE_ROUTE . '.create')) - ->type($venueName, 'venue') + ->type($venue->venue, 'venue') ->press('Add') ->seePageIs(route(self::BASE_ROUTE . '.create')) ->seeInElement('.alert.alert-danger', 'The venue already exists.') - ->seeInDatabase('venues', ['id' => $venueId, 'venue' => $venueName]); + ->seeInDatabase('venues', [ + 'id' => 1, + 'venue' => $venue->venue, + ]); } public function testEditVenue() @@ -78,30 +81,43 @@ public function testEditVenue() /** @var Venue $venue */ $venue = factory(Venue::class)->create(); - $venueId = $venue->id; - $venueName = $venue->venue; - $newVenueName = 'New ' . $venueName; - $this->seeInDatabase('venues', ['id' => $venueId, 'venue' => $venueName]) - ->visit(route(self::BASE_ROUTE . '.edit', [$venueId])) - ->type($newVenueName, 'venue') + /** @var Venue $newVenue */ + $newVenue = factory(Venue::class)->make(); + + $this->seeInDatabase('venues', [ + 'id' => $venue->id, + 'venue' => $venue->venue, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$venue->id])) + ->type($newVenue->venue, 'venue') ->press('Update') ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Venue updated!') - ->seeInDatabase('venues', ['id' => $venueId, 'venue' => $newVenueName]); - $venueName = $newVenueName; + ->seeInDatabase('venues', [ + 'id' => $venue->id, + 'venue' => $newVenue->venue, + ]); + $venue->venue = $newVenue->venue; + unset($newVenue); - $anotherVenue = factory(Venue::class)->create(); - $anotherVenueName = $anotherVenue->venue; + /** @var Venue $newVenue */ + $newVenue = factory(Venue::class)->create(); // Already existing venue - $this->seeInDatabase('venues', ['id' => $venueId, 'venue' => $venueName]) - ->visit(route(self::BASE_ROUTE . '.edit', [$venueId])) - ->type($anotherVenueName, 'venue') + $this->seeInDatabase('venues', [ + 'id' => $venue->id, + 'venue' => $venue->venue, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$venue->id])) + ->type($newVenue->venue, 'venue') ->press('Update') - ->seePageIs(route(self::BASE_ROUTE . '.edit', [$venueId])) + ->seePageIs(route(self::BASE_ROUTE . '.edit', [$venue->id])) ->seeInElement('.alert.alert-danger', 'The venue already exists.') - ->seeInDatabase('venues', ['id' => $venueId, 'venue' => $venueName]); + ->seeInDatabase('venues', [ + 'id' => $venue->id, + 'venue' => $venue->venue, + ]); } public function testShowVenue() @@ -110,12 +126,10 @@ public function testShowVenue() /** @var Venue $venue */ $venue = factory(Venue::class)->create(); - $venueId = $venue->id; - $venueName = $venue->venue; - $this->visit(route(self::BASE_ROUTE . '.show', [$venueId])) - ->seeInElement('tbody tr td:nth-child(1)', $venueId) - ->seeInElement('tbody tr td:nth-child(2)', $venueName); + $this->visit(route(self::BASE_ROUTE . '.show', [$venue->id])) + ->seeInElement('tbody tr td:nth-child(1)', $venue->id) + ->seeInElement('tbody tr td:nth-child(2)', $venue->venue); } public function testDeleteVenue() @@ -125,11 +139,14 @@ public function testDeleteVenue() /** @var Venue $venue */ $venue = factory(Venue::class)->create(); $venueId = $venue->id; - $venueName = $venue->venue; - $this->seeInDatabase('venues', ['id' => $venueId, 'venue' => $venueName]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$venueId])) + $this->seeInDatabase('venues', [ + 'id' => $venue->id, + 'venue' => $venue->venue, + ]) + ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$venue->id])) ->isRedirect(route(self::BASE_ROUTE . '.index')); + $this->dontSeeInDatabase('venues', ['id' => $venueId]); } } diff --git a/tests/Admin/DataManagementTest.php b/tests/Admin/DataManagementTest.php index 7a1db45c..0b681aeb 100644 --- a/tests/Admin/DataManagementTest.php +++ b/tests/Admin/DataManagementTest.php @@ -12,8 +12,6 @@ class DataManagementTest extends TestCase { - private $admin; - public function testRedirectToLoginIfNotAdmin() { $this->visit(route('admin::dataManagement')) @@ -22,14 +20,14 @@ public function testRedirectToLoginIfNotAdmin() public function testBreadcrumbs() { - $this->be($this->admin); + $this->be($this->getFakeUser()); $this->breadcrumbsTests('admin::dataManagement', 'Data Management'); } public function testSeasonsTableButton() { - $this->be($this->admin); + $this->be($this->getFakeUser()); $this->visit(route('admin::dataManagement')) ->seeLink('Seasons', route('admin.data-management.seasons.index')); @@ -37,7 +35,7 @@ public function testSeasonsTableButton() public function testDivisionsTableButton() { - $this->be($this->admin); + $this->be($this->getFakeUser()); $this->visit(route('admin::dataManagement')) ->seeLink('Divisions', route('admin.data-management.divisions.index')); @@ -45,7 +43,7 @@ public function testDivisionsTableButton() public function testVenuesTableButton() { - $this->be($this->admin); + $this->be($this->getFakeUser()); $this->visit(route('admin::dataManagement')) ->seeLink('Venues', route('admin.data-management.venues.index')); @@ -53,7 +51,7 @@ public function testVenuesTableButton() public function testClubsTableButton() { - $this->be($this->admin); + $this->be($this->getFakeUser()); $this->visit(route('admin::dataManagement')) ->seeLink('Clubs', route('admin.data-management.clubs.index')); @@ -61,7 +59,7 @@ public function testClubsTableButton() public function testTeamsTableButton() { - $this->be($this->admin); + $this->be($this->getFakeUser()); $this->visit(route('admin::dataManagement')) ->seeLink('Teams', route('admin.data-management.teams.index')); @@ -69,7 +67,7 @@ public function testTeamsTableButton() public function testRolesTableButton() { - $this->be($this->admin); + $this->be($this->getFakeUser()); $this->visit(route('admin::dataManagement')) ->seeLink('Roles', route('admin.data-management.roles.index')); @@ -77,7 +75,7 @@ public function testRolesTableButton() public function testFixturesTableButton() { - $this->be($this->admin); + $this->be($this->getFakeUser()); $this->visit(route('admin::dataManagement')) ->seeLink('Fixtures', route('admin.data-management.fixtures.index')); @@ -85,16 +83,9 @@ public function testFixturesTableButton() public function testAvailableAppointmentsTableButton() { - $this->be($this->admin); + $this->be($this->getFakeUser()); $this->visit(route('admin::dataManagement')) ->seeLink('Available appointments', route('admin.data-management.available-appointments.index')); } - - protected function setUp() - { - parent::setUp(); - - $this->admin = $this->getFakeUser(); - } } From da5af88ed3c72d7232319b53e9da57058b0cc8fb Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sat, 14 May 2016 15:33:57 +0100 Subject: [PATCH 34/34] dev: added test for cascading delete --- .../DataManagement/FixturesController.php | 11 +++-- .../Admin/DataManagement/RolesController.php | 12 +++-- .../AvailableAppointmentsTableTest.php | 7 ++- tests/Admin/DataManagement/ClubsTableTest.php | 24 ++++++++-- .../DataManagement/DivisionsTableTest.php | 27 +++++++++-- .../DataManagement/FixturesTableTest.php | 39 +++++++++++++-- tests/Admin/DataManagement/RolesTableTest.php | 25 ++++++++-- .../Admin/DataManagement/SeasonsTableTest.php | 26 ++++++++-- tests/Admin/DataManagement/TeamsTableTest.php | 47 +++++++++++++++++-- .../Admin/DataManagement/VenuesTableTest.php | 24 ++++++++-- 10 files changed, 208 insertions(+), 34 deletions(-) diff --git a/app/Http/Controllers/Admin/DataManagement/FixturesController.php b/app/Http/Controllers/Admin/DataManagement/FixturesController.php index b358d41a..6105d96b 100644 --- a/app/Http/Controllers/Admin/DataManagement/FixturesController.php +++ b/app/Http/Controllers/Admin/DataManagement/FixturesController.php @@ -159,10 +159,13 @@ public function update(Request $request, $id) */ public function destroy($id) { - Fixture::destroy($id); - - \Flash::success('Fixture deleted!'); - + $canBeDeleted = empty(Fixture::find($id)->available_appointments->toArray()); + if ($canBeDeleted) { + Fixture::destroy($id); + \Flash::success('Fixture deleted!'); + } else { + \Flash::error('Cannot delete because they are existing appointments for this fixture.'); + } return redirect('admin/data-management/fixtures'); } diff --git a/app/Http/Controllers/Admin/DataManagement/RolesController.php b/app/Http/Controllers/Admin/DataManagement/RolesController.php index 2dfdcdfa..0ec6395e 100644 --- a/app/Http/Controllers/Admin/DataManagement/RolesController.php +++ b/app/Http/Controllers/Admin/DataManagement/RolesController.php @@ -107,10 +107,14 @@ public function update(Request $request, $id) */ public function destroy($id) { - Role::destroy($id); - - \Flash::success('Role deleted!'); - + $canBeDeleted = empty(Role::find($id)->available_appointment->toArray()); + if ($canBeDeleted) { + Role::destroy($id); + \Flash::success('Role deleted!'); + } else { + \Flash::error('Cannot delete because they are existing appointments for this role.'); + } + return redirect('admin/data-management/roles'); } diff --git a/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php b/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php index 4c8e665e..482f249c 100644 --- a/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php +++ b/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php @@ -223,9 +223,8 @@ public function testDeleteAvailableAppointment() 'fixture_id' => $appointment->fixture_id, 'role_id' => $appointment->role_id, ]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$appointment->id])) - ->isRedirect(route(self::BASE_ROUTE . '.index')); - - $this->dontSeeInDatabase('available_appointments', ['id' => $appointmentId]); + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$appointment->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->dontSeeInDatabase('available_appointments', ['id' => $appointmentId]); } } diff --git a/tests/Admin/DataManagement/ClubsTableTest.php b/tests/Admin/DataManagement/ClubsTableTest.php index dbe9fe81..2f8689f8 100644 --- a/tests/Admin/DataManagement/ClubsTableTest.php +++ b/tests/Admin/DataManagement/ClubsTableTest.php @@ -8,6 +8,7 @@ namespace Admin\DataManagement; +use App\Models\Team; use Tests\TestCase; use App\Models\Club; @@ -144,9 +145,26 @@ public function testDeleteClub() 'id' => $club->id, 'club' => $club->club, ]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$club->id])) - ->isRedirect(route(self::BASE_ROUTE . '.index')); + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$club->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Club deleted!') + ->dontSeeInDatabase('clubs', ['id' => $clubId]); - $this->dontSeeInDatabase('clubs', ['id' => $clubId]); + // Delete a clubs with teams + /** @var Club $club */ + $club = factory(Club::class)->create(); + /** @var Team $team */ + $team = factory(Team::class)->create(['club_id' => $club->id]); + $this->seeInDatabase('clubs', [ + 'id' => $club->id, + 'club' => $club->club, + ]) + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$club->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-danger', 'Cannot delete because they are existing teams in this club.') + ->seeInDatabase('clubs', [ + 'id' => $club->id, + 'club' => $club->club, + ]); } } diff --git a/tests/Admin/DataManagement/DivisionsTableTest.php b/tests/Admin/DataManagement/DivisionsTableTest.php index 32696499..fcae02aa 100644 --- a/tests/Admin/DataManagement/DivisionsTableTest.php +++ b/tests/Admin/DataManagement/DivisionsTableTest.php @@ -8,6 +8,7 @@ namespace Admin\DataManagement; +use App\Models\Fixture; use Tests\TestCase; use App\Models\Division; use App\Models\Season; @@ -177,9 +178,29 @@ public function testDeleteDivision() 'season_id' => $division->season_id, 'division' => $division->division, ]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$division->id])) - ->isRedirect(route(self::BASE_ROUTE . '.index')); + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$division->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Division deleted!') + ->dontSeeInDatabase('divisions', ['id' => $divisionId]); + + // Delete division with fixtures + /** @var Division $division */ + $division = factory(Division::class)->create(); + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(['division_id' => $division->id]); - $this->dontSeeInDatabase('divisions', ['id' => $divisionId]); + $this->seeInDatabase('divisions', [ + 'id' => $division->id, + 'season_id' => $division->season_id, + 'division' => $division->division, + ]) + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$division->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-danger', 'Cannot delete because they are existing fixtures in this division.') + ->seeInDatabase('divisions', [ + 'id' => $division->id, + 'season_id' => $division->season_id, + 'division' => $division->division, + ]); } } diff --git a/tests/Admin/DataManagement/FixturesTableTest.php b/tests/Admin/DataManagement/FixturesTableTest.php index a4ab2a4f..c3c52651 100644 --- a/tests/Admin/DataManagement/FixturesTableTest.php +++ b/tests/Admin/DataManagement/FixturesTableTest.php @@ -8,6 +8,7 @@ namespace Admin\DataManagement; +use App\Models\AvailableAppointment; use Tests\TestCase; use App\Models\Fixture; @@ -243,9 +244,41 @@ public function testDeleteFixture() 'warm_up_time' => $fixture->warm_up_time, 'start_time' => $fixture->start_time, ]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$fixture->id])) - ->isRedirect(route(self::BASE_ROUTE . '.index')); + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$fixture->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Fixture deleted!') + ->dontSeeInDatabase('fixtures', ['id' => $fixtureId]); + + // Delete fixture with existing appointment + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + /** @var AvailableAppointment $appointment */ + $appointment = factory(AvailableAppointment::class)->create(['fixture_id' => $fixture->id]); - $this->dontSeeInDatabase('fixtures', ['id' => $fixtureId]); + $this->seeInDatabase('fixtures', [ + 'id' => $fixture->id, + 'division_id' => $fixture->division_id, + 'home_team_id' => $fixture->home_team_id, + 'away_team_id' => $fixture->away_team_id, + 'venue_id' => $fixture->venue_id, + 'match_number' => $fixture->match_number, + 'match_date' => $fixture->match_date->format('Y-m-d'), + 'warm_up_time' => $fixture->warm_up_time, + 'start_time' => $fixture->start_time, + ]) + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$fixture->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-danger', 'Cannot delete because they are existing appointments for this fixture.') + ->seeInDatabase('fixtures', [ + 'id' => $fixture->id, + 'division_id' => $fixture->division_id, + 'home_team_id' => $fixture->home_team_id, + 'away_team_id' => $fixture->away_team_id, + 'venue_id' => $fixture->venue_id, + 'match_number' => $fixture->match_number, + 'match_date' => $fixture->match_date->format('Y-m-d'), + 'warm_up_time' => $fixture->warm_up_time, + 'start_time' => $fixture->start_time, + ]); } } diff --git a/tests/Admin/DataManagement/RolesTableTest.php b/tests/Admin/DataManagement/RolesTableTest.php index ea705dfc..33cbfbad 100644 --- a/tests/Admin/DataManagement/RolesTableTest.php +++ b/tests/Admin/DataManagement/RolesTableTest.php @@ -8,6 +8,7 @@ namespace Admin\DataManagement; +use App\Models\AvailableAppointment; use Tests\TestCase; use App\Models\Role; @@ -144,9 +145,27 @@ public function testDeleteRole() 'id' => $role->id, 'role' => $role->role, ]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$role->id])) - ->isRedirect(route(self::BASE_ROUTE . '.index')); + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$role->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Role deleted!') + ->dontSeeInDatabase('roles', ['id' => $roleId]); + + // Delete a role with available appointments + /** @var Role $role */ + $role = factory(Role::class)->create(); + /** @var AvailableAppointment $appointment */ + $appointment = factory(AvailableAppointment::class)->create(['role_id' => $role->id]); - $this->dontSeeInDatabase('roles', ['id' => $roleId]); + $this->seeInDatabase('roles', [ + 'id' => $role->id, + 'role' => $role->role, + ]) + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$role->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-danger', 'Cannot delete because they are existing appointments for this role.') + ->seeInDatabase('roles', [ + 'id' => $role->id, + 'role' => $role->role, + ]); } } diff --git a/tests/Admin/DataManagement/SeasonsTableTest.php b/tests/Admin/DataManagement/SeasonsTableTest.php index a003026b..f80d9021 100644 --- a/tests/Admin/DataManagement/SeasonsTableTest.php +++ b/tests/Admin/DataManagement/SeasonsTableTest.php @@ -8,6 +8,8 @@ namespace Admin\DataManagement; +use App\Models\Division; +use PhpParser\Node\Expr\AssignOp\Div; use Tests\TestCase; use App\Models\Season; @@ -144,9 +146,27 @@ public function testDeleteSeason() 'id' => $season->id, 'season' => $season->season, ]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$season->id])) - ->isRedirect(route(self::BASE_ROUTE . '.index')); + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$season->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Season deleted!') + ->dontSeeInDatabase('seasons', ['id' => $seasonId]); + + // Delete a season with divisions + /** @var Season $season */ + $season = factory(Season::class)->create(); + /** @var Division $division */ + $division = factory(Division::class)->create(['season_id' => $season->id]); - $this->dontSeeInDatabase('seasons', ['id' => $seasonId]); + $this->seeInDatabase('seasons', [ + 'id' => $season->id, + 'season' => $season->season, + ]) + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$season->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-danger', 'Cannot delete because they are existing divisions in this season.') + ->seeInDatabase('seasons', [ + 'id' => $season->id, + 'season' => $season->season, + ]); } } diff --git a/tests/Admin/DataManagement/TeamsTableTest.php b/tests/Admin/DataManagement/TeamsTableTest.php index 20cf835d..6a9624d0 100644 --- a/tests/Admin/DataManagement/TeamsTableTest.php +++ b/tests/Admin/DataManagement/TeamsTableTest.php @@ -8,6 +8,7 @@ namespace Admin\DataManagement; +use App\Models\Fixture; use Tests\TestCase; use App\Models\Team; use App\Models\Club; @@ -175,9 +176,47 @@ public function testDeleteTeam() 'club_id' => $team->club_id, 'team' => $team->team, ]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$team->id])) - ->isRedirect(route(self::BASE_ROUTE . '.index')); - - $this->dontSeeInDatabase('teams', ['id' => $teamId]); + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$team->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Team deleted!') + ->dontSeeInDatabase('teams', ['id' => $teamId]); + + // Delete team with fixtures + /** @var Team $team */ + $team = factory(Team::class)->create(); + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(['home_team_id' => $team->id]); + + $this->seeInDatabase('teams', [ + 'id' => $team->id, + 'club_id' => $team->club_id, + 'team' => $team->team, + ]) + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$team->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-danger', 'Cannot delete because they are existing fixtures for this team.') + ->seeInDatabase('teams', [ + 'id' => $team->id, + 'club_id' => $team->club_id, + 'team' => $team->team, + ]); + + Fixture::destroy($fixture->id); + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(['away_team_id' => $team->id]); + + $this->seeInDatabase('teams', [ + 'id' => $team->id, + 'club_id' => $team->club_id, + 'team' => $team->team, + ]) + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$team->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-danger', 'Cannot delete because they are existing fixtures for this team.') + ->seeInDatabase('teams', [ + 'id' => $team->id, + 'club_id' => $team->club_id, + 'team' => $team->team, + ]); } } diff --git a/tests/Admin/DataManagement/VenuesTableTest.php b/tests/Admin/DataManagement/VenuesTableTest.php index 397da480..7fd8da3c 100644 --- a/tests/Admin/DataManagement/VenuesTableTest.php +++ b/tests/Admin/DataManagement/VenuesTableTest.php @@ -8,6 +8,7 @@ namespace Admin\DataManagement; +use App\Models\Fixture; use Tests\TestCase; use App\Models\Venue; @@ -144,9 +145,26 @@ public function testDeleteVenue() 'id' => $venue->id, 'venue' => $venue->venue, ]) - ->call('DELETE', route(self::BASE_ROUTE . '.destroy', [$venue->id])) - ->isRedirect(route(self::BASE_ROUTE . '.index')); + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$venue->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Venue deleted!') + ->dontSeeInDatabase('venues', ['id' => $venueId]); + + // Delete a venue with fixtures + /** @var Venue $venue */ + $venue = factory(Venue::class)->create(); + $fixture = factory(Fixture::class)->create(['venue_id' => $venue->id]); - $this->dontSeeInDatabase('venues', ['id' => $venueId]); + $this->seeInDatabase('venues', [ + 'id' => $venue->id, + 'venue' => $venue->venue, + ]) + ->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$venue->id])) + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-danger', 'Cannot delete because they are existing fixtures at this venue.') + ->seeInDatabase('venues', [ + 'id' => $venue->id, + 'venue' => $venue->venue, + ]); } }