Skip to content
This repository was archived by the owner on Jun 18, 2024. It is now read-only.

Commit 12ba114

Browse files
author
Luuk van Kooten
committed
Added new modules charts for allergy & charts for allergy
1 parent f52cb33 commit 12ba114

File tree

14 files changed

+342
-9
lines changed

14 files changed

+342
-9
lines changed

app/Allergy.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Allergy extends Model
8+
{
9+
10+
protected $fillable = ['allergy'];
11+
12+
public function user()
13+
{
14+
return $this->belongsToMany(User::class, 'allergy_user');
15+
}
16+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Ajax;
4+
5+
use Illuminate\Http\Request;
6+
use App\Http\Controllers\Controller;
7+
8+
class ChartsController extends Controller
9+
{
10+
function __construct()
11+
{
12+
$this->middleware(['auth', 'can:statestieken']);
13+
}
14+
15+
public function data(Request $request)
16+
{
17+
$v = \validator($request->all(), [
18+
'' => '',
19+
]);
20+
}
21+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use App\{
7+
Allergy, Role, User
8+
};
9+
class AllergyController extends Controller
10+
{
11+
function __construct()
12+
{
13+
$this->middleware(['auth', 'can:allergieen']);
14+
}
15+
16+
public function create()
17+
{
18+
$users = \Auth::user()->hasRole('Huisarts') ? \Auth::user()->user()->get() :
19+
Role::whereName('Gebruiker')->first()->users;
20+
21+
$allergies = [];
22+
23+
return view('main.allergy.create', compact('users', 'allergies'));
24+
}
25+
26+
27+
public function store(Request $request)
28+
{
29+
$request->validate([
30+
'user' => 'exists:users,name|required|string',
31+
'allergy' => 'string|required',
32+
]);
33+
34+
$user = User::whereName($request->user)->first()->id;
35+
36+
$allergy = Allergy::create([
37+
'allergy' => $request->allergy,
38+
]);
39+
40+
41+
$allergy->user()->attach($user);
42+
43+
return redirect('allergieen')->with('status', 'Allergie ingevoerd.');
44+
45+
}
46+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
class StaticController extends Controller
8+
{
9+
function __construct()
10+
{
11+
$this->middleware(['auth', 'can:statestieken']);
12+
}
13+
14+
/**
15+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
16+
*/
17+
public function index() {
18+
return view('main.static.index');
19+
}
20+
}

app/Repositories/HasAllergy.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Repositories;
4+
5+
use App\Allergy;
6+
7+
trait HasAllergy
8+
{
9+
public function allergy()
10+
{
11+
return $this->belongsToMany(Allergy::class, 'allergy_user', 'allergy_id', 'user_id');
12+
}
13+
}

app/User.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace App;
44

5-
use App\Repositories\{HasRoles, HasPractitioner, HasConsult, HasGroup, HasAddress};
5+
use App\Repositories\{HasRoles, HasPractitioner, HasConsult, HasGroup, HasAddress, HasAllergy};
66
use Laravel\Passport\HasApiTokens;
77
use Illuminate\Notifications\Notifiable;
88
use Illuminate\Foundation\Auth\User as Authenticatable;
@@ -15,7 +15,8 @@ class User extends Authenticatable
1515
HasPractitioner,
1616
HasConsult,
1717
HasGroup,
18-
HasAddress;
18+
HasAddress,
19+
HasAllergy;
1920

2021
/**
2122
* The attributes that are mass assignable.
@@ -43,7 +44,7 @@ class User extends Authenticatable
4344
*/
4445
public function owns($related)
4546
{
46-
return $this->id == $related->id;
47+
return $this->id === $related->id;
4748
}
4849

4950
public static function isAdmin()
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreateAllergiesTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('allergies', function (Blueprint $table) {
17+
$table->increments('id');
18+
$table->string('allergy');
19+
$table->timestamps();
20+
});
21+
22+
Schema::create('allergy_user', function (Blueprint $table) {
23+
$table->integer('allergy_id')->unsigned();
24+
$table->foreign('allergy_id')
25+
->references('id')
26+
->on('allergies')
27+
->onDelete('cascade');
28+
$table->primary(['user_id', 'allergy_id']);
29+
30+
$table->integer('user_id')->unsigned();
31+
$table->foreign('user_id')
32+
->references('id')
33+
->on('users')
34+
->onDelete('cascade');
35+
});
36+
37+
38+
}
39+
40+
/**
41+
* Reverse the migrations.
42+
*
43+
* @return void
44+
*/
45+
public function down()
46+
{
47+
Schema::dropIfExists('allergies');
48+
}
49+
}

package-lock.json

Lines changed: 39 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"webpack-livereload-plugin": "^2.1.1"
2323
},
2424
"dependencies": {
25+
"chart.js": "^2.7.2",
2526
"font-awesome": "^4.7.0"
2627
}
2728
}

resources/assets/js/chart.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
window.Chart = require('chart.js');

0 commit comments

Comments
 (0)