jauhar54 2 yıl önce
işleme
03c91e0dba
100 değiştirilmiş dosya ile 9606 ekleme ve 0 silme
  1. 15
    0
      .editorconfig
  2. 53
    0
      .env.example
  3. 5
    0
      .gitattributes
  4. 15
    0
      .gitignore
  5. 13
    0
      .styleci.yml
  6. 78
    0
      README.md
  7. 100
    0
      app/Console/Commands/ExpiredDateDarah.php
  8. 44
    0
      app/Console/Kernel.php
  9. 56
    0
      app/Exceptions/Handler.php
  10. 312
    0
      app/Helpers/Helper.php
  11. 96
    0
      app/Http/Controllers/Admin/DashboardController.php
  12. 433
    0
      app/Http/Controllers/Admin/Raharja/EventOrganisasiController.php
  13. 268
    0
      app/Http/Controllers/Admin/Raharja/KelompokDriverController.php
  14. 266
    0
      app/Http/Controllers/Admin/Raharja/MasterPointsController.php
  15. 287
    0
      app/Http/Controllers/Admin/Raharja/MessageController.php
  16. 306
    0
      app/Http/Controllers/Admin/Raharja/NewsController.php
  17. 307
    0
      app/Http/Controllers/Admin/Raharja/TipsController.php
  18. 353
    0
      app/Http/Controllers/Admin/TransportationController.php
  19. 323
    0
      app/Http/Controllers/Admin/Trivia/TriviaController.php
  20. 341
    0
      app/Http/Controllers/Admin/User_management/PermissionController.php
  21. 480
    0
      app/Http/Controllers/Admin/User_management/PetugasUddController.php
  22. 402
    0
      app/Http/Controllers/Admin/User_management/RoleController.php
  23. 448
    0
      app/Http/Controllers/Admin/User_management/RumahSakitController.php
  24. 400
    0
      app/Http/Controllers/Admin/User_management/UserController.php
  25. 56
    0
      app/Http/Controllers/Api/V1/KelompokDriverController.php
  26. 182
    0
      app/Http/Controllers/Api/V1/MessageController.php
  27. 182
    0
      app/Http/Controllers/Api/V1/NewsController.php
  28. 107
    0
      app/Http/Controllers/Api/V1/PointLogController.php
  29. 25
    0
      app/Http/Controllers/Api/V1/TestController.php
  30. 0
    0
      app/Http/Controllers/Api/V1/TimelineController.php
  31. 183
    0
      app/Http/Controllers/Api/V1/TipsController.php
  32. 138
    0
      app/Http/Controllers/Api/V1/TransportationController.php
  33. 241
    0
      app/Http/Controllers/Api/V1/TravelController.php
  34. 139
    0
      app/Http/Controllers/Api/V1/TriviaController.php
  35. 260
    0
      app/Http/Controllers/Api/V1/UserController.php
  36. 40
    0
      app/Http/Controllers/Auth/ConfirmPasswordController.php
  37. 22
    0
      app/Http/Controllers/Auth/ForgotPasswordController.php
  38. 108
    0
      app/Http/Controllers/Auth/LoginController.php
  39. 73
    0
      app/Http/Controllers/Auth/RegisterController.php
  40. 30
    0
      app/Http/Controllers/Auth/ResetPasswordController.php
  41. 42
    0
      app/Http/Controllers/Auth/VerificationController.php
  42. 13
    0
      app/Http/Controllers/Controller.php
  43. 125
    0
      app/Http/Controllers/FetchController.php
  44. 28
    0
      app/Http/Controllers/HomeController.php
  45. 112
    0
      app/Http/Controllers/UploadController.php
  46. 74
    0
      app/Http/Kernel.php
  47. 23
    0
      app/Http/Middleware/APIVersion.php
  48. 24
    0
      app/Http/Middleware/AuthCheckLogin.php
  49. 21
    0
      app/Http/Middleware/Authenticate.php
  50. 17
    0
      app/Http/Middleware/CheckForMaintenanceMode.php
  51. 17
    0
      app/Http/Middleware/EncryptCookies.php
  52. 27
    0
      app/Http/Middleware/RedirectIfAuthenticated.php
  53. 18
    0
      app/Http/Middleware/TrimStrings.php
  54. 23
    0
      app/Http/Middleware/TrustProxies.php
  55. 17
    0
      app/Http/Middleware/VerifyCsrfToken.php
  56. 70
    0
      app/Imports/StockReleaseImport.php
  57. 15
    0
      app/Model/ModelHasRoles.php
  58. 15
    0
      app/Model/NewsLog.php
  59. 15
    0
      app/Model/PointLog.php
  60. 15
    0
      app/Model/Points.php
  61. 24
    0
      app/Model/Profile.php
  62. 18
    0
      app/Model/Raharja/CategoryMesssage.php
  63. 21
    0
      app/Model/Raharja/EventOrganisasi.php
  64. 18
    0
      app/Model/Raharja/EventOrganisasiMembers.php
  65. 20
    0
      app/Model/Raharja/KelompokDriver.php
  66. 28
    0
      app/Model/Raharja/Message.php
  67. 26
    0
      app/Model/Raharja/News.php
  68. 18
    0
      app/Model/Raharja/NewsLikes.php
  69. 26
    0
      app/Model/Raharja/Tips.php
  70. 18
    0
      app/Model/Raharja/TipsLikes.php
  71. 23
    0
      app/Model/Raharja/UserReceive.php
  72. 14
    0
      app/Model/RoleHasPermission.php
  73. 15
    0
      app/Model/TipsLog.php
  74. 21
    0
      app/Model/Transportation.php
  75. 15
    0
      app/Model/Travel.php
  76. 15
    0
      app/Model/TravelLog.php
  77. 15
    0
      app/Model/Trivia.php
  78. 15
    0
      app/Model/TriviaAnswer.php
  79. 39
    0
      app/Model/User/MasterRumahSakits.php
  80. 30
    0
      app/Model/User/PetugasUnitDonorDarahUdds.php
  81. 29
    0
      app/Providers/AppServiceProvider.php
  82. 30
    0
      app/Providers/AuthServiceProvider.php
  83. 21
    0
      app/Providers/BroadcastServiceProvider.php
  84. 34
    0
      app/Providers/EventServiceProvider.php
  85. 84
    0
      app/Providers/RouteServiceProvider.php
  86. 15
    0
      app/Roles.php
  87. 26
    0
      app/StockLogs.php
  88. 58
    0
      app/User.php
  89. 68
    0
      app/Utils/DashboardUtil.php
  90. 53
    0
      artisan
  91. 55
    0
      bootstrap/app.php
  92. 2
    0
      bootstrap/cache/.gitignore
  93. 74
    0
      composer.json
  94. 280
    0
      config/app.php
  95. 117
    0
      config/auth.php
  96. 59
    0
      config/broadcasting.php
  97. 103
    0
      config/cache.php
  98. 34
    0
      config/cors.php
  99. 147
    0
      config/database.php
  100. 0
    0
      config/datatables.php

+ 15
- 0
.editorconfig Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+root = true
2
+
3
+[*]
4
+charset = utf-8
5
+end_of_line = lf
6
+insert_final_newline = true
7
+indent_style = space
8
+indent_size = 4
9
+trim_trailing_whitespace = true
10
+
11
+[*.md]
12
+trim_trailing_whitespace = false
13
+
14
+[*.{yml,yaml}]
15
+indent_size = 2

+ 53
- 0
.env.example Dosyayı Görüntüle

@@ -0,0 +1,53 @@
1
+APP_NAME=Laravel
2
+APP_ENV=local
3
+APP_KEY=base64:maICT6trNzJAqPMRnPOvW/IIreaVSnnahE3Nr7Oymhg=
4
+APP_DEBUG=true
5
+APP_URL=http://localhost
6
+HASH=RAHARJA2022
7
+
8
+LOG_CHANNEL=stack
9
+LOG_DEPRECATIONS_CHANNEL=null
10
+LOG_LEVEL=debug
11
+
12
+DB_CONNECTION=mysql
13
+DB_HOST=127.0.0.1
14
+DB_PORT=3306
15
+DB_DATABASE=dev_raharja
16
+DB_USERNAME=root
17
+DB_PASSWORD=
18
+
19
+BROADCAST_DRIVER=log
20
+CACHE_DRIVER=file
21
+FILESYSTEM_DRIVER=local
22
+QUEUE_CONNECTION=sync
23
+SESSION_DRIVER=database
24
+SESSION_LIFETIME=120
25
+
26
+MEMCACHED_HOST=127.0.0.1
27
+
28
+REDIS_HOST=127.0.0.1
29
+REDIS_PASSWORD=null
30
+REDIS_PORT=6379
31
+
32
+MAIL_MAILER=smtp
33
+MAIL_HOST=mailhog
34
+MAIL_PORT=1025
35
+MAIL_USERNAME=null
36
+MAIL_PASSWORD=null
37
+MAIL_ENCRYPTION=null
38
+MAIL_FROM_ADDRESS=null
39
+MAIL_FROM_NAME="${APP_NAME}"
40
+
41
+AWS_ACCESS_KEY_ID=
42
+AWS_SECRET_ACCESS_KEY=
43
+AWS_DEFAULT_REGION=us-east-1
44
+AWS_BUCKET=
45
+AWS_USE_PATH_STYLE_ENDPOINT=false
46
+
47
+PUSHER_APP_ID=
48
+PUSHER_APP_KEY=
49
+PUSHER_APP_SECRET=
50
+PUSHER_APP_CLUSTER=mt1
51
+
52
+MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
53
+MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

+ 5
- 0
.gitattributes Dosyayı Görüntüle

@@ -0,0 +1,5 @@
1
+* text=auto
2
+*.css linguist-vendored
3
+*.scss linguist-vendored
4
+*.js linguist-vendored
5
+CHANGELOG.md export-ignore

+ 15
- 0
.gitignore Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+/node_modules
2
+/public/hot
3
+/public/storage
4
+/storage/framework
5
+/storage/framework/cache
6
+/storage/logs
7
+/vendor
8
+.env
9
+.env.backup
10
+.phpunit.result.cache
11
+composer.lock
12
+Homestead.json
13
+Homestead.yaml
14
+npm-debug.log
15
+yarn-error.log

+ 13
- 0
.styleci.yml Dosyayı Görüntüle

@@ -0,0 +1,13 @@
1
+php:
2
+  preset: laravel
3
+  disabled:
4
+    - unused_use
5
+  finder:
6
+    not-name:
7
+      - index.php
8
+      - server.php
9
+js:
10
+  finder:
11
+    not-name:
12
+      - webpack.mix.js
13
+css: true

+ 78
- 0
README.md Dosyayı Görüntüle

@@ -0,0 +1,78 @@
1
+<p align="center"><img src="https://res.cloudinary.com/dtfbvvkyp/image/upload/v1566331377/laravel-logolockup-cmyk-red.svg" width="400"></p>
2
+
3
+<p align="center">
4
+<a href="https://travis-ci.org/laravel/framework"><img src="https://travis-ci.org/laravel/framework.svg" alt="Build Status"></a>
5
+<a href="https://packagist.org/packages/laravel/framework"><img src="https://poser.pugx.org/laravel/framework/d/total.svg" alt="Total Downloads"></a>
6
+<a href="https://packagist.org/packages/laravel/framework"><img src="https://poser.pugx.org/laravel/framework/v/stable.svg" alt="Latest Stable Version"></a>
7
+<a href="https://packagist.org/packages/laravel/framework"><img src="https://poser.pugx.org/laravel/framework/license.svg" alt="License"></a>
8
+</p>
9
+
10
+## About Laravel
11
+
12
+Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
13
+
14
+- [Simple, fast routing engine](https://laravel.com/docs/routing).
15
+- [Powerful dependency injection container](https://laravel.com/docs/container).
16
+- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
17
+- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
18
+- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
19
+- [Robust background job processing](https://laravel.com/docs/queues).
20
+- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
21
+
22
+Laravel is accessible, powerful, and provides tools required for large, robust applications.
23
+
24
+## Learning Laravel
25
+
26
+Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
27
+
28
+If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 1500 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
29
+
30
+## Laravel Sponsors
31
+
32
+We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell).
33
+
34
+- **[Vehikl](https://vehikl.com/)**
35
+- **[Tighten Co.](https://tighten.co)**
36
+- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
37
+- **[64 Robots](https://64robots.com)**
38
+- **[Cubet Techno Labs](https://cubettech.com)**
39
+- **[Cyber-Duck](https://cyber-duck.co.uk)**
40
+- **[British Software Development](https://www.britishsoftware.co)**
41
+- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)**
42
+- **[DevSquad](https://devsquad.com)**
43
+- [UserInsights](https://userinsights.com)
44
+- [Fragrantica](https://www.fragrantica.com)
45
+- [SOFTonSOFA](https://softonsofa.com/)
46
+- [User10](https://user10.com)
47
+- [Soumettre.fr](https://soumettre.fr/)
48
+- [CodeBrisk](https://codebrisk.com)
49
+- [1Forge](https://1forge.com)
50
+- [TECPRESSO](https://tecpresso.co.jp/)
51
+- [Runtime Converter](http://runtimeconverter.com/)
52
+- [WebL'Agence](https://weblagence.com/)
53
+- [Invoice Ninja](https://www.invoiceninja.com)
54
+- [iMi digital](https://www.imi-digital.de/)
55
+- [Earthlink](https://www.earthlink.ro/)
56
+- [Steadfast Collective](https://steadfastcollective.com/)
57
+- [We Are The Robots Inc.](https://watr.mx/)
58
+- [Understand.io](https://www.understand.io/)
59
+- [Abdel Elrafa](https://abdelelrafa.com)
60
+- [Hyper Host](https://hyper.host)
61
+- [Appoly](https://www.appoly.co.uk)
62
+- [OP.GG](https://op.gg)
63
+
64
+## Contributing
65
+
66
+Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
67
+
68
+## Code of Conduct
69
+
70
+In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
71
+
72
+## Security Vulnerabilities
73
+
74
+If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
75
+
76
+## License
77
+
78
+The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

+ 100
- 0
app/Console/Commands/ExpiredDateDarah.php Dosyayı Görüntüle

@@ -0,0 +1,100 @@
1
+<?php
2
+
3
+namespace App\Console\Commands;
4
+
5
+use App\Model\Data\Order\Pemusnahan\Pemusnahan;
6
+use App\Model\Data\StockLogs;
7
+use App\Model\Data\StockRelease;
8
+use App\Model\Data\Stocks;
9
+use Carbon\Carbon;
10
+use Illuminate\Console\Command;
11
+use Illuminate\Support\Facades\DB;
12
+use Auth;
13
+
14
+class ExpiredDateDarah extends Command
15
+{
16
+    /**
17
+     * The name and signature of the console command.
18
+     *
19
+     * @var string
20
+     */
21
+    protected $signature = 'expired:date';
22
+
23
+    /**
24
+     * The console command description.
25
+     *
26
+     * @var string
27
+     */
28
+    protected $description = 'Hapus Kantong Darah Yang Expired';
29
+
30
+    /**
31
+     * Create a new command instance.
32
+     *
33
+     * @return void
34
+     */
35
+    public function __construct()
36
+    {
37
+        parent::__construct();
38
+    }
39
+
40
+    /**
41
+     * Execute the console command.
42
+     *
43
+     * @return int
44
+     */
45
+    public function handle()
46
+    {
47
+        $this->info('Cek cron job');
48
+        $cek_data =  StockRelease::where('expired_date', '<', Carbon::now())
49
+        ->get();
50
+
51
+        foreach($cek_data as $key => $value){
52
+
53
+            $cek_stock_release[$key] = StockRelease::where('id', $value->id)->first();
54
+
55
+            $data_stock_release[$key] = [
56
+                'status_id' => 3,
57
+            ];
58
+
59
+            DB::table('stock_releases')->where('id', $value->id)
60
+            ->update($data_stock_release[$key]);
61
+
62
+            $cek_stock[$key] = Stocks::where('golongan_darah_id', $value->golongan_darah_id)
63
+            ->where('rhesus_id', $value->rhesus_id)
64
+            ->where('produk_id', $value->produk_id)
65
+            ->where('unit_donor_darah_id', $value->unit_donor_darah_id)
66
+            ->first();
67
+
68
+            if($cek_stock[$key]->quantity_kantong != 0){
69
+                $data_stock[$key] = [
70
+                    'quantity_kantong' => $cek_stock[$key]['quantity_kantong'] - 1,
71
+                ];
72
+                DB::table('stocks')->where('golongan_darah_id', $value->golongan_darah_id)
73
+                    ->where('produk_id', $value->produk_id)
74
+                    ->where('rhesus_id', $value->rhesus_id)
75
+                    ->where('unit_donor_darah_id', $value->unit_donor_darah_id)
76
+                    ->update($data_stock[$key]);
77
+            }
78
+
79
+            $data_log[$key] = [
80
+                'log'              => 'Pemusnahan Darah dengan no kantong :  ' . $value->no_kantong,
81
+                'user_id'          => 1,
82
+                'quantity_kantong' => 1,
83
+                'is_stock_in'      => 1,
84
+                'is_stock_out'     => 0,
85
+                'created_at'       => NOW(),
86
+                'updated_at'       => NOW(),
87
+            ];
88
+            $data_pemusnahan[$key] = [
89
+                'release_id' => $value->id,
90
+                'keterangan' => 'Darah Sudah Expired',
91
+                'petugas_id' => 1,
92
+                'created_at' => NOW(),
93
+                'updated_at' => NOW(),
94
+            ];
95
+
96
+        }
97
+        $update_log             = StockLogs::insert($data_log);
98
+        $insert_data_pemusnahan = Pemusnahan::insert($data_pemusnahan);
99
+    }
100
+}

+ 44
- 0
app/Console/Kernel.php Dosyayı Görüntüle

@@ -0,0 +1,44 @@
1
+<?php
2
+
3
+namespace App\Console;
4
+
5
+use App\Console\Commands\ExpiredDateDarah;
6
+use Illuminate\Console\Scheduling\Schedule;
7
+use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
8
+
9
+class Kernel extends ConsoleKernel
10
+{
11
+    /**
12
+     * The Artisan commands provided by your application.
13
+     *
14
+     * @var array
15
+     */
16
+    protected $commands = [
17
+        ExpiredDateDarah::class,
18
+    ];
19
+
20
+    /**
21
+     * Define the application's command schedule.
22
+     *
23
+     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
24
+     * @return void
25
+     */
26
+    protected function schedule(Schedule $schedule)
27
+    {
28
+        // $schedule->command('inspire')->hourly();
29
+        $schedule->command('expired:date')
30
+        ->everyMinute();
31
+    }
32
+
33
+    /**
34
+     * Register the commands for the application.
35
+     *
36
+     * @return void
37
+     */
38
+    protected function commands()
39
+    {
40
+        $this->load(__DIR__.'/Commands');
41
+
42
+        require base_path('routes/console.php');
43
+    }
44
+}

+ 56
- 0
app/Exceptions/Handler.php Dosyayı Görüntüle

@@ -0,0 +1,56 @@
1
+<?php
2
+
3
+namespace App\Exceptions;
4
+
5
+use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
6
+use Throwable;
7
+
8
+class Handler extends ExceptionHandler
9
+{
10
+    /**
11
+     * A list of the exception types that are not reported.
12
+     *
13
+     * @var array
14
+     */
15
+    protected $dontReport = [
16
+        //
17
+    ];
18
+
19
+    /**
20
+     * A list of the inputs that are never flashed for validation exceptions.
21
+     *
22
+     * @var array
23
+     */
24
+    protected $dontFlash = [
25
+        'password',
26
+        'password_confirmation',
27
+    ];
28
+
29
+    /**
30
+     * Report or log an exception.
31
+     *
32
+     * @param  \Throwable  $exception
33
+     * @return void
34
+     *
35
+     * @throws \Exception
36
+     */
37
+    public function report(Throwable $exception)
38
+    {
39
+        parent::report($exception);
40
+    }
41
+
42
+    /**
43
+     * Render an exception into an HTTP response.
44
+     *
45
+     * @param  \Illuminate\Http\Request  $request
46
+     * @param  \Throwable  $exception
47
+     * @return \Symfony\Component\HttpFoundation\Response
48
+     *
49
+     * @throws \Throwable
50
+     */
51
+    public function render($request, Throwable $exception)
52
+    {
53
+        return parent::render($request, $exception);
54
+        // return redirect(route('auth.index'));
55
+    }
56
+}

+ 312
- 0
app/Helpers/Helper.php Dosyayı Görüntüle

@@ -0,0 +1,312 @@
1
+<?php
2
+
3
+namespace App\Helpers;
4
+
5
+
6
+use Auth;
7
+use ReflectionClass;
8
+use File;
9
+use URL;
10
+use Spatie\Permission\Models\Permission;
11
+use Spatie\Permission\Models\Role;
12
+use Carbon\Carbon;
13
+
14
+class Helper
15
+{
16
+    public static function success_alert($message)
17
+    {
18
+        $string = '';
19
+        if (is_array($message)) {
20
+            $string = '<ul>';
21
+            foreach ($message as $key => $value) {
22
+                $string .= '<li>' . ucfirst($value) . '</li>';
23
+            }
24
+            $string .= '</li>';
25
+        } else {
26
+            $string = ucfirst($message);
27
+        }
28
+        $alert = '<div class="alert alert-success alert-dismissible text-left fade show" role="alert">
29
+                    <strong>Success !</strong>
30
+                    ' . $string . '
31
+                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
32
+                        <span aria-hidden="true">&times;</span>
33
+                    </button>
34
+                </div>';
35
+        return $alert;
36
+    }
37
+
38
+
39
+       /**summernote */
40
+       public static function input_summernote($value)
41
+       {
42
+           libxml_use_internal_errors(true);
43
+           $dom = new \DomDocument();
44
+           $dom->loadHtml($value, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
45
+           $images = $dom->getElementsByTagName('img');
46
+
47
+           if (!empty($images)) {
48
+               foreach ($images as $k => $img) {
49
+                   $data = $img->getAttribute('src');
50
+                   list($type, $data) = explode(';', $data);
51
+                   list(, $data)      = explode(',', $data);
52
+                   $data = base64_decode($data);
53
+                   $image_name = "/summernote/images/" . Carbon::parse(NOW())->format('d-m-Y-His') . $k . '.png';
54
+                   $path = public_path() . $image_name;
55
+                   file_put_contents($path, $data);
56
+                   $img->removeAttribute('src');
57
+                   $img->setAttribute('src', $image_name);
58
+               }
59
+           }
60
+
61
+           $value = $dom->saveHTML();
62
+           return $value;
63
+       }
64
+
65
+    public static function parsing_alert($message)
66
+    {
67
+        $string = '';
68
+        if (is_array($message)) {
69
+            foreach ($message as $key => $value) {
70
+                $string .= ucfirst($value) . '<br>';
71
+            }
72
+        } else {
73
+            $string = ucfirst($message);
74
+        }
75
+        return $string;
76
+    }
77
+
78
+    public static function warning_alert($message)
79
+    {
80
+        $string = '';
81
+        if (is_array($message)) {
82
+
83
+            foreach ($message as $key => $value) {
84
+                $string .= '<li>' . ucfirst($value) . '</li>';
85
+            }
86
+            $string .= '</li>';
87
+        } else {
88
+            $string = ucfirst($message);
89
+        }
90
+        $alert = '<div class="alert alert-warning alert-dismissible fade show" role="alert">
91
+                    <strong>Warning !</strong> ' . $string . '
92
+                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
93
+                        <span aria-hidden="true">&times;</span>
94
+                    </button>
95
+                </div>';
96
+        return $alert;
97
+    }
98
+
99
+    public static function failed_alert($message)
100
+    {
101
+        $string = '';
102
+        if (is_array($message)) {
103
+            $string = '<ul class="m-0">';
104
+            foreach ($message as $key => $value) {
105
+                $string .= '<li>' . ucfirst($value) . '</li>';
106
+            }
107
+            $string .= '</li>';
108
+        } else {
109
+            $string = ucfirst($message);
110
+        }
111
+        $alert = '<div class="alert alert-danger alert-dismissible text-left fade show" role="alert">
112
+                    ' . $string . '
113
+                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
114
+                        <span aria-hidden="true">&times;</span>
115
+                    </button>
116
+                </div>';
117
+        return $alert;
118
+    }
119
+
120
+    public static function alert_fail($message)
121
+    {
122
+        $string = '';
123
+        if (is_array($message)) {
124
+            foreach ($message as $key => $value) {
125
+                $string .= ucfirst($value) . '<br>';
126
+            }
127
+        } else {
128
+            $string = ucfirst($message);
129
+        }
130
+        return $string;
131
+    }
132
+
133
+    public static function short_text($phrase, $max_words, $tanda_baca = null)
134
+    {
135
+
136
+        if ($tanda_baca != null) {
137
+            $phrase_array = explode($tanda_baca, $phrase);
138
+            if (count($phrase_array) > $max_words && $max_words > 0) {
139
+
140
+                $phrase = implode($tanda_baca, array_slice($phrase_array, 0, $max_words)) . '...';
141
+            }
142
+        } else {
143
+            $phrase_array = explode(' ', $phrase);
144
+            if (count($phrase_array) > $max_words && $max_words > 0) {
145
+
146
+                $phrase = implode(' ', array_slice($phrase_array, 0, $max_words)) . '...';
147
+            }
148
+        }
149
+
150
+        return $phrase;
151
+    }
152
+
153
+    /**
154
+     * cek jika dia super admin jangan dikasih user + permission
155
+     */
156
+    public static function get_permission_by_role()
157
+    {
158
+
159
+        $get_roles_user = Auth::user()->roles->pluck('id')->toArray();
160
+        /**1 = super admin */
161
+        if (in_array(1, $get_roles_user)) {
162
+            $permission = Permission::get();
163
+        } else {
164
+            $not_in = [
165
+                5, //permission-create
166
+                6, //permission-delete
167
+                7, //permission-update
168
+                8, //permission-list
169
+                9, //user-create
170
+                10, //user-delete
171
+                11, //user-update
172
+                12, //user-list
173
+            ];
174
+            $permission = Permission::whereNotIn('id', $not_in)
175
+                ->get();
176
+        }
177
+        return $permission;
178
+    }
179
+
180
+    public static function get_roles()
181
+    {
182
+        $get_roles_user = Auth::user()->roles->pluck('id')->toArray();
183
+        /**1 = super admin */
184
+        if (in_array(1, $get_roles_user)) {
185
+            $permission = Role::get();
186
+        } else {
187
+
188
+            $not_in = [1];
189
+            $permission = Role::whereNotIn('id', $not_in)
190
+                ->get();
191
+        }
192
+        return $permission;
193
+    }
194
+
195
+    public static function is_super_admin()
196
+    {
197
+        return Auth::user()->roles->where('id', 1)->first();
198
+    }
199
+    public static function format_date($date, $format)
200
+    {
201
+        $newDate = date($format, strtotime($date));
202
+        return $newDate;
203
+    }
204
+
205
+    public static function swal()
206
+    {
207
+        if (session('success')) {
208
+            alert()->html('', session('success'), 'success');
209
+        }
210
+
211
+        if (session('error')) {
212
+            alert()->html('', session('error'), 'error');
213
+        }
214
+
215
+        if (session('warning')) {
216
+            alert()->html('', session('warning'), 'warning');
217
+        }
218
+    }
219
+
220
+    /**Helper Enum */
221
+    public static function enum($value)
222
+    {
223
+        if ($value == 0) {
224
+            return 'Tidak';
225
+        } else if ($value == 1) {
226
+            return 'Ya';
227
+        }
228
+    }
229
+    /**end enum */
230
+
231
+    public static function declare_route()
232
+    {
233
+        $loader = require base_path('vendor/autoload.php');
234
+        $methods = [];
235
+        $route = [];
236
+        $classes = [];
237
+        // dd($loader->getClassMap());
238
+        foreach ($loader->getClassMap() as $class => $file) {
239
+            if (preg_match('/[a-z]+Controller$/', $class)) {
240
+                $reflection = new ReflectionClass($class);
241
+                // dd($reflection);
242
+                // exclude inherited methods
243
+                foreach ($reflection->getMethods() as $method)
244
+                    if ($method->class == $reflection->getName()) {
245
+
246
+                        $classes[] = $class;
247
+                        if ($method->name == 'route') {
248
+                            $methods[] = $method->name;
249
+                            $route[] = app(get_class(new $class))->route();
250
+                        }
251
+                    }
252
+            }
253
+        }
254
+        return $route;
255
+    }
256
+
257
+    public static function get_ip_user(){
258
+        $ipaddress = '';
259
+        if (getenv('HTTP_CLIENT_IP'))
260
+            $ipaddress = getenv('HTTP_CLIENT_IP');
261
+        else if(getenv('HTTP_X_FORWARDED_FOR'))
262
+            $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
263
+        else if(getenv('HTTP_X_FORWARDED'))
264
+            $ipaddress = getenv('HTTP_X_FORWARDED');
265
+        else if(getenv('HTTP_FORWARDED_FOR'))
266
+            $ipaddress = getenv('HTTP_FORWARDED_FOR');
267
+        else if(getenv('HTTP_FORWARDED'))
268
+        $ipaddress = getenv('HTTP_FORWARDED');
269
+        else if(getenv('REMOTE_ADDR'))
270
+            $ipaddress = getenv('REMOTE_ADDR');
271
+        else
272
+            $ipaddress = 'UNKNOWN';
273
+
274
+        return $ipaddress;
275
+    }
276
+
277
+    public static function Hash($value, $type='encode', $return_json=false)
278
+    {
279
+        $secret = getenv('HASH');
280
+        if ($type == 'encode') {
281
+            $return =  base64_encode($value.$secret);
282
+        }elseif ('decode') {
283
+            $return =  str_replace($secret, '', base64_decode($value));
284
+        }else{
285
+            $return = 'Wrong type hashing';
286
+        }
287
+        
288
+        if (!empty($return_json)) {
289
+            echo json_encode($return);
290
+        }else{
291
+            return $return;
292
+        }
293
+    }
294
+
295
+    public static function base64_to_image($string, $nama_module, $is_json=false)
296
+    {
297
+        $image = $string;  // your base64 encoded
298
+        $image = str_replace('data:image/png;base64,', '', $image);
299
+        $image = str_replace(' ', '+', $image);
300
+        $imageName = str_random(10).'.'.'png';
301
+        \File::put(storage_path(). '/images/'. $nama_module . '/' . $imageName, base64_decode($image));
302
+
303
+        $return = URL::to('storage/images/'. $nama_module . '/' . $imageName);
304
+        
305
+        if (!empty($return_json)) {
306
+            echo json_encode($return);
307
+        }else{
308
+            return $return;
309
+        }
310
+    }
311
+
312
+}

+ 96
- 0
app/Http/Controllers/Admin/DashboardController.php Dosyayı Görüntüle

@@ -0,0 +1,96 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Admin;
4
+
5
+use App\Helpers\Helper;
6
+use App\Http\Controllers\Controller;
7
+
8
+use Illuminate\Support\Facades\DB;
9
+//modal
10
+;
11
+use Carbon\Carbon;
12
+use Illuminate\Support\Str;
13
+use Auth;
14
+
15
+//UTILS
16
+use App\Utils\DashboardUtil;
17
+
18
+//MODEL
19
+use App\Model\Logistik\ManajemenKantong;
20
+use App\Model\Master\Reagen;
21
+use App\Model\Master\ItemKantongs;
22
+use App\Model\Master\MasterJenisKantong;
23
+use App\Model\Master\MerkReagen;
24
+use App\Model\Master\Reagens;
25
+use GuzzleHttp\Psr7\Request;
26
+
27
+class DashboardController extends Controller
28
+{
29
+    /**
30
+     * Title untuk judul di web
31
+     * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
32
+     */
33
+    private $title = 'Admin';
34
+    private $route = 'admin.dashboard.'; //path awal foldernya ajah
35
+    protected $DashboardUtil;
36
+    public function __construct(DashboardUtil $DashboardUtil)
37
+    {
38
+        $this->DashboardUtil = $DashboardUtil;
39
+        DB::enableQueryLog();
40
+    }
41
+
42
+    public function index()
43
+    {
44
+        // $petugas_udd_id                 = Auth::user()->petugas->unit_donor_darah_id;
45
+        // $kantongLogistik_last_30_days   = ManajemenKantong::getData30Days($status_kantongs = 1, $status_kantong_item = 1, $petugas_udd_id, $param_order = 'created_at', $imltd = null, $kgd = null);
46
+        // $kantongAftap_last_30_days      = ManajemenKantong::getData30Days($status_kantongs = 1, $status_kantong_item = 2, $petugas_udd_id, $param_order = 'created_at', $imltd = null, $kgd = null);
47
+        // $kantongBelumImltd_last_30_days = ManajemenKantong::getData30Days($status_kantongs = 3, $status_kantong_item = 3, $petugas_udd_id, $param_order = 'updated_at', $imltd = 'is_lulus_imltd', $kgd = null);
48
+        // $kantongBelumKgd_last_30_days   = ManajemenKantong::getData30Days($status_kantongs = 3, $status_kantong_item = 3, $petugas_udd_id, $param_order = 'updated_at', $imltd = null, $kgd = 'is_konfirmasi_golongan_darah');
49
+        // $kantongRelease_last_1_years    = $this->DashboardUtil->getDataLast1Years(9, $petugas_udd_id, 'updated_at');                                                                                                            //param, status id 9 release
50
+
51
+        // $kantongLogistik   = ManajemenKantong::getKantong($status_kantongs = 1,$status_kantong_item = 1, $petugas_udd_id, $imtld = null, $kgd = null);
52
+        // $kantongAftap      =  ManajemenKantong::where('kantong_items.status_id', '=', 2)
53
+        //                         ->where('kantong_items.is_pemindahan_aftap', '=', 1)
54
+        //                         ->where('kantongs.status_id', '=', 1)
55
+        //                         ->where('kantong_items.unit_donor_darah_id', Auth::user()->petugas->unit_donor_darah_id)
56
+        //                         ->join('kantong_items', 'kantongs.id', 'kantong_items.kantong_id')
57
+        //                         ->groupBy('kantong_id')
58
+        //                         ->get();
59
+        // $kantongBelumImltd =  ItemKantongs::selectRaw('
60
+        //                     kantong_items.id,
61
+        //                     kantong_items.no_kantong,
62
+        //                     kantong_items.kantong_id
63
+        //                     ')
64
+        //                     ->leftjoin('hasil_imltds', 'hasil_imltds.kantong_item_id','=','kantong_items.id')
65
+        //                     ->join('kantongs', 'kantongs.id','kantong_items.kantong_id')
66
+        //                     ->where('hasil_imltds.id',null)
67
+        //                     ->where('kantongs.status_id',3)
68
+        //                     ->where('kantong_items.is_sah', 1 )
69
+        //                     ->whereNull('is_lulus_imltd')
70
+        //                     ->where('kantong_items.unit_donor_darah_id', Auth::user()->petugas->unit_donor_darah_id)
71
+        //                     ->groupBy('kantong_items.kantong_id')->orderBy('kantong_items.created_at', 'asc')->get();
72
+        // $kantongBelumKgd   = ManajemenKantong::getKantong($status_kantongs = 3,$status_kantong_item = null, $petugas_udd_id, $imltd = null, $kgd = 'is_konfirmasi_golongan_darah');
73
+        // $belum_aftap       = ManajemenKantong::getKantong($status_kantongs = 1,$status_kantong_item = 11, $petugas_udd_id, $imltd = null, $kgd = null);
74
+
75
+        $data = [
76
+            //bawaan
77
+            'title'             => $this->title,
78
+            'route'             => $this->route,
79
+            // 'kantongLogistik'   => count($kantongLogistik),
80
+            // 'kantongAftap'      => count($kantongAftap),
81
+            // 'kantongBelumImltd' => count($kantongBelumImltd),
82
+            // 'kantongBelumKgd'   => count($kantongBelumKgd),
83
+            // 'count_logistik'    => $kantongLogistik,
84
+            // 'count_aftap'       => $kantongAftap,
85
+            // 'belum_aftap'       => $belum_aftap,
86
+            // 'jenis_kantong'     => MasterJenisKantong::All(),
87
+            // 'master_reagen'     => Reagen::where('unit_donor_darah_id', Auth::user()->petugas->unit_donor_darah_id)->get(),
88
+            // 'reagens'           => Reagens::where('reagens.unit_donor_darah_id', Auth::user()->petugas->unit_donor_darah_id)
89
+            //                     ->join('master_reagens', 'reagens.master_reagen_id', 'master_reagens.id')
90
+            //                     ->get(),
91
+            // 'merk_reagen' => MerkReagen::all(),
92
+        ];
93
+        // dd($data['reagens']);
94
+        return view($this->route . 'index', $data);
95
+    }
96
+}

+ 433
- 0
app/Http/Controllers/Admin/Raharja/EventOrganisasiController.php Dosyayı Görüntüle

@@ -0,0 +1,433 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Admin\Raharja;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use Illuminate\Http\Request;
8
+use App\Helpers\Helper;
9
+use App\Model\Raharja\EventOrganisasi;
10
+use App\Model\Raharja\EventOrganisasiMembers;
11
+use App\Model\Raharja\KelompokDriver;
12
+use App\Model\Raharja\Tips;
13
+use Yajra\Datatables\Datatables;
14
+use Auth;
15
+use Carbon\Carbon;
16
+use Illuminate\Support\Facades\Storage;
17
+use Validator;
18
+use Hashids;
19
+
20
+//load modelmu
21
+class EventOrganisasiController extends Controller
22
+{
23
+    /**
24
+     * Title untuk judul di web
25
+     * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
26
+     */
27
+    private $title      = 'Event Organisasi';                 /**jangan lupa diganti*/
28
+    private $route      = 'admin.event-organisasi.';          //path awal foldernya ajah (misal folder di admin/dashboard) => 'admin.dashboard' | jangan lupa diganti
29
+    private $header     = 'Event Organisasi';
30
+    private $sub_header = 'Event Organisasi';
31
+    private $url        = 'admin.raharja.event_organisasi.';
32
+
33
+    public function __construct()
34
+    {
35
+        DB::enableQueryLog();
36
+        /** nyalakan jika sudah set rolenya, jika ini dinyalakan halaman ini tidak akan keluar */
37
+    }
38
+
39
+
40
+    public function index()
41
+    {
42
+        Helper::swal();
43
+
44
+        $data = [
45
+            //bawaan
46
+            'title'      => $this->title,
47
+            'route'      => $this->route,
48
+            'header'     => $this->header,
49
+            'sub_header' => $this->sub_header,
50
+        ];
51
+
52
+        return view($this->url . 'index', $data);
53
+    }
54
+    public function getData($udd_id = null)
55
+    {
56
+        $query = EventOrganisasi::query();
57
+
58
+        return Datatables::of($query)
59
+            ->addIndexColumn()
60
+            ->addColumn('start', function($query){
61
+                return Carbon::parse($query->start_date)->format('Y-m-d');
62
+            })
63
+            ->addColumn('end', function($query){
64
+                return Carbon::parse($query->end_date)->format('Y-m-d');
65
+            })
66
+            ->addColumn('aksi', function ($query) {
67
+
68
+                /**cek role */
69
+                $aksi = '';
70
+                $aksi .= "<a href='" . route($this->route . 'update', ['data_id' => Hashids::encode($query->id)]) . "' class='btn btn-sm btn-primary btn-edit'>Edit</a>";
71
+                $aksi .= "<a href='" . route($this->route . 'kelompok_driver', ['data_id' => Hashids::encode($query->id)]) . "' class='btn btn-sm btn-warning btn-edit'>Kelompok Driver</a>";
72
+                $aksi .= "<a href='javascript:;' data-route='" . route($this->route . 'delete_action', ['data_id' => Hashids::encode($query->id)]) . "' class='btn btn-danger btn-sm btn-delete'>Delete</a>";
73
+                return $aksi;
74
+            })
75
+            ->rawColumns(['aksi'])
76
+            ->toJson();
77
+    }
78
+    public function create()
79
+    {
80
+        $data = [
81
+            //bawaan
82
+            'title'         => $this->title,
83
+            'route'         => $this->route,
84
+            'header'        => $this->header,
85
+            'sub_header'    => $this->sub_header,
86
+
87
+        ];
88
+
89
+        Helper::swal();
90
+
91
+        return view($this->url . 'create', $data);
92
+    }
93
+
94
+    public function create_action(Request $request)
95
+    {
96
+        //declare post untuk simpan semua request yang diinputkan oleh form name=""
97
+        $post = $request->all();
98
+        $file = $request->file('banner');
99
+
100
+        /**digunakan untuk set rule validator */
101
+        $rules = [
102
+            'banner'     => 'required|file|max:1000',
103
+            'start_date' => 'required',
104
+            'end_date'   => 'required',
105
+            'deskripsi'  => 'required',
106
+        ];
107
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
108
+        $alert = [
109
+            'file'  => 'File maksimal 1MB'
110
+        ];
111
+        $validator = Validator::make($post, $rules, $alert);
112
+
113
+        if ($validator->passes()) {
114
+            /**menggunakan transaction */
115
+            DB::beginTransaction();
116
+
117
+            $nama_file = time()."_".$file->getClientOriginalName();
118
+
119
+            Storage::putFileAs('public/images/event_organisasi/', $file, $nama_file );
120
+
121
+            $query             = new EventOrganisasi();
122
+            $query->start_date = $request->start_date;
123
+            $query->end_date   = $request->end_date;
124
+            $query->deskripsi  = $request->deskripsi;
125
+            $query->banner     = $nama_file;
126
+            $query->save();
127
+
128
+            if ($query) {
129
+                DB::commit();
130
+                $message = 'Berhasil';
131
+                return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
132
+            } else {
133
+                DB::rollback();
134
+                $message = 'Gagal';
135
+                return redirect()->back()->with('error', Helper::parsing_alert($message));
136
+            }
137
+        }
138
+        /**kenapa menggunakan back ? karena baliknya pasti ke halaman sebelumnya */
139
+        $message = Helper::parsing_alert($validator->errors()->all());
140
+        return redirect()->back()->with('error', $message)->withInput();
141
+    }
142
+
143
+    public function update($data_id)
144
+    {
145
+
146
+        Helper::swal();
147
+
148
+
149
+        $data_id = Hashids::decode($data_id);
150
+        if (!empty($data_id)) {
151
+
152
+            $cek_data = EventOrganisasi::where('id', $data_id[0])->first();
153
+
154
+            if ($cek_data) {
155
+                $data = [
156
+                    //bawaan
157
+                    'title'         => $this->title,
158
+                    'route'         => $this->route,
159
+                    'header'        => $this->header,
160
+                    'sub_header'    => $this->sub_header,
161
+                    'data'          => $cek_data
162
+                ];
163
+                return view($this->url . 'update', $data);
164
+            }
165
+            $message = 'Id tidak ditemukan atau sudah dihapus';
166
+            return redirect()->back()->with('error', $message);
167
+        }
168
+        $message = 'Id tdak ditemukan';
169
+        return redirect()->back()->with('error', $message);
170
+    }
171
+
172
+    public function update_action(Request $request)
173
+    {
174
+        $post = $request->all();
175
+       /**digunakan untuk set rule validator */
176
+        $rules = [
177
+            'banner'     => 'file|max:1000',
178
+            'start_date' => 'required',
179
+            'end_date'   => 'required',
180
+            'deskripsi'  => 'required',
181
+        ];
182
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
183
+        $alert = [];
184
+        $validator = Validator::make($post, $rules, $alert);
185
+
186
+        $data_id = Hashids::decode($request['id']);
187
+
188
+        if (!empty($data_id)) {
189
+            /**cek apakah data_idnya ada ? */
190
+            $query = EventOrganisasi::find($data_id[0]);
191
+
192
+            if ($query) {
193
+                /**cek apakah id data benar" ada di DB ? */
194
+                if ($validator->passes()) {
195
+                    /**validatornya */
196
+                    DB::beginTransaction();
197
+                    $file = $request->file('banner');
198
+                    if($file){
199
+                        $nama_file = time()."_".$file->getClientOriginalName();
200
+
201
+                        Storage::putFileAs('public/images/event_organisasi/', $file, $nama_file );
202
+
203
+                        Storage::delete('public/images/event_organisasi/'.$query->thumbnail);
204
+                        $query->banner = $nama_file;
205
+                    }
206
+
207
+                    $query->start_date = $request->start_date;
208
+                    $query->end_date   = $request->end_date;
209
+                    $query->deskripsi  = $request->deskripsi;
210
+                    $query->save();
211
+
212
+                    if ($query) {
213
+                        DB::commit();
214
+                        $message = 'Berhasil';
215
+                        return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
216
+                    } else {
217
+                        DB::rollback();
218
+                        $message = 'Gagal';
219
+                        return redirect()->back()->with('error', Helper::parsing_alert($message));
220
+                    }
221
+                }
222
+
223
+                $message = Helper::parsing_alert($validator->errors()->all());
224
+
225
+                return redirect()->back()->with('error', $message);
226
+            } else {
227
+                $message = 'Id tdak ditemukan';
228
+                return redirect()->back()->with('error', $message);
229
+            }
230
+        } else {
231
+            $message = 'Id tidak boleh kosong';
232
+            return redirect()->back()->with('error', $message);
233
+        }
234
+    }
235
+
236
+    public function delete_action($id_modelmu)
237
+    {
238
+        $id = Hashids::decode($id_modelmu);
239
+        /**cek idnya apakah ada ? */
240
+
241
+        if (!empty($id)) {
242
+
243
+            $cek_data = EventOrganisasi::find($id[0]);
244
+
245
+            if ($cek_data) {
246
+                DB::beginTransaction();
247
+                try {
248
+                    $arr_member = $cek_data->kelompokMember;
249
+                    foreach($arr_member as $like){
250
+                        $like->delete();
251
+                    }
252
+
253
+                    Storage::delete('public/images/event_organisasi/'.$cek_data->thumbnail);
254
+                    $delete = $cek_data->delete();
255
+
256
+                    DB::commit();
257
+                    $message = 'Sukses';
258
+                    $response = [
259
+                        'message' => $message,
260
+                        'status'   => true,
261
+                    ];
262
+                    return response()->json($response);
263
+                } catch (Exception $e) {
264
+                    DB::rollback();
265
+                    $message = 'Gagal';
266
+                    $response = [
267
+                        'message' => $message,
268
+                        'status'   => false,
269
+                    ];
270
+                    return response()->json($response);
271
+                }
272
+            }
273
+            $message = 'Id tidak ditemukan atau sudah dihapus';
274
+            $response = [
275
+                'message' => $message,
276
+                'status'   => false,
277
+            ];
278
+            return response()->json($response);
279
+        }
280
+        $message = 'Id tdak ditemukan';
281
+        $response = [
282
+            'message' => $message,
283
+            'status'   => false,
284
+        ];
285
+        return response()->json($response);
286
+    }
287
+
288
+
289
+    public function kelompokDriver($data_id)
290
+    {
291
+
292
+        Helper::swal();
293
+
294
+
295
+        $data_id = Hashids::decode($data_id);
296
+        if (!empty($data_id)) {
297
+
298
+            $cek_data = EventOrganisasi::where('id', $data_id[0])->first();
299
+
300
+            if ($cek_data) {
301
+                $data = [
302
+                    //bawaan
303
+                    'title'          => $this->title,
304
+                    'route'          => $this->route,
305
+                    'header'         => $this->header,
306
+                    'sub_header'     => $this->sub_header,
307
+                    'data'           => $cek_data,
308
+                    'route_get_data' => route($this->route . 'get_data_kelompok_driver', ['data_id' => $cek_data->id]),
309
+                ];
310
+                return view($this->url . 'kelompok_driver_member', $data);
311
+            }
312
+            $message = 'Id tidak ditemukan atau sudah dihapus';
313
+            return redirect()->back()->with('error', $message);
314
+        }
315
+        $message = 'Id tdak ditemukan';
316
+        return redirect()->back()->with('error', $message);
317
+    }
318
+
319
+    public function getDataKelompokDriver($data_id){
320
+
321
+        $query = EventOrganisasiMembers::where('event_organisasi_id', $data_id);
322
+
323
+        return Datatables::of($query)
324
+            ->addIndexColumn()
325
+            ->addColumn('nama', function ($query){
326
+                return $query->kelompokDriver->nama;
327
+            })
328
+            ->filterColumn('nama', function($query, $keyword) {
329
+
330
+                $query->whereHas('kelompokDriver', function ($sub) use ($keyword) {
331
+                    $sub->where('nama', 'like', '%' . $keyword . '%');
332
+                });;
333
+            })
334
+            ->addColumn('aksi', function ($query) {
335
+
336
+                /**cek role */
337
+                $aksi = '';
338
+                    $aksi .= "<a href='javascript:;' data-route='" . route($this->route . 'delete_kelompok_driver', ['data_id' => Hashids::encode($query->id)]) . "' class='btn btn-danger btn-sm btn-delete'>Delete</a>";
339
+                return $aksi;
340
+            })
341
+            ->rawColumns(['aksi'])
342
+            ->toJson();
343
+    }
344
+
345
+    public function deleteKelompokDriver($data_id){
346
+        $id = Hashids::decode($data_id);
347
+        /**cek idnya apakah ada ? */
348
+
349
+        if (!empty($id)) {
350
+
351
+            $cek_data = EventOrganisasiMembers::find($id[0]);
352
+
353
+            if ($cek_data) {
354
+                DB::beginTransaction();
355
+                try {
356
+                    $delete = $cek_data->delete();
357
+
358
+                    DB::commit();
359
+                    $message = 'Sukses';
360
+                    $response = [
361
+                        'message' => $message,
362
+                        'status'   => true,
363
+                    ];
364
+                    return response()->json($response);
365
+                } catch (Exception $e) {
366
+                    DB::rollback();
367
+                    $message = 'Gagal';
368
+                    $response = [
369
+                        'message' => $message,
370
+                        'status'   => false,
371
+                    ];
372
+                    return response()->json($response);
373
+                }
374
+            }
375
+            $message = 'Id tidak ditemukan atau sudah dihapus';
376
+            $response = [
377
+                'message' => $message,
378
+                'status'   => false,
379
+            ];
380
+            return response()->json($response);
381
+        }
382
+        $message = 'Id tdak ditemukan';
383
+        $response = [
384
+            'message' => $message,
385
+            'status'   => false,
386
+        ];
387
+        return response()->json($response);
388
+    }
389
+
390
+    public function selectKelompokDriver(Request $request){
391
+        if (session('error')) {
392
+            alert()->html('', session('error'), 'error');
393
+        }
394
+
395
+        $term = trim($request['nama']);
396
+        $arr_organisasi = EventOrganisasiMembers::where('event_organisasi_id', $request['e_o_id'])->get()->pluck('kelompok_driver_id')->toArray();
397
+        $kelompok_driver = KelompokDriver::whereNotIn('id', $arr_organisasi)->take(10);
398
+
399
+        if (!empty($request['not_in'])) {
400
+            $id = collect($request['not_in']);
401
+            $kelompok_driver = $kelompok_driver->whereNotIn('id', $id);
402
+        }
403
+        if (!empty($term)) {
404
+            $kelompok_driver = $kelompok_driver->where('nama', 'like', '%' . $term . '%');
405
+        }
406
+        $kelompok_driver = $kelompok_driver->get();
407
+        $response = [];
408
+
409
+        foreach ($kelompok_driver as $key => $value) {
410
+            $response[] = ['id' => $value->id, 'text' => $value->nama ];
411
+        }
412
+
413
+        return response()->json($response);
414
+    }
415
+
416
+    public function addKelompokDriver(Request $request){
417
+
418
+        $query                      = new EventOrganisasiMembers();
419
+        $query->event_organisasi_id = $request->organisasi_id;
420
+        $query->kelompok_driver_id  = $request->kelompok_driver_id;
421
+        $query->save();
422
+
423
+        if ($query) {
424
+            DB::commit();
425
+            $message = 'Berhasil';
426
+            return redirect(route($this->route . 'kelompok_driver',['data_id' => Hashids::encode($request->organisasi_id)]))->with('success', Helper::parsing_alert($message));
427
+        } else {
428
+            DB::rollback();
429
+            $message = 'Gagal';
430
+            return redirect()->back()->with('error', Helper::parsing_alert($message));
431
+        }
432
+    }
433
+}

+ 268
- 0
app/Http/Controllers/Admin/Raharja/KelompokDriverController.php Dosyayı Görüntüle

@@ -0,0 +1,268 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Admin\Raharja;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use Illuminate\Http\Request;
8
+use App\Helpers\Helper;
9
+use App\Model\Raharja\KelompokDriver;
10
+use Yajra\Datatables\Datatables;
11
+use Auth;
12
+use Illuminate\Support\Facades\Storage;
13
+use Validator;
14
+use Hashids;
15
+
16
+//load modelmu
17
+class KelompokDriverController extends Controller
18
+{
19
+    /**
20
+     * Title untuk judul di web
21
+     * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
22
+     */
23
+    private $title      = 'Kelompok Driver';                 /**jangan lupa diganti*/
24
+    private $route      = 'admin.kelompok-driver.';          //path awal foldernya ajah (misal folder di admin/dashboard) => 'admin.dashboard' | jangan lupa diganti
25
+    private $header     = 'Kelompok Driver';
26
+    private $sub_header = 'Kelompok Driver';
27
+    private $url        = 'admin.raharja.kelompok_driver.';
28
+
29
+    public function __construct()
30
+    {
31
+        DB::enableQueryLog();
32
+    }
33
+
34
+
35
+    public function index()
36
+    {
37
+        Helper::swal();
38
+
39
+        $data = [
40
+            //bawaan
41
+            'title'      => $this->title,
42
+            'route'      => $this->route,
43
+            'header'     => $this->header,
44
+            'sub_header' => $this->sub_header,
45
+        ];
46
+
47
+        return view($this->url . 'index', $data);
48
+    }
49
+    public function getData($udd_id = null)
50
+    {
51
+        $query = KelompokDriver::query();
52
+
53
+        return Datatables::of($query)
54
+            ->addIndexColumn()
55
+            ->addColumn('aksi', function ($query) {
56
+
57
+                /**cek role */
58
+                $aksi = '';
59
+                $aksi .= "<a href='" . route($this->route . 'update', ['data_id' => Hashids::encode($query->id)]) . "' class='btn btn-sm btn-primary btn-edit'>Edit</a>";
60
+                $aksi .= "<a href='javascript:;' data-route='" . route($this->route . 'delete_action', ['data_id' => Hashids::encode($query->id)]) . "' class='btn btn-danger btn-sm btn-delete'>Delete</a>";
61
+                return $aksi;
62
+            })
63
+            ->rawColumns(['aksi'])
64
+            ->toJson();
65
+    }
66
+    public function create()
67
+    {
68
+        $data = [
69
+            //bawaan
70
+            'title'         => $this->title,
71
+            'route'         => $this->route,
72
+            'header'        => $this->header,
73
+            'sub_header'    => $this->sub_header,
74
+
75
+        ];
76
+
77
+        Helper::swal();
78
+
79
+        return view($this->url . 'create', $data);
80
+    }
81
+
82
+    public function create_action(Request $request)
83
+    {
84
+        //declare post untuk simpan semua request yang diinputkan oleh form name=""
85
+        $post = $request->all();
86
+        $file = $request->file('logo');
87
+
88
+        /**digunakan untuk set rule validator */
89
+        $rules = [
90
+            'logo'      => 'required|file|max:1000',
91
+            'nama'      => 'required',
92
+            'website'   => 'required',
93
+            'deskripsi' => 'required',
94
+        ];
95
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
96
+        $alert = [
97
+            'file'  => 'File maksimal 1MB'
98
+        ];
99
+        $validator = Validator::make($post, $rules, $alert);
100
+
101
+        if ($validator->passes()) {
102
+            /**menggunakan transaction */
103
+            DB::beginTransaction();
104
+
105
+            $nama_file = time()."_".$file->getClientOriginalName();
106
+
107
+            Storage::putFileAs('public/images/kelompok_driver/', $file, $nama_file );
108
+
109
+            $query            = new KelompokDriver();
110
+            $query->logo      = $nama_file;
111
+            $query->nama      = $request->nama;
112
+            $query->website   = $request->website;
113
+            $query->deskripsi = $request->deskripsi;
114
+            $query->save();
115
+
116
+            if ($query) {
117
+                DB::commit();
118
+                $message = 'Berhasil';
119
+                return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
120
+            } else {
121
+                DB::rollback();
122
+                $message = 'Gagal';
123
+                return redirect()->back()->with('error', Helper::parsing_alert($message));
124
+            }
125
+        }
126
+        /**kenapa menggunakan back ? karena baliknya pasti ke halaman sebelumnya */
127
+        $message = Helper::parsing_alert($validator->errors()->all());
128
+        return redirect()->back()->with('error', $message)->withInput();
129
+    }
130
+
131
+    public function update($data_id)
132
+    {
133
+
134
+        Helper::swal();
135
+
136
+
137
+        $data_id = Hashids::decode($data_id);
138
+        if (!empty($data_id)) {
139
+
140
+            $cek_data = KelompokDriver::where('id', $data_id[0])->first();
141
+
142
+            if ($cek_data) {
143
+                $data = [
144
+                    //bawaan
145
+                    'title'         => $this->title,
146
+                    'route'         => $this->route,
147
+                    'header'        => $this->header,
148
+                    'sub_header'    => $this->sub_header,
149
+                    'data'          => $cek_data
150
+                ];
151
+                return view($this->url . 'update', $data);
152
+            }
153
+            $message = 'Id tidak ditemukan atau sudah dihapus';
154
+            return redirect()->back()->with('error', $message);
155
+        }
156
+        $message = 'Id tdak ditemukan';
157
+        return redirect()->back()->with('error', $message);
158
+    }
159
+
160
+    public function update_action(Request $request)
161
+    {
162
+        $post = $request->all();
163
+       /**digunakan untuk set rule validator */
164
+        $rules = [
165
+            'logo'      => 'file|max:1000',
166
+            'nama'      => 'required',
167
+            'website'   => 'required',
168
+            'deskripsi' => 'required',
169
+        ];
170
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
171
+        $alert = [];
172
+        $validator = Validator::make($post, $rules, $alert);
173
+
174
+        $data_id = Hashids::decode($request['id']);
175
+
176
+        if (!empty($data_id)) {
177
+            /**cek apakah data_idnya ada ? */
178
+            $query = KelompokDriver::find($data_id[0]);
179
+
180
+            if ($query) {
181
+                /**cek apakah id data benar" ada di DB ? */
182
+                if ($validator->passes()) {
183
+                    /**validatornya */
184
+                    DB::beginTransaction();
185
+                    $file = $request->file('logo');
186
+                    if($file){
187
+                        $nama_file = time()."_".$file->getClientOriginalName();
188
+                        Storage::putFileAs('public/images/kelompok_driver/', $file, $nama_file );
189
+                        Storage::delete('public/images/kelompok_driver/'.$query->logo);
190
+                        $query->logo = $nama_file;
191
+                    }
192
+
193
+                    $query->nama      = $request->nama;
194
+                    $query->website   = $request->website;
195
+                    $query->deskripsi = $request->deskripsi;
196
+                    $query->save();
197
+
198
+                    if ($query) {
199
+                        DB::commit();
200
+                        $message = 'Berhasil';
201
+                        return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
202
+                    } else {
203
+                        DB::rollback();
204
+                        $message = 'Gagal';
205
+                        return redirect()->back()->with('error', Helper::parsing_alert($message));
206
+                    }
207
+                }
208
+
209
+                $message = Helper::parsing_alert($validator->errors()->all());
210
+
211
+                return redirect()->back()->with('error', $message);
212
+            } else {
213
+                $message = 'Id tdak ditemukan';
214
+                return redirect()->back()->with('error', $message);
215
+            }
216
+        } else {
217
+            $message = 'Id tidak boleh kosong';
218
+            return redirect()->back()->with('error', $message);
219
+        }
220
+    }
221
+
222
+    public function delete_action($id_modelmu)
223
+    {
224
+        $id = Hashids::decode($id_modelmu);
225
+        /**cek idnya apakah ada ? */
226
+
227
+        if (!empty($id)) {
228
+
229
+            $cek_data = KelompokDriver::find($id[0]);
230
+
231
+            if ($cek_data) {
232
+                DB::beginTransaction();
233
+                try {
234
+                    Storage::delete('public/images/kelompok_driver/'.$cek_data->logo);
235
+                    $delete = $cek_data->delete();
236
+                    DB::commit();
237
+                    $message = 'Sukses';
238
+                    $response = [
239
+                        'message' => $message,
240
+                        'status'   => true,
241
+                    ];
242
+                    return response()->json($response);
243
+                } catch (Exception $e) {
244
+                    DB::rollback();
245
+                    $message = 'Gagal';
246
+                    $response = [
247
+                        'message' => $message,
248
+                        'status'   => false,
249
+                    ];
250
+                    return response()->json($response);
251
+                }
252
+            }
253
+            $message = 'Id tidak ditemukan atau sudah dihapus';
254
+            $response = [
255
+                'message' => $message,
256
+                'status'   => false,
257
+            ];
258
+            return response()->json($response);
259
+        }
260
+        $message = 'Id tdak ditemukan';
261
+        $response = [
262
+            'message' => $message,
263
+            'status'   => false,
264
+        ];
265
+        return response()->json($response);
266
+    }
267
+
268
+}

+ 266
- 0
app/Http/Controllers/Admin/Raharja/MasterPointsController.php Dosyayı Görüntüle

@@ -0,0 +1,266 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Admin\Raharja;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use Illuminate\Http\Request;
8
+use App\Helpers\Helper;
9
+use App\Model\Points;
10
+use Yajra\Datatables\Datatables;
11
+use Auth;
12
+use Illuminate\Support\Facades\Storage;
13
+use Validator;
14
+use Hashids;
15
+
16
+//load modelmu
17
+class MasterPointsController extends Controller
18
+{
19
+    /**
20
+     * Title untuk judul di web
21
+     * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
22
+     */
23
+    private $title      = 'Master Points';                 /**jangan lupa diganti*/
24
+    private $route      = 'admin.master-points.';          //path awal foldernya ajah (misal folder di admin/dashboard) => 'admin.dashboard' | jangan lupa diganti
25
+    private $header     = 'Points';
26
+    private $sub_header = 'Points';
27
+    private $url        = 'admin.raharja.master_points.';
28
+
29
+     public function __construct()
30
+    {
31
+        DB::enableQueryLog();
32
+        /** nyalakan jika sudah set rolenya, jika ini dinyalakan halaman ini tidak akan keluar */
33
+        // $this->middleware('permission:searching-list|searching-create|searching-update|searching-delete', ['only' => ['index', 'create', 'update']]);
34
+        // $this->middleware('permission:searching-create', ['only' => ['create', 'create_action']]);
35
+        // $this->middleware('permission:searching-update', ['only' => ['update', 'update_action']]);
36
+        // $this->middleware('permission:searching-delete', ['only' => ['delete']]);
37
+    }
38
+
39
+     /**
40
+    * Ini contoh crud yang sudah jalan
41
+    * index digunakna untuk tampilan awal dari menu yang akan dibuat
42
+    * Untuk CRUD Biar cepat
43
+    * Silahkan ganti
44
+    * EloquentMu:: => dengan model anda
45
+    * $id_modelmu => ganti dengan id di model anda
46
+    * id_di_routenya => jangan lupa disesuaikan dengan yang dideclare di route
47
+    */
48
+
49
+
50
+    public function index()
51
+    {
52
+        Helper::swal();
53
+
54
+        $data = [
55
+            //bawaan
56
+            'title'      => $this->title,
57
+            'route'      => $this->route,
58
+            'header'     => $this->header,
59
+            'sub_header' => $this->sub_header,
60
+        ];
61
+        // dd($data);
62
+        return view($this->url . 'index', $data);
63
+    }
64
+    public function getData($udd_id = null)
65
+    {
66
+        $query = Points::query();
67
+
68
+        return Datatables::of($query)
69
+            ->addIndexColumn()
70
+            ->addColumn('aksi', function ($query) {
71
+
72
+                /**cek role */
73
+                $aksi = '';
74
+                // if (Auth::user()->can('master-jenis-kantong-update')) {
75
+                    $aksi .= "<a href='" . route($this->route . 'update', ['news_id' => Hashids::encode($query->id)]) . "' class='btn btn-sm btn-primary btn-edit'>Edit</a>";
76
+                // }
77
+
78
+                // if (Auth::user()->can('master-jenis-kantong-delete')) {
79
+                    $aksi .= "<a href='javascript:;' data-route='" . route($this->route . 'delete_action', ['news_id' => Hashids::encode($query->id)]) . "' class='btn btn-danger btn-sm btn-delete'>Delete</a>";
80
+                // }
81
+                return $aksi;
82
+            })
83
+            ->rawColumns(['aksi'])
84
+            ->toJson();
85
+    }
86
+    public function create()
87
+    {
88
+        $data = [
89
+            //bawaan
90
+            'title'         => $this->title,
91
+            'route'         => $this->route,
92
+            'header'        => $this->header,
93
+            'sub_header'    => $this->sub_header,
94
+
95
+        ];
96
+
97
+        Helper::swal();
98
+
99
+        return view($this->url . 'create', $data);
100
+    }
101
+
102
+    public function create_action(Request $request)
103
+    {
104
+        //declare post untuk simpan semua request yang diinputkan oleh form name=""
105
+        $post = $request->all();
106
+        //dd($post);
107
+        /**digunakan untuk set rule validator */
108
+        $rules = [
109
+            'type'   => 'required',
110
+            'value' => 'required',
111
+        ];
112
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
113
+
114
+        $validator = Validator::make($post, $rules);
115
+
116
+        if ($validator->passes()) {
117
+            /**menggunakan transaction */
118
+            DB::beginTransaction();
119
+
120
+            $query            = new Points();
121
+            $query->type     = $request->type;
122
+            $query->value   = $request->value;
123
+            $query->save();
124
+
125
+            if ($query) {
126
+                DB::commit();
127
+                $message = 'Berhasil';
128
+                return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
129
+            } else {
130
+                DB::rollback();
131
+                $message = 'Gagal';
132
+                return redirect()->back()->with('error', Helper::parsing_alert($message));
133
+            }
134
+        }
135
+        /**kenapa menggunakan back ? karena baliknya pasti ke halaman sebelumnya */
136
+        $message = Helper::parsing_alert($validator->errors()->all());
137
+        return redirect()->back()->with('error', $message)->withInput();
138
+    }
139
+
140
+    public function update($data_id)
141
+    {
142
+
143
+        Helper::swal();
144
+
145
+
146
+        $data_id = Hashids::decode($data_id);
147
+        if (!empty($data_id)) {
148
+
149
+            $cek_data = Points::where('id', $data_id[0])->first();
150
+
151
+            if ($cek_data) {
152
+                $data = [
153
+                    //bawaan
154
+                    'title'         => $this->title,
155
+                    'route'         => $this->route,
156
+                    'header'        => $this->header,
157
+                    'sub_header'    => $this->sub_header,
158
+                    'data'          => $cek_data
159
+                ];
160
+                return view($this->url . 'update', $data);
161
+            }
162
+            $message = 'Id tidak ditemukan atau sudah dihapus';
163
+            return redirect()->back()->with('error', $message);
164
+        }
165
+        $message = 'Id tdak ditemukan';
166
+        return redirect()->back()->with('error', $message);
167
+    }
168
+
169
+    public function update_action(Request $request)
170
+    {
171
+        $post = $request->all();
172
+       /**digunakan untuk set rule validator */
173
+        $rules = [
174
+            'type'   => 'required',
175
+            'value' => 'required',
176
+        ];
177
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
178
+        $alert = [];
179
+        $validator = Validator::make($post, $rules, $alert);
180
+
181
+        $data_id = Hashids::decode($request['id']);
182
+
183
+        if (!empty($data_id)) {
184
+            /**cek apakah data_idnya ada ? */
185
+            $query = Points::find($data_id[0]);
186
+
187
+            if ($query) {
188
+                /**cek apakah id data benar" ada di DB ? */
189
+                if ($validator->passes()) {
190
+                    /**validatornya */
191
+                    DB::beginTransaction();
192
+
193
+                    $query->type   = $request->type;
194
+                    $query->value = $request->value;
195
+                    $query->save();
196
+
197
+                    if ($query) {
198
+                        DB::commit();
199
+                        $message = 'Berhasil';
200
+                        return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
201
+                    } else {
202
+                        DB::rollback();
203
+                        $message = 'Gagal';
204
+                        return redirect()->back()->with('error', Helper::parsing_alert($message));
205
+                    }
206
+                }
207
+
208
+                $message = Helper::parsing_alert($validator->errors()->all());
209
+
210
+                return redirect()->back()->with('error', $message);
211
+            } else {
212
+                $message = 'Id tdak ditemukan';
213
+                return redirect()->back()->with('error', $message);
214
+            }
215
+        } else {
216
+            $message = 'Id tidak boleh kosong';
217
+            return redirect()->back()->with('error', $message);
218
+        }
219
+    }
220
+
221
+    public function delete_action($id_modelmu)
222
+    {
223
+        $id = Hashids::decode($id_modelmu);
224
+        /**cek idnya apakah ada ? */
225
+
226
+        if (!empty($id)) {
227
+
228
+            $cek_data = Points::find($id[0]);
229
+
230
+            if ($cek_data) {
231
+                DB::beginTransaction();
232
+                try {
233
+                    $cek_data->delete();
234
+                    DB::commit();
235
+                    $message = 'Sukses';
236
+                    $response = [
237
+                        'message' => $message,
238
+                        'status'   => true,
239
+                    ];
240
+                    return response()->json($response);
241
+                } catch (Exception $e) {
242
+                    DB::rollback();
243
+                    $message = 'Gagal';
244
+                    $response = [
245
+                        'message' => $message,
246
+                        'status'   => false,
247
+                    ];
248
+                    return response()->json($response);
249
+                }
250
+            }
251
+            $message = 'Id tidak ditemukan atau sudah dihapus';
252
+            $response = [
253
+                'message' => $message,
254
+                'status'   => false,
255
+            ];
256
+            return response()->json($response);
257
+        }
258
+        $message = 'Id tdak ditemukan';
259
+        $response = [
260
+            'message' => $message,
261
+            'status'   => false,
262
+        ];
263
+        return response()->json($response);
264
+    }
265
+
266
+}

+ 287
- 0
app/Http/Controllers/Admin/Raharja/MessageController.php Dosyayı Görüntüle

@@ -0,0 +1,287 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Admin\Raharja;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use Illuminate\Http\Request;
8
+use App\Helpers\Helper;
9
+use App\Model\Raharja\CategoryMesssage;
10
+use App\Model\Raharja\Message;
11
+use App\Model\Raharja\News;
12
+use App\Model\Raharja\UserReceive;
13
+use App\User;
14
+use Yajra\Datatables\Datatables;
15
+use Auth;
16
+use Carbon\Carbon;
17
+use Illuminate\Support\Facades\Storage;
18
+use Validator;
19
+use Hashids;
20
+
21
+//load modelmu
22
+class MessageController extends Controller
23
+{
24
+    /**
25
+     * Title untuk judul di web
26
+     * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
27
+     */
28
+    private $title      = 'Message';                 /**jangan lupa diganti*/
29
+    private $route      = 'admin.message.';          //path awal foldernya ajah (misal folder di admin/dashboard) => 'admin.dashboard' | jangan lupa diganti
30
+    private $header     = 'Message';
31
+    private $sub_header = 'Message';
32
+    private $url        = 'admin.raharja.message.';
33
+
34
+     public function __construct()
35
+    {
36
+        DB::enableQueryLog();
37
+        /** nyalakan jika sudah set rolenya, jika ini dinyalakan halaman ini tidak akan keluar */
38
+        // $this->middleware('permission:searching-list|searching-create|searching-update|searching-delete', ['only' => ['index', 'create', 'update']]);
39
+        // $this->middleware('permission:searching-create', ['only' => ['create', 'create_action']]);
40
+        // $this->middleware('permission:searching-update', ['only' => ['update', 'update_action']]);
41
+        // $this->middleware('permission:searching-delete', ['only' => ['delete']]);
42
+    }
43
+
44
+     /**
45
+    * Ini contoh crud yang sudah jalan
46
+    * index digunakna untuk tampilan awal dari menu yang akan dibuat
47
+    * Untuk CRUD Biar cepat
48
+    * Silahkan ganti
49
+    * EloquentMu:: => dengan model anda
50
+    * $id_modelmu => ganti dengan id di model anda
51
+    * id_di_routenya => jangan lupa disesuaikan dengan yang dideclare di route
52
+    */
53
+
54
+
55
+    public function index()
56
+    {
57
+        Helper::swal();
58
+
59
+        $data = [
60
+            //bawaan
61
+            'title'      => $this->title,
62
+            'route'      => $this->route,
63
+            'header'     => $this->header,
64
+            'sub_header' => $this->sub_header,
65
+        ];
66
+        // dd($data);
67
+        return view($this->url . 'index', $data);
68
+    }
69
+    public function getData($udd_id = null)
70
+    {
71
+        $query = Message::query();
72
+
73
+        return Datatables::of($query)
74
+            ->addIndexColumn()
75
+            ->addColumn('aksi', function ($query) {
76
+
77
+                /**cek role */
78
+                $aksi = '';
79
+                // if (Auth::user()->can('master-jenis-kantong-update')) {
80
+                    // $aksi .= "<a href='" . route($this->route . 'send', ['data_id' => Hashids::encode($query->id)]) . "' class='btn btn-sm btn-primary btn-edit'>Kirim</a>";
81
+                // }
82
+
83
+                // if (Auth::user()->can('master-jenis-kantong-delete')) {
84
+                    $aksi .= "<a href='javascript:;' data-route='" . route($this->route . 'delete_action', ['data_id' => Hashids::encode($query->id)]) . "' class='btn btn-danger btn-sm btn-delete'>Delete</a>";
85
+                // }
86
+                return $aksi;
87
+            })
88
+            ->rawColumns(['aksi'])
89
+            ->toJson();
90
+    }
91
+    public function create()
92
+    {
93
+        $arr_category = CategoryMesssage::get();
94
+        $data = [
95
+            //bawaan
96
+            'title'         => $this->title,
97
+            'route'         => $this->route,
98
+            'header'        => $this->header,
99
+            'sub_header'    => $this->sub_header,
100
+            'categories'    => $arr_category,
101
+
102
+        ];
103
+
104
+        Helper::swal();
105
+
106
+        return view($this->url . 'create', $data);
107
+    }
108
+
109
+    public function create_action(Request $request)
110
+    {
111
+        //declare post untuk simpan semua request yang diinputkan oleh form name=""
112
+        $post = $request->all();
113
+        //dd($post);
114
+        /**digunakan untuk set rule validator */
115
+        $rules = [
116
+            'title'    => 'required',
117
+            'content'  => 'required',
118
+            'category' => 'required',
119
+        ];
120
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
121
+        $alert = [
122
+            'file'  => 'File maksimal 1MB'
123
+        ];
124
+        $validator = Validator::make($post, $rules, $alert);
125
+
126
+        if ($validator->passes()) {
127
+            /**menggunakan transaction */
128
+            DB::beginTransaction();
129
+
130
+            $set_data_message = [
131
+                'category_message_id' => $post['category'],
132
+                'title'               => $post['title'],
133
+                'user_id'               => Auth::user()->id,
134
+                'content'             => Helper::input_summernote($post['content']),
135
+            ];
136
+
137
+            $message = Message::create($set_data_message);
138
+
139
+            if($post['keterangan_kirim'] == 'semua'){
140
+                $arr_user = User::get()->pluck('id')->toArray();
141
+            }else{
142
+                $arr_user = $post['pilih_user'];
143
+            }
144
+
145
+            foreach($arr_user as $key => $value){
146
+                $set_data_user_recive[] = [
147
+                    'message_id' => $message->id,
148
+                    'user_id'    => $value,
149
+                    'created_at' => Carbon::now(),
150
+                    'is_check'   => 0,
151
+                ];
152
+            }
153
+            $user_receive = UserReceive::insert($set_data_user_recive);
154
+
155
+            if ($message && $user_receive) {
156
+                DB::commit();
157
+                $message = 'Berhasil';
158
+                return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
159
+            } else {
160
+                DB::rollback();
161
+                $message = 'Gagal';
162
+                return redirect()->back()->with('error', Helper::parsing_alert($message));
163
+            }
164
+        }
165
+        /**kenapa menggunakan back ? karena baliknya pasti ke halaman sebelumnya */
166
+        $message = Helper::parsing_alert($validator->errors()->all());
167
+        return redirect()->back()->with('error', $message)->withInput();
168
+    }
169
+
170
+
171
+    public function delete_action($id_modelmu)
172
+    {
173
+        $id = Hashids::decode($id_modelmu);
174
+        /**cek idnya apakah ada ? */
175
+
176
+        if (!empty($id)) {
177
+
178
+            $cek_data = Message::find($id[0]);
179
+            if ($cek_data) {
180
+                DB::beginTransaction();
181
+                try {
182
+                    $arr_user_receive = UserReceive::Where('message_id', $cek_data->id)->delete();
183
+                    $delete = $cek_data->delete();
184
+                    DB::commit();
185
+                    $message = 'Sukses';
186
+                    $response = [
187
+                        'message' => $message,
188
+                        'status'   => true,
189
+                    ];
190
+                    return response()->json($response);
191
+                } catch (Exception $e) {
192
+                    DB::rollback();
193
+                    $message = 'Gagal';
194
+                    $response = [
195
+                        'message' => $message,
196
+                        'status'   => false,
197
+                    ];
198
+                    return response()->json($response);
199
+                }
200
+            }
201
+            $message = 'Id tidak ditemukan atau sudah dihapus';
202
+            $response = [
203
+                'message' => $message,
204
+                'status'   => false,
205
+            ];
206
+            return response()->json($response);
207
+        }
208
+        $message = 'Id tdak ditemukan';
209
+        $response = [
210
+            'message' => $message,
211
+            'status'   => false,
212
+        ];
213
+        return response()->json($response);
214
+    }
215
+
216
+    public function selectUser(Request $request){
217
+        if (session('error')) {
218
+            alert()->html('', session('error'), 'error');
219
+        }
220
+        $term = trim($request['nama']);
221
+
222
+        $user = User::take(10);
223
+
224
+        if (!empty($request['not_in'])) {
225
+            $id = collect($request['not_in']);
226
+            $user = $user->whereNotIn('id', $id);
227
+        }
228
+        if (!empty($term)) {
229
+            $user = $user->where('nama', 'like', '%' . $term . '%');
230
+        }
231
+        $user = $user->get();
232
+        $response = [];
233
+
234
+        foreach ($user as $key => $value) {
235
+            $response[] = ['id' => $value->id, 'text' => $value->name ];
236
+        }
237
+
238
+        return response()->json($response);
239
+    }
240
+
241
+    public function send($data_id){
242
+        $id = Hashids::decode($data_id);
243
+        $query = Message::where('id', $id)->first();
244
+
245
+        foreach($query->userReceive as $key => $value){
246
+            $set_data_user_recive[] = [
247
+                'message_id' => $query->id,
248
+                'user_receive_id'    => $value->user_id,
249
+                'author_id'    => $query->user_id,
250
+                'title'      => $query->title,
251
+                'content'    => $query->content,
252
+                'category'   => $query->categoryMessage->name,
253
+            ];
254
+        }
255
+        if($set_data_user_recive){
256
+            $result = $set_data_user_recive;
257
+
258
+            $res_status = true;
259
+            $msg = 'Kirim Data';
260
+            $status_msg = $msg;
261
+
262
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
263
+
264
+        }else {
265
+
266
+            $res_status = false;
267
+            $msg = 'Data tidak ditemukan';
268
+            $status_msg = $msg;
269
+
270
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
271
+        }
272
+    }
273
+    public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null)
274
+    {
275
+        $response['response'] = array(
276
+            'status'     => $status,
277
+            'message'    => $msg,
278
+            'status_msg' => $status_msg,
279
+        );
280
+        $response['param'] = !empty($param) ? $param : '';
281
+
282
+        $response['results'] = $result;
283
+
284
+        return response()->json($response, 200);
285
+    }
286
+
287
+}

+ 306
- 0
app/Http/Controllers/Admin/Raharja/NewsController.php Dosyayı Görüntüle

@@ -0,0 +1,306 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Admin\Raharja;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use Illuminate\Http\Request;
8
+use App\Helpers\Helper;
9
+use App\Model\Raharja\News;
10
+use Yajra\Datatables\Datatables;
11
+use Auth;
12
+use Illuminate\Support\Facades\Storage;
13
+use Validator;
14
+use Hashids;
15
+
16
+//load modelmu
17
+class NewsController extends Controller
18
+{
19
+    /**
20
+     * Title untuk judul di web
21
+     * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
22
+     */
23
+    private $title      = 'News';                 /**jangan lupa diganti*/
24
+    private $route      = 'admin.news.';          //path awal foldernya ajah (misal folder di admin/dashboard) => 'admin.dashboard' | jangan lupa diganti
25
+    private $header     = 'News';
26
+    private $sub_header = 'News';
27
+    private $url        = 'admin.raharja.news.';
28
+
29
+     public function __construct()
30
+    {
31
+        DB::enableQueryLog();
32
+        /** nyalakan jika sudah set rolenya, jika ini dinyalakan halaman ini tidak akan keluar */
33
+        // $this->middleware('permission:searching-list|searching-create|searching-update|searching-delete', ['only' => ['index', 'create', 'update']]);
34
+        // $this->middleware('permission:searching-create', ['only' => ['create', 'create_action']]);
35
+        // $this->middleware('permission:searching-update', ['only' => ['update', 'update_action']]);
36
+        // $this->middleware('permission:searching-delete', ['only' => ['delete']]);
37
+    }
38
+
39
+     /**
40
+    * Ini contoh crud yang sudah jalan
41
+    * index digunakna untuk tampilan awal dari menu yang akan dibuat
42
+    * Untuk CRUD Biar cepat
43
+    * Silahkan ganti
44
+    * EloquentMu:: => dengan model anda
45
+    * $id_modelmu => ganti dengan id di model anda
46
+    * id_di_routenya => jangan lupa disesuaikan dengan yang dideclare di route
47
+    */
48
+
49
+
50
+    public function index()
51
+    {
52
+        Helper::swal();
53
+
54
+        $data = [
55
+            //bawaan
56
+            'title'      => $this->title,
57
+            'route'      => $this->route,
58
+            'header'     => $this->header,
59
+            'sub_header' => $this->sub_header,
60
+        ];
61
+        // dd($data);
62
+        return view($this->url . 'index', $data);
63
+    }
64
+    public function getData($udd_id = null)
65
+    {
66
+        $query = News::query();
67
+
68
+        return Datatables::of($query)
69
+            ->addIndexColumn()
70
+            ->addColumn('count_like', function($query){
71
+                return count($query->newsLikes);
72
+            })
73
+            ->addColumn('aksi', function ($query) {
74
+
75
+                /**cek role */
76
+                $aksi = '';
77
+                // if (Auth::user()->can('master-jenis-kantong-update')) {
78
+                    $aksi .= "<a href='" . route($this->route . 'update', ['news_id' => Hashids::encode($query->id)]) . "' class='btn btn-sm btn-primary btn-edit'>Edit</a>";
79
+                // }
80
+
81
+                // if (Auth::user()->can('master-jenis-kantong-delete')) {
82
+                    $aksi .= "<a href='javascript:;' data-route='" . route($this->route . 'delete_action', ['news_id' => Hashids::encode($query->id)]) . "' class='btn btn-danger btn-sm btn-delete'>Delete</a>";
83
+                // }
84
+                return $aksi;
85
+            })
86
+            ->rawColumns(['aksi'])
87
+            ->toJson();
88
+    }
89
+    public function create()
90
+    {
91
+        $data = [
92
+            //bawaan
93
+            'title'         => $this->title,
94
+            'route'         => $this->route,
95
+            'header'        => $this->header,
96
+            'sub_header'    => $this->sub_header,
97
+
98
+        ];
99
+
100
+        Helper::swal();
101
+
102
+        return view($this->url . 'create', $data);
103
+    }
104
+
105
+    public function create_action(Request $request)
106
+    {
107
+        //declare post untuk simpan semua request yang diinputkan oleh form name=""
108
+        $post = $request->all();
109
+        $file = $request->file('gambar');
110
+        //dd($post);
111
+        /**digunakan untuk set rule validator */
112
+        $rules = [
113
+            'title'        => 'required',
114
+            'gambar'       => 'required|file|max:1000',
115
+            'content'      => 'required',
116
+            'sub_title'    => 'required',
117
+            'date_publish' => 'required',
118
+        ];
119
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
120
+        $alert = [
121
+            'file'  => 'File maksimal 1MB'
122
+        ];
123
+        $validator = Validator::make($post, $rules, $alert);
124
+
125
+        if ($validator->passes()) {
126
+            /**menggunakan transaction */
127
+            DB::beginTransaction();
128
+
129
+            $nama_file = time()."_".$file->getClientOriginalName();
130
+
131
+            $tujuan_upload = 'gambar';
132
+
133
+            //$file->move($tujuan_upload,$nama_file);
134
+            Storage::putFileAs('public/images/news/', $file, $nama_file );
135
+
136
+            $query               = new News();
137
+            $query->title        = $request->title;
138
+            $query->content      = Helper::input_summernote($request->content);
139
+            $query->sub_title    = Helper::input_summernote($request->sub_title);
140
+            $query->date_publish = $request->date_publish;
141
+            $query->user_id      = Auth::user()->id;
142
+            $query->thumbnail    = $nama_file;
143
+            $query->save();
144
+
145
+            if ($query) {
146
+                DB::commit();
147
+                $message = 'Berhasil';
148
+                return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
149
+            } else {
150
+                DB::rollback();
151
+                $message = 'Gagal';
152
+                return redirect()->back()->with('error', Helper::parsing_alert($message));
153
+            }
154
+        }
155
+        /**kenapa menggunakan back ? karena baliknya pasti ke halaman sebelumnya */
156
+        $message = Helper::parsing_alert($validator->errors()->all());
157
+        return redirect()->back()->with('error', $message)->withInput();
158
+    }
159
+
160
+    public function update($data_id)
161
+    {
162
+
163
+        Helper::swal();
164
+
165
+
166
+        $data_id = Hashids::decode($data_id);
167
+        if (!empty($data_id)) {
168
+
169
+            $cek_data = News::where('id', $data_id[0])->first();
170
+
171
+            if ($cek_data) {
172
+                $data = [
173
+                    //bawaan
174
+                    'title'         => $this->title,
175
+                    'route'         => $this->route,
176
+                    'header'        => $this->header,
177
+                    'sub_header'    => $this->sub_header,
178
+                    'data'          => $cek_data
179
+                ];
180
+                return view($this->url . 'update', $data);
181
+            }
182
+            $message = 'Id tidak ditemukan atau sudah dihapus';
183
+            return redirect()->back()->with('error', $message);
184
+        }
185
+        $message = 'Id tdak ditemukan';
186
+        return redirect()->back()->with('error', $message);
187
+    }
188
+
189
+    public function update_action(Request $request)
190
+    {
191
+        $post = $request->all();
192
+       /**digunakan untuk set rule validator */
193
+        $rules = [
194
+            'title'        => 'required',
195
+            'content'      => 'required',
196
+            'sub_title'    => 'required',
197
+            'date_publish' => 'required',
198
+        ];
199
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
200
+        $alert = [];
201
+        $validator = Validator::make($post, $rules, $alert);
202
+
203
+        $data_id = Hashids::decode($request['id']);
204
+
205
+        if (!empty($data_id)) {
206
+            /**cek apakah data_idnya ada ? */
207
+            $query = News::find($data_id[0]);
208
+
209
+            if ($query) {
210
+                /**cek apakah id data benar" ada di DB ? */
211
+                if ($validator->passes()) {
212
+                    /**validatornya */
213
+                    DB::beginTransaction();
214
+                    $file = $request->file('gambar');
215
+                    if($file){
216
+                        $nama_file = time()."_".$file->getClientOriginalName();
217
+                        $tujuan_upload = 'gambar';
218
+                        //$file->move($tujuan_upload,$nama_file);
219
+                        Storage::putFileAs('public/images/news/', $file, $nama_file );
220
+                        //File::delete('gambar/'.$query->gambar);
221
+                        Storage::delete('public/images/news/'.$query->thumbnail);
222
+                        $query->thumbnail = $nama_file;
223
+                    }
224
+
225
+                    $query->title        = $request->title;
226
+                    $query->content      = Helper::input_summernote($request->content);
227
+                    $query->sub_title    = Helper::input_summernote($request->sub_title);
228
+                    $query->date_publish = $request->date_publish;
229
+                    $query->save();
230
+
231
+                    if ($query) {
232
+                        DB::commit();
233
+                        $message = 'Berhasil';
234
+                        return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
235
+                    } else {
236
+                        DB::rollback();
237
+                        $message = 'Gagal';
238
+                        return redirect()->back()->with('error', Helper::parsing_alert($message));
239
+                    }
240
+                }
241
+
242
+                $message = Helper::parsing_alert($validator->errors()->all());
243
+
244
+                return redirect()->back()->with('error', $message);
245
+            } else {
246
+                $message = 'Id tdak ditemukan';
247
+                return redirect()->back()->with('error', $message);
248
+            }
249
+        } else {
250
+            $message = 'Id tidak boleh kosong';
251
+            return redirect()->back()->with('error', $message);
252
+        }
253
+    }
254
+
255
+    public function delete_action($id_modelmu)
256
+    {
257
+        $id = Hashids::decode($id_modelmu);
258
+        /**cek idnya apakah ada ? */
259
+
260
+        if (!empty($id)) {
261
+
262
+            $cek_data = News::find($id[0]);
263
+
264
+            if ($cek_data) {
265
+                DB::beginTransaction();
266
+                try {
267
+                    //File::delete('gambar/'.$cek_data->gambar);
268
+                    $arr_likes = $cek_data->newsLikes;
269
+                    foreach($arr_likes as $like){
270
+                        $like->delete();
271
+                    }
272
+                    Storage::delete('public/images/news/'.$cek_data->thumbnail);
273
+                    $delete = $cek_data->delete();
274
+                    DB::commit();
275
+                    $message = 'Sukses';
276
+                    $response = [
277
+                        'message' => $message,
278
+                        'status'   => true,
279
+                    ];
280
+                    return response()->json($response);
281
+                } catch (Exception $e) {
282
+                    DB::rollback();
283
+                    $message = 'Gagal';
284
+                    $response = [
285
+                        'message' => $message,
286
+                        'status'   => false,
287
+                    ];
288
+                    return response()->json($response);
289
+                }
290
+            }
291
+            $message = 'Id tidak ditemukan atau sudah dihapus';
292
+            $response = [
293
+                'message' => $message,
294
+                'status'   => false,
295
+            ];
296
+            return response()->json($response);
297
+        }
298
+        $message = 'Id tdak ditemukan';
299
+        $response = [
300
+            'message' => $message,
301
+            'status'   => false,
302
+        ];
303
+        return response()->json($response);
304
+    }
305
+
306
+}

+ 307
- 0
app/Http/Controllers/Admin/Raharja/TipsController.php Dosyayı Görüntüle

@@ -0,0 +1,307 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Admin\Raharja;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use Illuminate\Http\Request;
8
+use App\Helpers\Helper;
9
+use App\Model\Raharja\News;
10
+use App\Model\Raharja\Tips;
11
+use Yajra\Datatables\Datatables;
12
+use Auth;
13
+use Illuminate\Support\Facades\Storage;
14
+use Validator;
15
+use Hashids;
16
+
17
+//load modelmu
18
+class TipsController extends Controller
19
+{
20
+    /**
21
+     * Title untuk judul di web
22
+     * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
23
+     */
24
+    private $title      = 'Tips';                 /**jangan lupa diganti*/
25
+    private $route      = 'admin.tips.';          //path awal foldernya ajah (misal folder di admin/dashboard) => 'admin.dashboard' | jangan lupa diganti
26
+    private $header     = 'Tips';
27
+    private $sub_header = 'Tips';
28
+    private $url        = 'admin.raharja.tips.';
29
+
30
+     public function __construct()
31
+    {
32
+        DB::enableQueryLog();
33
+        /** nyalakan jika sudah set rolenya, jika ini dinyalakan halaman ini tidak akan keluar */
34
+        // $this->middleware('permission:searching-list|searching-create|searching-update|searching-delete', ['only' => ['index', 'create', 'update']]);
35
+        // $this->middleware('permission:searching-create', ['only' => ['create', 'create_action']]);
36
+        // $this->middleware('permission:searching-update', ['only' => ['update', 'update_action']]);
37
+        // $this->middleware('permission:searching-delete', ['only' => ['delete']]);
38
+    }
39
+
40
+     /**
41
+    * Ini contoh crud yang sudah jalan
42
+    * index digunakna untuk tampilan awal dari menu yang akan dibuat
43
+    * Untuk CRUD Biar cepat
44
+    * Silahkan ganti
45
+    * EloquentMu:: => dengan model anda
46
+    * $id_modelmu => ganti dengan id di model anda
47
+    * id_di_routenya => jangan lupa disesuaikan dengan yang dideclare di route
48
+    */
49
+
50
+
51
+    public function index()
52
+    {
53
+        Helper::swal();
54
+
55
+        $data = [
56
+            //bawaan
57
+            'title'      => $this->title,
58
+            'route'      => $this->route,
59
+            'header'     => $this->header,
60
+            'sub_header' => $this->sub_header,
61
+        ];
62
+        // dd($data);
63
+        return view($this->url . 'index', $data);
64
+    }
65
+    public function getData($udd_id = null)
66
+    {
67
+        $query = Tips::query();
68
+
69
+        return Datatables::of($query)
70
+            ->addIndexColumn()
71
+            ->addColumn('count_like', function($query){
72
+                return count($query->tipsLike);
73
+            })
74
+            ->addColumn('aksi', function ($query) {
75
+
76
+                /**cek role */
77
+                $aksi = '';
78
+                // if (Auth::user()->can('master-jenis-kantong-update')) {
79
+                    $aksi .= "<a href='" . route($this->route . 'update', ['news_id' => Hashids::encode($query->id)]) . "' class='btn btn-sm btn-primary btn-edit'>Edit</a>";
80
+                // }
81
+
82
+                // if (Auth::user()->can('master-jenis-kantong-delete')) {
83
+                    $aksi .= "<a href='javascript:;' data-route='" . route($this->route . 'delete_action', ['news_id' => Hashids::encode($query->id)]) . "' class='btn btn-danger btn-sm btn-delete'>Delete</a>";
84
+                // }
85
+                return $aksi;
86
+            })
87
+            ->rawColumns(['aksi'])
88
+            ->toJson();
89
+    }
90
+    public function create()
91
+    {
92
+        $data = [
93
+            //bawaan
94
+            'title'         => $this->title,
95
+            'route'         => $this->route,
96
+            'header'        => $this->header,
97
+            'sub_header'    => $this->sub_header,
98
+
99
+        ];
100
+
101
+        Helper::swal();
102
+
103
+        return view($this->url . 'create', $data);
104
+    }
105
+
106
+    public function create_action(Request $request)
107
+    {
108
+        //declare post untuk simpan semua request yang diinputkan oleh form name=""
109
+        $post = $request->all();
110
+        $file = $request->file('gambar');
111
+        //dd($post);
112
+        /**digunakan untuk set rule validator */
113
+        $rules = [
114
+            'title'        => 'required',
115
+            'gambar'       => 'required|file|max:1000',
116
+            'sub_title'    => 'required',
117
+            'date_publish' => 'required',
118
+        ];
119
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
120
+        $alert = [
121
+            'file'  => 'File maksimal 1MB'
122
+        ];
123
+        $validator = Validator::make($post, $rules, $alert);
124
+
125
+        if ($validator->passes()) {
126
+            /**menggunakan transaction */
127
+            DB::beginTransaction();
128
+
129
+            $nama_file = time()."_".$file->getClientOriginalName();
130
+
131
+            $tujuan_upload = 'gambar';
132
+            //$file->move($tujuan_upload,$nama_file);
133
+
134
+            Storage::putFileAs('public/images/tips/', $file, $nama_file );
135
+
136
+            $query               = new Tips();
137
+            $query->title        = $request->title;
138
+            $query->content      = Helper::input_summernote($request->content);
139
+            $query->sub_title    = Helper::input_summernote($request->sub_title);
140
+            $query->date_publish = $request->date_publish;
141
+            $query->user_id      = Auth::user()->id;
142
+            $query->thumbnail    = $nama_file;
143
+            $query->save();
144
+
145
+            if ($query) {
146
+                DB::commit();
147
+                $message = 'Berhasil';
148
+                return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
149
+            } else {
150
+                DB::rollback();
151
+                $message = 'Gagal';
152
+                return redirect()->back()->with('error', Helper::parsing_alert($message));
153
+            }
154
+        }
155
+        /**kenapa menggunakan back ? karena baliknya pasti ke halaman sebelumnya */
156
+        $message = Helper::parsing_alert($validator->errors()->all());
157
+        return redirect()->back()->with('error', $message)->withInput();
158
+    }
159
+
160
+    public function update($data_id)
161
+    {
162
+
163
+        Helper::swal();
164
+
165
+
166
+        $data_id = Hashids::decode($data_id);
167
+        if (!empty($data_id)) {
168
+
169
+            $cek_data = Tips::where('id', $data_id[0])->first();
170
+
171
+            if ($cek_data) {
172
+                $data = [
173
+                    //bawaan
174
+                    'title'         => $this->title,
175
+                    'route'         => $this->route,
176
+                    'header'        => $this->header,
177
+                    'sub_header'    => $this->sub_header,
178
+                    'data'          => $cek_data
179
+                ];
180
+                return view($this->url . 'update', $data);
181
+            }
182
+            $message = 'Id tidak ditemukan atau sudah dihapus';
183
+            return redirect()->back()->with('error', $message);
184
+        }
185
+        $message = 'Id tdak ditemukan';
186
+        return redirect()->back()->with('error', $message);
187
+    }
188
+
189
+    public function update_action(Request $request)
190
+    {
191
+        $post = $request->all();
192
+       /**digunakan untuk set rule validator */
193
+        $rules = [
194
+            'title'        => 'required',
195
+            'content'      => 'required',
196
+            'sub_title'    => 'required',
197
+            'date_publish' => 'required',
198
+        ];
199
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
200
+        $alert = [];
201
+        $validator = Validator::make($post, $rules, $alert);
202
+
203
+        $data_id = Hashids::decode($request['id']);
204
+
205
+        if (!empty($data_id)) {
206
+            /**cek apakah data_idnya ada ? */
207
+            $query = Tips::find($data_id[0]);
208
+
209
+            if ($query) {
210
+                /**cek apakah id data benar" ada di DB ? */
211
+                if ($validator->passes()) {
212
+                    /**validatornya */
213
+                    DB::beginTransaction();
214
+                    $file = $request->file('gambar');
215
+                    if($file){
216
+                        $nama_file = time()."_".$file->getClientOriginalName();
217
+                        $tujuan_upload = 'gambar';
218
+                        //$file->move($tujuan_upload,$nama_file);
219
+                        Storage::putFileAs('public/images/tips/', $file, $nama_file );
220
+                        //File::delete('gambar/'.$query->gambar);
221
+                        Storage::delete('public/images/tips/'.$query->thumbnail);
222
+                        $query->thumbnail = $nama_file;
223
+                    }
224
+
225
+                    $query->title        = $request->title;
226
+                    $query->content      = Helper::input_summernote($request->content);
227
+                    $query->sub_title    = Helper::input_summernote($request->sub_title);
228
+                    $query->date_publish = $request->date_publish;
229
+                    $query->save();
230
+
231
+                    if ($query) {
232
+                        DB::commit();
233
+                        $message = 'Berhasil';
234
+                        return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
235
+                    } else {
236
+                        DB::rollback();
237
+                        $message = 'Gagal';
238
+                        return redirect()->back()->with('error', Helper::parsing_alert($message));
239
+                    }
240
+                }
241
+
242
+                $message = Helper::parsing_alert($validator->errors()->all());
243
+
244
+                return redirect()->back()->with('error', $message);
245
+            } else {
246
+                $message = 'Id tdak ditemukan';
247
+                return redirect()->back()->with('error', $message);
248
+            }
249
+        } else {
250
+            $message = 'Id tidak boleh kosong';
251
+            return redirect()->back()->with('error', $message);
252
+        }
253
+    }
254
+
255
+    public function delete_action($id_modelmu)
256
+    {
257
+        $id = Hashids::decode($id_modelmu);
258
+        /**cek idnya apakah ada ? */
259
+
260
+        if (!empty($id)) {
261
+
262
+            $cek_data = Tips::find($id[0]);
263
+
264
+            if ($cek_data) {
265
+                DB::beginTransaction();
266
+                try {
267
+                    $arr_likes = $cek_data->tipsLike;
268
+                    foreach($arr_likes as $like){
269
+                        $like->delete();
270
+                    }
271
+                    //File::delete('gambar/'.$cek_data->gambar);
272
+                    Storage::delete('public/images/tips/'.$cek_data->thumbnail);
273
+                    $delete = $cek_data->delete();
274
+
275
+                    DB::commit();
276
+                    $message = 'Sukses';
277
+                    $response = [
278
+                        'message' => $message,
279
+                        'status'   => true,
280
+                    ];
281
+                    return response()->json($response);
282
+                } catch (Exception $e) {
283
+                    DB::rollback();
284
+                    $message = 'Gagal';
285
+                    $response = [
286
+                        'message' => $message,
287
+                        'status'   => false,
288
+                    ];
289
+                    return response()->json($response);
290
+                }
291
+            }
292
+            $message = 'Id tidak ditemukan atau sudah dihapus';
293
+            $response = [
294
+                'message' => $message,
295
+                'status'   => false,
296
+            ];
297
+            return response()->json($response);
298
+        }
299
+        $message = 'Id tdak ditemukan';
300
+        $response = [
301
+            'message' => $message,
302
+            'status'   => false,
303
+        ];
304
+        return response()->json($response);
305
+    }
306
+
307
+}

+ 353
- 0
app/Http/Controllers/Admin/TransportationController.php Dosyayı Görüntüle

@@ -0,0 +1,353 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Admin;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use Illuminate\Http\Request;
8
+use App\Helpers\Helper;
9
+use Validator;
10
+use Hashids;
11
+use Yajra\Datatables\Datatables;
12
+use Auth;
13
+use Illuminate\Support\Facades\Route;
14
+use Illuminate\Support\Facades\File;
15
+use Illuminate\Support\Facades\Storage;
16
+
17
+//load modelmu
18
+use App\Model\Transportation;
19
+
20
+class TransportationController extends Controller
21
+{
22
+    /**
23
+     * Title untuk judul di web
24
+     * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
25
+     */
26
+    private $title = 'Transportation'; /**jangan lupa diganti*/
27
+    private $route = 'admin.transportation.'; //path awal foldernya ajah (misal folder di admin/dashboard) => 'admin.dashboard' | jangan lupa diganti
28
+    private $header = 'Transportation';
29
+    private $sub_header = 'Transportation';
30
+    /**khusus namespace ambil pathnya aja contoh : App\Http\Controllers\Admin\Simdondar\DonorDarah -> Admin\Simdondar\DonorDarah*/
31
+    private $namespace_controller = 'Admin';
32
+    private $url_prefix = 'admin/transportation/';
33
+
34
+     public function __construct()
35
+    {
36
+        // DB::enableQueryLog();
37
+        // /** nyalakan jika sudah set rolenya, jika ini dinyalakan halaman ini tidak akan keluar */
38
+        // $this->middleware('permission:master_alat-list|master_alat-create|master_alat-update|master_alat-delete', ['only' => ['index', 'create', 'update']]);
39
+        // $this->middleware('permission:master_alat-create', ['only' => ['create', 'create_action']]);
40
+        // $this->middleware('permission:master_alat-update', ['only' => ['update', 'update_action']]);
41
+        // $this->middleware('permission:master_alat-delete', ['only' => ['delete']]);
42
+    }
43
+
44
+     /**
45
+    * Ini contoh crud yang sudah jalan
46
+    * index digunakna untuk tampilan awal dari menu yang akan dibuat
47
+    * Untuk CRUD Biar cepat
48
+    * Silahkan ganti
49
+    * EloquentMu:: => dengan model anda
50
+    * $id_modelmu => ganti dengan id di model anda
51
+    * id_di_routenya => jangan lupa disesuaikan dengan yang dideclare di route
52
+    */
53
+
54
+
55
+    public function index()
56
+    {
57
+        Helper::swal();
58
+
59
+        $data = [
60
+            //bawaan
61
+            'title' => $this->title,
62
+            'route' => $this->route,
63
+            'header'        => $this->header,
64
+            'sub_header'    => $this->sub_header,
65
+        ];
66
+        // dd($data);
67
+        return view($this->route . 'index', $data);
68
+    }
69
+    /**
70
+    *digunakan untuk datatable yajra
71
+    *querynya bisa ganti" sesuai hati
72
+    */
73
+    public function getData()
74
+    {
75
+        $query = Transportation::query();
76
+        $data_table =  Datatables::of($query)
77
+            ->addIndexColumn()
78
+            ->addColumn('aksi', function ($query) {
79
+
80
+                /**cek role */
81
+                $aksi = '';
82
+                    $aksi .= "<a href='" . route($this->route . 'update', ['id_di_routenya' => Hashids::encode($query->id)]) . "' class='btn btn-sm btn-primary btn-edit'>Edit</a>";
83
+
84
+                // if (Auth::user()->can('master_alat-delete')) {
85
+                //     $aksi .= "<a href='javascript:;' data-route='" . route($this->route . 'delete_action', ['id_di_routenya' => Hashids::encode($query->id)]) . "' class='btn btn-danger btn-sm btn-delete'>Delete</a>";
86
+                // }
87
+                return $aksi;
88
+            })
89
+            ->addIndexColumn()
90
+            ->rawColumns(['aksi'])
91
+            ->escapeColumns([]) //digunakan untuk render html
92
+            ->toJson();
93
+        return $data_table;
94
+    }
95
+
96
+    /**
97
+    * create digunakan untuk menampilkan tampilan buat
98
+    */
99
+    public function create()
100
+    {
101
+        $data = [
102
+            //bawaan
103
+            'title'         => $this->title,
104
+            'route'         => $this->route,
105
+            'header'        => $this->header,
106
+            'sub_header'    => $this->sub_header,
107
+
108
+        ];
109
+
110
+        Helper::swal();
111
+
112
+        return view($this->route . 'create', $data);
113
+    }
114
+
115
+    /**
116
+     * create_action digunakan untuk aksi post
117
+     * lengkap dengan validatornya
118
+     */
119
+    public function create_action(Request $request)
120
+    {
121
+        //declare post untuk simpan semua request yang diinputkan oleh form name=""
122
+        $post = $request->all();
123
+        $file = $request->file('gambar');
124
+        //dd($post);
125
+        /**digunakan untuk set rule validator */
126
+        $rules = [
127
+            'gambar' => 'required|file|max:1000',
128
+        ];
129
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
130
+        $alert = [
131
+            'file'  => 'File maksimal 1MB'
132
+        ];
133
+        $validator = Validator::make($post, $rules, $alert);
134
+
135
+        if ($validator->passes()) {
136
+            /**menggunakan transaction */
137
+            DB::beginTransaction();
138
+
139
+            $nama_file = time()."_".$file->getClientOriginalName();
140
+
141
+            $tujuan_upload = 'gambar';
142
+
143
+            //$file->move($tujuan_upload,$nama_file);
144
+            Storage::putFileAs('public/images/transportation/', $file, $nama_file );
145
+
146
+            $query                              = new Transportation();
147
+            $query->name                        = $request->name;
148
+            $query->transportation_identity     = $request->transportation_identity;
149
+            $query->transportation_type         = $request->transportation_type;
150
+            $query->transportation_photo        = $nama_file;
151
+            $query->user_id                     = Auth::user()->id;
152
+            $query->save();
153
+
154
+            if ($query) {
155
+                DB::commit();
156
+                $message = 'Berhasil';
157
+                return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
158
+            } else {
159
+                DB::rollback();
160
+                $message = 'Gagal';
161
+                return redirect()->back()->with('error', Helper::parsing_alert($message));
162
+            }
163
+        }
164
+        /**kenapa menggunakan back ? karena baliknya pasti ke halaman sebelumnya */
165
+        $message = Helper::parsing_alert($validator->errors()->all());
166
+        return redirect()->back()->with('error', $message)->withInput();
167
+    }
168
+
169
+    /** update sama seperti create hanya saja digunakan untuk update (viewnya saja) */
170
+    public function update($id_modelmu)
171
+    {
172
+
173
+        Helper::swal();
174
+
175
+
176
+        $id_modelmu = Hashids::decode($id_modelmu);
177
+        if (!empty($id_modelmu)) {
178
+
179
+            $cek_data = MasterAlat::where('id', $id_modelmu[0])->first();
180
+
181
+            if ($cek_data) {
182
+                $data = [
183
+                    //bawaan
184
+                    'title'         => $this->title,
185
+                    'route'         => $this->route,
186
+                    'header'        => $this->header,
187
+                    'sub_header'    => $this->sub_header,
188
+                    'data'          => $cek_data
189
+                ];
190
+                return view($this->route . 'update', $data);
191
+            }
192
+            $message = 'Id tidak ditemukan atau sudah dihapus';
193
+            return redirect()->back()->with('error', $message);
194
+        }
195
+        $message = 'Id tdak ditemukan';
196
+        return redirect()->back()->with('error', $message);
197
+    }
198
+
199
+    /**update_action POST
200
+     * Logikanya :
201
+     * 1. Cek Hashids::decode dari data_id apalah benar" di hash ?
202
+     * -iya
203
+     *  2. Cek ID yang didapatkan dari hash apakah benar adanya ?
204
+     *  -iya
205
+     *    3. proses validate
206
+     *    -iya
207
+     *      4. Proses update
208
+     *        - iya benar
209
+     *        - tidak salah
210
+     *    - tidak return error
211
+     *  - tidak return Id tdak ditemukan
212
+     * -tidak skip reutrn id null
213
+     */
214
+    public function update_action(Request $request)
215
+    {
216
+        $post = $request->all();
217
+       /**digunakan untuk set rule validator */
218
+        $rules = [];
219
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
220
+        $alert = [];
221
+        $validator = Validator::make($post, $rules, $alert);
222
+
223
+        $id_modelmu = Hashids::decode($request['id']);
224
+
225
+        if (!empty($id_modelmu)) {
226
+            /**cek apakah data_idnya ada ? */
227
+            $query = MasterAlat::find($id_modelmu[0]);
228
+
229
+            if ($query) {
230
+                /**cek apakah id data benar" ada di DB ? */
231
+                if ($validator->passes()) {
232
+                    /**validatornya */
233
+                    DB::beginTransaction();
234
+                    $file = $request->file('gambar');
235
+                    if($file){
236
+                        $nama_file = time()."_".$file->getClientOriginalName();
237
+                        $tujuan_upload = 'gambar';
238
+                        //$file->move($tujuan_upload,$nama_file);
239
+                        Storage::putFileAs('public/images/', $file, $nama_file );
240
+                        //File::delete('gambar/'.$query->gambar);
241
+                        Storage::delete('public/images/'.$query->gambar);
242
+                        $query->gambar = $nama_file;
243
+                    }
244
+
245
+                    $query->nama                = $request->nama;
246
+                    $query->type_alat_id        = $request->type_alat_id;
247
+                    $query->deskripsi           = $request->deskripsi;
248
+                    $query->unit_donor_darah_id = Auth::user()->petugas->unit_donor_darah_id;
249
+                    $query->save();
250
+
251
+                    if ($query) {
252
+                        DB::commit();
253
+                        $message = 'Berhasil';
254
+                        return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
255
+                    } else {
256
+                        DB::rollback();
257
+                        $message = 'Gagal';
258
+                        return redirect()->back()->with('error', Helper::parsing_alert($message));
259
+                    }
260
+                }
261
+
262
+                $message = Helper::parsing_alert($validator->errors()->all());
263
+
264
+                return redirect()->back()->with('error', $message);
265
+            } else {
266
+                $message = 'Id tdak ditemukan';
267
+                return redirect()->back()->with('error', $message);
268
+            }
269
+        } else {
270
+            $message = 'Id tidak boleh kosong';
271
+            return redirect()->back()->with('error', $message);
272
+        }
273
+    }
274
+
275
+    /**digunakan untuk delete
276
+     * Logikanya :
277
+     * 1. Cek hash id
278
+     * -ya
279
+     *  2. Cek id dari hash
280
+     *  - ya
281
+     *      3. Proses delete
282
+     *      -Ya
283
+     *      -Tidak
284
+     *  - tidak return Id tidak ditemukan atau sudah dihapus
285
+     * -tidak reutrn Id tdak ditemukan
286
+     */
287
+    public function delete_action($id_modelmu)
288
+    {
289
+        $id = Hashids::decode($id_modelmu);
290
+        /**cek idnya apakah ada ? */
291
+
292
+        if (!empty($id)) {
293
+
294
+            $cek_data = MasterAlat::find($id[0]);
295
+
296
+            if ($cek_data) {
297
+                DB::beginTransaction();
298
+                try {
299
+                    //File::delete('gambar/'.$cek_data->gambar);
300
+                    Storage::delete('public/images/'.$cek_data->gambar);
301
+                    $delete = $cek_data->delete();
302
+                    DB::commit();
303
+                    $message = 'Sukses';
304
+                    $response = [
305
+                        'message' => $message,
306
+                        'status'   => true,
307
+                    ];
308
+                    return response()->json($response);
309
+                } catch (Exception $e) {
310
+                    DB::rollback();
311
+                    $message = 'Gagal';
312
+                    $response = [
313
+                        'message' => $message,
314
+                        'status'   => false,
315
+                    ];
316
+                    return response()->json($response);
317
+                }
318
+            }
319
+            $message = 'Id tidak ditemukan atau sudah dihapus';
320
+            $response = [
321
+                'message' => $message,
322
+                'status'   => false,
323
+            ];
324
+            return response()->json($response);
325
+        }
326
+        $message = 'Id tdak ditemukan';
327
+        $response = [
328
+            'message' => $message,
329
+            'status'   => false,
330
+        ];
331
+        return response()->json($response);
332
+    }
333
+
334
+    /**declare routenya disni*/
335
+    public function route(){
336
+        $route = Route::namespace($this->namespace_controller)
337
+            ->prefix($this->url_prefix)
338
+            ->name($this->route)
339
+            ->group(function () {
340
+                Route::get('/', ['as' => 'index', 'uses' => 'TransportationController@index']);
341
+                Route::get('/get-data/{udd_id?}', ['as' => 'get_data', 'uses' => 'TransportationController@getData']);
342
+                Route::get('/datatables', ['as' => 'datatables', 'uses' => 'TransportationController@datatables']);
343
+                Route::get('/create', ['as' => 'create', 'uses' => 'TransportationController@create']);
344
+                Route::get('/update/{id_di_routenya}', ['as' => 'update', 'uses' => 'TransportationController@update']);
345
+                Route::get('/delete-action/{id_di_routenya}', ['as' => 'delete_action', 'uses' => 'TransportationController@delete_action']);
346
+
347
+                Route::post('/create-action', ['as' => 'create_action', 'uses' => 'TransportationController@create_action']);
348
+                Route::post('/update-action', ['as' => 'update_action', 'uses' => 'TransportationController@update_action']);
349
+            });
350
+        return $route;
351
+    }
352
+    /**end declare route */
353
+}

+ 323
- 0
app/Http/Controllers/Admin/Trivia/TriviaController.php Dosyayı Görüntüle

@@ -0,0 +1,323 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Admin\Trivia;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use Illuminate\Http\Request;
8
+use App\Helpers\Helper;
9
+use App\Model\Trivia;
10
+use App\Model\TriviaAnswer;
11
+use Yajra\Datatables\Datatables;
12
+use Auth;
13
+use Illuminate\Support\Facades\Storage;
14
+use Validator;
15
+use Hashids;
16
+use URL;
17
+
18
+//load modelmu
19
+class TriviaController extends Controller
20
+{
21
+    /**
22
+     * Title untuk judul di web
23
+     * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
24
+     */
25
+    private $title      = 'Trivia';                 /**jangan lupa diganti*/
26
+    private $route      = 'admin.trivia.';          //path awal foldernya ajah (misal folder di admin/dashboard) => 'admin.dashboard' | jangan lupa diganti
27
+    private $header     = 'Trivia';
28
+    private $sub_header = 'Trivia';
29
+    private $url        = 'admin.trivia.';
30
+
31
+     public function __construct()
32
+    {
33
+        DB::enableQueryLog();
34
+        /** nyalakan jika sudah set rolenya, jika ini dinyalakan halaman ini tidak akan keluar */
35
+        // $this->middleware('permission:searching-list|searching-create|searching-update|searching-delete', ['only' => ['index', 'create', 'update']]);
36
+        // $this->middleware('permission:searching-create', ['only' => ['create', 'create_action']]);
37
+        // $this->middleware('permission:searching-update', ['only' => ['update', 'update_action']]);
38
+        // $this->middleware('permission:searching-delete', ['only' => ['delete']]);
39
+    }
40
+
41
+     /**
42
+    * Ini contoh crud yang sudah jalan
43
+    * index digunakna untuk tampilan awal dari menu yang akan dibuat
44
+    * Untuk CRUD Biar cepat
45
+    * Silahkan ganti
46
+    * EloquentMu:: => dengan model anda
47
+    * $id_modelmu => ganti dengan id di model anda
48
+    * id_di_routenya => jangan lupa disesuaikan dengan yang dideclare di route
49
+    */
50
+
51
+
52
+    public function index()
53
+    {
54
+        Helper::swal();
55
+
56
+        $data = [
57
+            //bawaan
58
+            'title'      => $this->title,
59
+            'route'      => $this->route,
60
+            'header'     => $this->header,
61
+            'sub_header' => $this->sub_header,
62
+        ];
63
+        // dd($data);
64
+        return view($this->url . 'index', $data);
65
+    }
66
+    public function getData($udd_id = null)
67
+    {
68
+        // $query = Trivia::query();
69
+        $query = Trivia::leftJoin('trivia_answer', 'trivia.id', '=', 'trivia_answer.trivia_id')
70
+        ->select(['trivia.question', 'trivia.id', 'trivia.image', 'trivia_answer.answer', 'trivia_answer.is_right'])
71
+        ->where('trivia_answer.is_right', 't');
72
+        // dd($query);
73
+
74
+        return Datatables::of($query)
75
+            ->addIndexColumn()
76
+            ->addColumn('image', function ($query) {
77
+                $image = '<img src="'.URL::to('storage/images/trivia/'.$query->image).'" alt="'.$query->image.'" style="height: 100px;">';
78
+
79
+                return $image;
80
+            })
81
+            ->addColumn('aksi', function ($query) {
82
+
83
+                /**cek role */
84
+                $aksi = '';
85
+                // if (Auth::user()->can('master-jenis-kantong-update')) {
86
+                    $aksi .= "<a href='" . route($this->route . 'update', ['trivia_id' => Hashids::encode($query->id)]) . "' class='btn btn-sm btn-primary btn-edit'>Edit</a>";
87
+                // }
88
+
89
+                // if (Auth::user()->can('master-jenis-kantong-delete')) {
90
+                    $aksi .= "<a href='javascript:;' data-route='" . route($this->route . 'delete_action', ['trivia_id' => Hashids::encode($query->id)]) . "' class='btn btn-danger btn-sm btn-delete'>Delete</a>";
91
+                // }
92
+                return $aksi;
93
+            })
94
+            ->rawColumns(['aksi', 'image'])
95
+            ->toJson();
96
+    }
97
+    public function create()
98
+    {
99
+        $data = [
100
+            //bawaan
101
+            'title'         => $this->title,
102
+            'route'         => $this->route,
103
+            'header'        => $this->header,
104
+            'sub_header'    => $this->sub_header,
105
+
106
+        ];
107
+
108
+        Helper::swal();
109
+
110
+        return view($this->url . 'create', $data);
111
+    }
112
+
113
+    public function create_action(Request $request)
114
+    {
115
+        //declare post untuk simpan semua request yang diinputkan oleh form name=""
116
+        $post = $request->all();
117
+        // dd($post);
118
+        $file = $request->file('image');
119
+        //dd($post);
120
+        /**digunakan untuk set rule validator */
121
+        $rules = [
122
+            'question'   => 'required',
123
+            'image'  => 'required|file|max:1000',
124
+        ];
125
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
126
+        $alert = [
127
+            'file'  => 'File maksimal 1MB'
128
+        ];
129
+        $validator = Validator::make($post, $rules, $alert);
130
+
131
+        if ($validator->passes()) {
132
+            /**menggunakan transaction */
133
+            DB::beginTransaction();
134
+
135
+            $nama_file = time()."_".$file->getClientOriginalName();
136
+
137
+            $tujuan_upload = 'image';
138
+
139
+            //$file->move($tujuan_upload,$nama_file);
140
+            Storage::putFileAs('public/images/trivia/', $file, $nama_file );
141
+
142
+            $trivia              = new Trivia();
143
+            $trivia->question    = $request->question;
144
+            $trivia->image       = $nama_file;
145
+            $trivia->save();
146
+
147
+            foreach ($request->answer as $key => $value) {
148
+                $trivia_answer              = new TriviaAnswer();
149
+                $trivia_answer->answer      = $value;
150
+                $trivia_answer->trivia_id   = $trivia->id;
151
+                $trivia_answer->is_right    = ($key==0)?"t":"f";
152
+                $trivia_answer->save();
153
+            }
154
+
155
+            if ($trivia) {
156
+                DB::commit();
157
+                $message = 'Berhasil';
158
+                return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
159
+            } else {
160
+                DB::rollback();
161
+                $message = 'Gagal';
162
+                return redirect()->back()->with('error', Helper::parsing_alert($message));
163
+            }
164
+        }
165
+        /**kenapa menggunakan back ? karena baliknya pasti ke halaman sebelumnya */
166
+        $message = Helper::parsing_alert($validator->errors()->all());
167
+        return redirect()->back()->with('error', $message)->withInput();
168
+    }
169
+
170
+    public function update($data_id)
171
+    {
172
+
173
+        Helper::swal();
174
+
175
+
176
+        $data_id = Hashids::decode($data_id);
177
+        if (!empty($data_id)) {
178
+
179
+            $trivia = Trivia::where('id', $data_id[0])->first();
180
+            $trivia_answer = TriviaAnswer::where('trivia_id', $data_id[0])->get();
181
+
182
+            if ($trivia) {
183
+                $data = [
184
+                    //bawaan
185
+                    'title'         => $this->title,
186
+                    'route'         => $this->route,
187
+                    'header'        => $this->header,
188
+                    'sub_header'    => $this->sub_header,
189
+                    'trivia'        => $trivia,
190
+                    'trivia_answer' => $trivia_answer
191
+                ];
192
+                return view($this->url . 'update', $data);
193
+            }
194
+            $message = 'Id tidak ditemukan atau sudah dihapus';
195
+            return redirect()->back()->with('error', $message);
196
+        }
197
+        $message = 'Id tdak ditemukan';
198
+        return redirect()->back()->with('error', $message);
199
+    }
200
+
201
+    public function update_action(Request $request)
202
+    {
203
+        $post = $request->all();
204
+        // dd($post);
205
+       /**digunakan untuk set rule validator */
206
+        $rules = [
207
+            'question'   => 'required',
208
+        ];
209
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
210
+        $alert = [];
211
+        $validator = Validator::make($post, $rules, $alert);
212
+
213
+        $data_id = Hashids::decode($request['id']);
214
+
215
+        if (!empty($data_id)) {
216
+            /**cek apakah data_idnya ada ? */
217
+            $trivia = Trivia::find($data_id[0]);
218
+
219
+            if ($trivia) {
220
+                /**cek apakah id data benar" ada di DB ? */
221
+                if ($validator->passes()) {
222
+                    /**validatornya */
223
+                    DB::beginTransaction();
224
+                    $file = $request->file('image');
225
+                    if($file){
226
+                        $nama_file = time()."_".$file->getClientOriginalName();
227
+                        $tujuan_upload = 'image';
228
+                        //$file->move($tujuan_upload,$nama_file);
229
+                        Storage::putFileAs('public/images/trivia/', $file, $nama_file );
230
+                        //File::delete('image/'.$trivia->image);
231
+                        Storage::delete('public/images/trivia/'.$trivia->image);
232
+                        $trivia->image = $nama_file;
233
+                    }
234
+
235
+                    $trivia->question   = $request->question;
236
+                    $trivia->save();
237
+
238
+                    $counter=0;
239
+                    foreach ($request->answer as $key => $value) {
240
+                        // dd(($key==0)?"t":"f");
241
+                        $trivia_answer = TriviaAnswer::find($key);
242
+                        $trivia_answer->answer      = $value;
243
+                        $trivia_answer->trivia_id   = $trivia->id;
244
+                        $trivia_answer->is_right    = ($counter==0)?"t":"f";
245
+                        $trivia_answer->save();
246
+
247
+                        $counter += 1;
248
+                    }
249
+
250
+                    if ($trivia) {
251
+                        DB::commit();
252
+                        $message = 'Berhasil';
253
+                        return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
254
+                    } else {
255
+                        DB::rollback();
256
+                        $message = 'Gagal';
257
+                        return redirect()->back()->with('error', Helper::parsing_alert($message));
258
+                    }
259
+                }
260
+
261
+                $message = Helper::parsing_alert($validator->errors()->all());
262
+
263
+                return redirect()->back()->with('error', $message);
264
+            } else {
265
+                $message = 'Id tdak ditemukan';
266
+                return redirect()->back()->with('error', $message);
267
+            }
268
+        } else {
269
+            $message = 'Id tidak boleh kosong';
270
+            return redirect()->back()->with('error', $message);
271
+        }
272
+    }
273
+
274
+    public function delete_action($id_modelmu)
275
+    {
276
+        $id = Hashids::decode($id_modelmu);
277
+        /**cek idnya apakah ada ? */
278
+
279
+        if (!empty($id)) {
280
+
281
+            $trivia = Trivia::find($id[0]);
282
+            $trivia_answer = TriviaAnswer::where('trivia_id', $id[0])->firstOrFail();
283
+
284
+            if ($trivia) {
285
+                DB::beginTransaction();
286
+                try {
287
+                    //File::delete('image/'.$trivia->image);
288
+                    Storage::delete('public/images/trivia/'.$trivia->image);
289
+                    $delete = $trivia->delete();
290
+                    $delete2 = $trivia_answer->delete();
291
+                    DB::commit();
292
+                    $message = 'Sukses';
293
+                    $response = [
294
+                        'message' => $message,
295
+                        'status'   => true,
296
+                    ];
297
+                    return response()->json($response);
298
+                } catch (Exception $e) {
299
+                    DB::rollback();
300
+                    $message = 'Gagal';
301
+                    $response = [
302
+                        'message' => $message,
303
+                        'status'   => false,
304
+                    ];
305
+                    return response()->json($response);
306
+                }
307
+            }
308
+            $message = 'Id tidak ditemukan atau sudah dihapus';
309
+            $response = [
310
+                'message' => $message,
311
+                'status'   => false,
312
+            ];
313
+            return response()->json($response);
314
+        }
315
+        $message = 'Id tdak ditemukan';
316
+        $response = [
317
+            'message' => $message,
318
+            'status'   => false,
319
+        ];
320
+        return response()->json($response);
321
+    }
322
+
323
+}

+ 341
- 0
app/Http/Controllers/Admin/User_management/PermissionController.php Dosyayı Görüntüle

@@ -0,0 +1,341 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Admin\User_management;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use Illuminate\Http\Request;
8
+use App\Helpers\Helper;
9
+use Validator;
10
+use Hashids;
11
+use Spatie\Permission\Models\Permission;
12
+use Auth;
13
+use Illuminate\Support\Facades\Route;
14
+
15
+//load modelmu
16
+use Yajra\Datatables\Datatables;
17
+
18
+class PermissionController extends Controller
19
+{
20
+    /**
21
+     * Untuk CRUD Biar cepat
22
+     * Silahkan ganti
23
+     * Permission:: => dengan model anda
24
+     * $permission_id => ganti dengan id di model anda
25
+     */
26
+
27
+    /**
28
+     * Title untuk judul di web
29
+     * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
30
+     */
31
+    private $title = 'Admin Usermagement | Permission';
32
+    /**jangan lupa diganti*/
33
+    private $route = 'admin.user_management.permission.'; //path awal foldernya ajah (misal folder di admin/dashboard) => 'admin.dashboard' | jangan lupa diganti
34
+    private $permission = ['list', 'create', 'update', 'delete'];
35
+    private $namespace_controller = 'Admin\User_management';
36
+    private $url_prefix = 'admin/user-management/permission/';
37
+    public function __construct()
38
+    {
39
+        DB::getQueryLog();
40
+        // $this->middleware('permission:permission-list|permission-create|permission-update|permission-delete', ['only' => ['index', 'create', 'update']]);
41
+        // $this->middleware('permission:permission-create', ['only' => ['create', 'create_action']]);
42
+        // $this->middleware('permission:permission-update', ['only' => ['update', 'update_action']]);
43
+        // $this->middleware('permission:permission-delete', ['only' => ['delete']]);
44
+    }
45
+
46
+    /**
47
+     * Ini contoh crud yang sudah jalan
48
+     * index digunakna untuk tampilan awal dari menu yang akan dibuat
49
+     */
50
+    public function index()
51
+    {
52
+        if (session('success')) {
53
+            alert()->html('', session('success'), 'success');
54
+        }
55
+
56
+        if (session('error')) {
57
+            alert()->html('', session('error'), 'error');
58
+        }
59
+
60
+
61
+        $data = [
62
+            //bawaan
63
+            'title' => $this->title,
64
+            'route' => $this->route,
65
+        ];
66
+        // dd($data);
67
+        return view($this->route . 'index', $data);
68
+    }
69
+
70
+    public function getData()
71
+    {
72
+        $query = Permission::query();
73
+
74
+        return Datatables::of($query)
75
+            ->addIndexColumn()
76
+            ->addColumn('aksi', function ($query) {
77
+
78
+                /**cek role */
79
+                $aksi = '';
80
+              
81
+                    $aksi .= "<a href='" . route($this->route . 'update', ['permission_id' => Hashids::encode($query->id)]) . "' class='btn btn-sm btn-primary btn-edit'>Edit</a>";
82
+                
83
+
84
+               
85
+                    $aksi .= "<a href='javascript:;' data-route='" . route($this->route . 'delete_action', ['permission_id' => Hashids::encode($query->id)]) . "' class='btn btn-danger btn-sm btn-delete'>Delete</a>";
86
+                
87
+                return $aksi;
88
+            })
89
+            ->rawColumns(['aksi'])
90
+            ->toJson();
91
+    }
92
+
93
+    /**
94
+     * create digunakan untuk menampilkan tampilan buat
95
+     */
96
+    public function create()
97
+    {
98
+        $data = [
99
+            //bawaan
100
+            'title' => $this->title,
101
+            'route' => $this->route,
102
+            'permission' => $this->permission
103
+        ];
104
+
105
+        if (session('success')) {
106
+            alert()->html('', session('success'), 'success');
107
+        }
108
+
109
+        if (session('error')) {
110
+            alert()->html('', session('error'), 'error');
111
+        }
112
+
113
+        return view($this->route . 'create', $data);
114
+    }
115
+
116
+    /**
117
+     * create_action digunakan untuk aksi post
118
+     * lengkap dengan validatornya
119
+     */
120
+    public function create_action(Request $request)
121
+    {
122
+        /**digunakan untuk set rule validator */
123
+        $rules = [
124
+            'name'  => 'required|min:2',
125
+            'permission' => 'required',
126
+        ];
127
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
128
+        $alert = [
129
+            'required'  => 'The :attribute is required',
130
+            'min'       => ':attribute Min :min Char'
131
+        ];
132
+        $validator = Validator::make($request->all(), $rules, $alert);
133
+
134
+        if ($validator->passes()) {
135
+            /**menggunakan transaction */
136
+
137
+            $insert = [];
138
+            $name = implode('_', explode(' ', $request['name']));
139
+
140
+            foreach ($request['permission'] as $key => $value) {
141
+                $insert[] = [
142
+                    'name' => $name . '-' . $value,
143
+                    'guard_name' => 'web',
144
+                ];
145
+            }
146
+
147
+            DB::beginTransaction();
148
+            $query = Permission::insert($insert);
149
+
150
+            if ($query) {
151
+                DB::commit();
152
+                $message = 'Berhasil';
153
+                return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
154
+            } else {
155
+                DB::rollback();
156
+                $message = 'Gagal';
157
+                return redirect()->back()->with('error', Helper::parsing_alert($message));
158
+            }
159
+        }
160
+        /**kenapa menggunakan back ? karena baliknya pasti ke halaman sebelumnya */
161
+        $message = Helper::parsing_alert($validator->errors()->all());
162
+        return redirect()->back()->with('error', $message)->withInput();
163
+    }
164
+
165
+    /** update sama seperti create hanya saja digunakan untuk update (viewnya saja) */
166
+    public function update($permission_id)
167
+    {
168
+
169
+        if (session('success')) {
170
+            alert()->html('', session('success'), 'success');
171
+        }
172
+
173
+        if (session('error')) {
174
+            alert()->html('', session('error'), 'error');
175
+        }
176
+
177
+
178
+        $permission_id = Hashids::decode($permission_id);
179
+        if (!empty($permission_id)) {
180
+
181
+            $cek_role = Permission::where('id', $permission_id[0])->first();
182
+
183
+            if ($cek_role) {
184
+                $data = [
185
+                    //bawaan
186
+                    'title' => $this->title,
187
+                    'route' => $this->route,
188
+                    'data'  => $cek_role
189
+                ];
190
+                return view($this->route . 'update', $data);
191
+            }
192
+            $message = 'Id role not found or has been deleted';
193
+            return redirect()->back()->with('error', $message);
194
+        }
195
+        $message = 'Id tdak ditemukan';
196
+        return redirect()->back()->with('error', $message);
197
+    }
198
+
199
+    /**update_action POST
200
+     * Logikanya :
201
+     * 1. Cek Hashids::decode dari role_id apalah benar" di hash ?
202
+     * -iya
203
+     *  2. Cek ID yang didapatkan dari hash apakah benar adanya ?
204
+     *  -iya
205
+     *    3. proses validate
206
+     *    -iya
207
+     *      4. Proses update
208
+     *        - iya benar
209
+     *        - tidak salah
210
+     *    - tidak return error
211
+     *  - tidak return Id tdak ditemukan
212
+     * -tidak skip reutrn id null
213
+     */
214
+    public function update_action(Request $request)
215
+    {
216
+        $rules = [
217
+            'name' => 'required|min:2|unique:roles,name',
218
+        ];
219
+        $alert = [
220
+            'required'  => 'The :attribute is required',
221
+            'min'       => ':attribute Min 2 Char'
222
+        ];
223
+        $validator = Validator::make($request->all(), $rules, $alert);
224
+
225
+        $permission_id = Hashids::decode($request['id']);
226
+
227
+        if (!empty($permission_id)) {
228
+            /**cek apakah role_idnya ada ? */
229
+            $cek_role = Permission::where('id', $permission_id[0])->first();
230
+
231
+            if ($cek_role) {
232
+                /**cek apakah id rolenya benar" ada di DB ? */
233
+                if ($validator->passes()) {
234
+                    /**validatornya */
235
+
236
+                    DB::beginTransaction();
237
+                    $query = $cek_role->update($request->input());
238
+
239
+                    if ($query) {
240
+                        DB::commit();
241
+                        $message = 'Berhasil';
242
+                        return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
243
+                    } else {
244
+                        DB::rollback();
245
+                        $message = 'Gagal';
246
+                        return redirect()->back()->with('error', Helper::parsing_alert($message));
247
+                    }
248
+                }
249
+
250
+                $message = Helper::parsing_alert($validator->errors()->all());
251
+
252
+                return redirect()->back()->with('error', $message);
253
+            } else {
254
+                $message = 'Id tdak ditemukan';
255
+                return redirect()->back()->with('error', $message);
256
+            }
257
+        } else {
258
+            $message = 'Id tidak boleh kosong';
259
+            return redirect()->back()->with('error', $message);
260
+        }
261
+    }
262
+
263
+    /**digunakan untuk delete
264
+     * Logikanya :
265
+     * 1. Cek hash id
266
+     * -ya
267
+     *  2. Cek id dari hash
268
+     *  - ya
269
+     *      3. Proses delete
270
+     *      -Ya
271
+     *      -Tidak
272
+     *  - tidak return Id tidak ditemukan atau sudah dihapus
273
+     * -tidak reutrn Id tdak ditemukan
274
+     */
275
+    public function delete_action($permission_id)
276
+    {
277
+        $permission_id = Hashids::decode($permission_id);
278
+        /**cek role idnya apakah ada ? */
279
+
280
+        if (!empty($permission_id)) {
281
+
282
+            $cek_role = Permission::where('id', $permission_id[0])->first();
283
+
284
+            if ($cek_role) {
285
+                DB::beginTransaction();
286
+                $delete = $cek_role->delete();
287
+                if ($delete) {
288
+                    DB::commit();
289
+                    $message = 'Succesfully';
290
+                    $response = [
291
+                        'message' => $message,
292
+                        'status'   => true,
293
+                    ];
294
+                    return response()->json($response);
295
+                } else {
296
+                    DB::rollback();
297
+                    $message = 'Gagal';
298
+                    $response = [
299
+                        'message' => $message,
300
+                        'status'   => false,
301
+                    ];
302
+                    return response()->json($response);
303
+                }
304
+            }
305
+            $message = 'Id tidak di temukan atau sudah di hapus';
306
+            $response = [
307
+                'message' => $message,
308
+                'status'   => false,
309
+            ];
310
+            return response()->json($response);
311
+        }
312
+        $message = 'Id tdak ditemukan';
313
+        $response = [
314
+            'message' => $message,
315
+            'status'   => false,
316
+        ];
317
+        return response()->json($response);
318
+    }
319
+
320
+    //custom route
321
+
322
+    public function route()
323
+    {
324
+        return Route::group([
325
+            'as' => $this->route,
326
+            'prefix' => $this->url_prefix,
327
+            'namespace' => $this->namespace_controller
328
+        ], function () {
329
+            Route::get('/', ['as' => 'index', 'uses' => 'PermissionController@index']);
330
+            Route::get('/create', ['as' => 'create', 'uses' => 'PermissionController@create']);
331
+            Route::get('/update/{permission_id}', ['as' => 'update', 'uses' => 'PermissionController@update']);
332
+            Route::get('/delete-action/{permission_id}', ['as' => 'delete_action', 'uses' => 'PermissionController@delete_action']);
333
+            Route::get('/get-data', ['as' => 'get_data', 'uses' => 'PermissionController@getData']);
334
+
335
+            Route::post('/create-action', ['as' => 'create_action', 'uses' => 'PermissionController@create_action']);
336
+            Route::post('/update-action', ['as' => 'update_action', 'uses' => 'PermissionController@update_action']);
337
+        });
338
+    }
339
+
340
+    //end custom route
341
+}

+ 480
- 0
app/Http/Controllers/Admin/User_management/PetugasUddController.php Dosyayı Görüntüle

@@ -0,0 +1,480 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Admin\User_management;
4
+
5
+use App\Helpers\Helper;
6
+use App\Http\Controllers\Controller;
7
+use Hashids;
8
+use Illuminate\Http\Request;
9
+use Illuminate\Support\Facades\DB;
10
+use Validator;
11
+use Auth;
12
+use Illuminate\Support\Facades\Route;
13
+
14
+//load modelmu
15
+use Illuminate\Support\Str;
16
+use App\Model\User\PetugasUnitDonorDarahUdds as petugas_udd;
17
+use App\Model\Master\MasterUdd;
18
+use App\Model\ModelHasRoles;
19
+use App\User;
20
+use Illuminate\Support\Facades\Hash;
21
+use Yajra\Datatables\Datatables;
22
+
23
+class PetugasUddController extends Controller
24
+{
25
+    /**
26
+     * Untuk CRUD Biar cepat
27
+     * Silahkan ganti
28
+     * petugas_udd:: => dengan model anda
29
+     * $petugas_udd_id => ganti dengan id di model anda
30
+     */
31
+
32
+    /**
33
+     * Title untuk judul di web
34
+     * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
35
+     */
36
+    private $title = 'Admin Usermanagement | Petugas UDD';
37
+    /**jangan lupa diganti*/
38
+    private $route = 'admin.user_management.petugas_udd.'; //path awal foldernya ajah (misal folder di admin/dashboard) => 'admin.dashboard' | jangan lupa diganti
39
+    private $namespace_controller = 'Admin\User_management';
40
+    private $url_prefix = 'user-management/petugas-udd/';
41
+
42
+    public function __construct()
43
+    {
44
+        DB::enableQueryLog();
45
+        /** nyalakan jika sudah set rolenya, jika ini dinyalakan halaman ini tidak akan keluar */
46
+        $this->middleware('permission:petugas_udd-list|petugas_udd-create|petugas_udd-update|petugas_udd-delete', ['only' => ['index', 'create', 'update']]);
47
+        $this->middleware('permission:petugas_udd-create', ['only' => ['create', 'create_action']]);
48
+        $this->middleware('permission:petugas_udd-update', ['only' => ['update', 'update_action']]);
49
+        $this->middleware('permission:petugas_udd-delete', ['only' => ['delete']]);
50
+    }
51
+
52
+    /**
53
+     * Ini contoh crud yang sudah jalan
54
+     * index digunakna untuk tampilan awal dari menu yang akan dibuat
55
+     */
56
+    public function index()
57
+    {
58
+        if (session('success')) {
59
+            alert()->html('', session('success'), 'success');
60
+        }
61
+
62
+        if (session('error')) {
63
+            alert()->html('', session('error'), 'error');
64
+        }
65
+        $data = [
66
+            //bawaan
67
+            'title' => $this->title,
68
+            'route' => $this->route,
69
+        ];
70
+        return view($this->route . 'index', $data);
71
+    }
72
+
73
+    public function getData()
74
+    {
75
+        /**
76
+         * deteksi jika dia bukan superadmin
77
+         * jika super admin tampil semua uddnya
78
+         * jika tidak maka tampilin hanya uddnya dia sendiri
79
+         * */
80
+        if (!empty(Helper::is_super_admin())) {
81
+            $petugas = petugas_udd::get();
82
+        } else {
83
+            $udd_id = Auth::user()->petugas->unit_donor_darah_id;
84
+            $petugas = petugas_udd::with('udd')
85
+                ->where('unit_donor_darah_id', $udd_id)
86
+                ->get();
87
+        }
88
+        foreach ($petugas as $key => $value) {
89
+            $value->no = $key + 1;
90
+            $value->email   = $value->user->email;
91
+
92
+            $role = '';
93
+            /**get role petugas */
94
+            $data_roles = $value->user->roles()->get();
95
+            foreach ($data_roles as $key => $value_roles) {
96
+                $role       .= $value_roles->name . (($key + 1) < $data_roles->count() ? ', ' : null);
97
+            }
98
+            $value->roles   = $role;
99
+            $value->udd_pmi     =  $value->udd->nama;
100
+        }
101
+
102
+        // dd($petugas);
103
+        return Datatables::of($petugas)
104
+            ->addColumn('aksi', function ($petugas) {
105
+
106
+                /**cek role */
107
+                $aksi = '';
108
+                if (Auth::user()->can('petugas_udd-update')) {
109
+                    $aksi .= "<a href='" . route($this->route . 'update', ['petugas_udd_id' => Hashids::encode($petugas->id)]) . "' class='btn btn-sm btn-primary btn-edit'>Edit</a>";
110
+                }
111
+
112
+                if (Auth::user()->can('petugas_udd-delete')) {
113
+                    // $aksi .= "<a href='javascript:;' data-route='" . route($this->route . 'delete_action', ['petugas_udd_id' => Hashids::encode($petugas->id)]) . "' class='btn btn-danger btn-sm btn-delete'>Delete</a>";
114
+                }
115
+
116
+                return $aksi;
117
+            })
118
+            ->rawColumns(['aksi'])
119
+            ->toJson();
120
+    }
121
+
122
+    /**
123
+     * create digunakan untuk menampilkan tampilan buat
124
+     * Catatan :
125
+     * Jika rolenya = 1 (superadmin) maka munculkan uddnya untuk piliham udd
126
+     * jika rolenya != 1 maka langsung insert uddnya sesuai dengan udd User id
127
+     */
128
+    public function create()
129
+    {
130
+        $role = Helper::get_roles();
131
+        $jumlah_role = $role->count();
132
+        $limit = 100;
133
+        $take = 0;
134
+        $jumlah_looping = ceil($jumlah_role / $limit);
135
+        $arr_role = [];
136
+        for ($i = 0; $i < $jumlah_looping; $i++) {
137
+            $limit_data = 100;
138
+            $role = $role->take($limit_data)->skip($take);
139
+            $cek_data[] = $role;
140
+            $arr_role[$i] = $role;
141
+            $take = $limit;
142
+            $limit += 100;
143
+        }
144
+        $data = [
145
+            //bawaan
146
+            'title' => $this->title,
147
+            'route' => $this->route,
148
+            'roles' => $arr_role,
149
+        ];
150
+        /**get udd jika role superadmin
151
+         * ini dibagi 4 - 4
152
+         */
153
+        $is_super_admin = Helper::is_super_admin();
154
+        if (!empty($is_super_admin)) {
155
+            $udd = MasterUdd::All();
156
+            $jumlah_udd = $udd->count();
157
+            $limit = 4;
158
+            $take = 0;
159
+            $jumlah_looping = ceil($jumlah_udd / $limit);
160
+            $arr_udd = [];
161
+            for ($i = 0; $i < $jumlah_looping; $i++) {
162
+                $limit_data = 4;
163
+                $udd = $udd->take($limit_data)->skip($take);
164
+                $arr_udd[$i] = $udd;
165
+                $take = $limit;
166
+                $limit += 4;
167
+            }
168
+            $data['udds'] = $arr_udd;
169
+        }
170
+        if (session('success')) {
171
+            alert()->html('', session('success'), 'success');
172
+        }
173
+
174
+        if (session('error')) {
175
+            alert()->html('', session('error'), 'error');
176
+        }
177
+
178
+        return view($this->route . 'create', $data);
179
+    }
180
+
181
+    /**
182
+     * create_action digunakan untuk aksi post
183
+     * lengkap dengan validatornya
184
+     */
185
+    public function create_action(Request $request)
186
+    {
187
+        /**digunakan untuk set rule validator */
188
+        $rules = [
189
+            'nama'                  => 'required|min:4',
190
+            'password'              => 'required|min:6',
191
+            'role_id'               => 'required',
192
+            // 'unit_donor_darah_id'   => 'required',
193
+            'email'                 => 'required|unique:users,email',
194
+        ];
195
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
196
+        $alert = [
197
+            'unique'    => ':attribute sudah tersedia',
198
+            'required'  => 'The :attribute harus diisi',
199
+            'min'       => ':attribute minimal :min  karakter'
200
+        ];
201
+        $validator = Validator::make($request->all(), $rules, $alert);
202
+
203
+        if ($validator->passes()) {
204
+            /**menggunakan transaction */
205
+            DB::beginTransaction();
206
+            $data_user = [
207
+                'name'      => $request['nama'],
208
+                'email'     => $request['email'],
209
+                'password'  => Hash::make($request['password']),
210
+            ];
211
+            $insert_user = User::create($data_user);
212
+            $insert_user->assignRole($request['role_id']);
213
+
214
+            $data_petugas = [
215
+                'nama' => $request['nama'],
216
+                'unit_donor_darah_id' => $request['unit_donor_darah_id'] ?? Auth::user()->petugas->unit_donor_darah_id,
217
+                'user_login_id' => $insert_user->id,
218
+            ];
219
+            $insert_petugas = petugas_udd::create($data_petugas);
220
+
221
+            if ($insert_petugas && $insert_user) {
222
+                DB::commit();
223
+                $message = 'Berhasil';
224
+                return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
225
+            } else {
226
+                DB::rollback();
227
+                $message = 'Gagal';
228
+                return redirect()->back()->with('error', Helper::parsing_alert($message));
229
+            }
230
+        }
231
+        /**kenapa menggunakan back ? karena baliknya pasti ke halaman sebelumnya */
232
+        $message = Helper::parsing_alert($validator->errors()->all());
233
+        return redirect()->back()->with('error', $message)->withInput();
234
+    }
235
+
236
+    /** update sama seperti create hanya saja digunakan untuk update (viewnya saja) */
237
+    public function update($petugas_udd_id)
238
+    {
239
+
240
+        if (session('success')) {
241
+            alert()->html('', session('success'), 'success');
242
+        }
243
+
244
+        if (session('error')) {
245
+            alert()->html('', session('error'), 'error');
246
+        }
247
+
248
+
249
+        $petugas_udd_id = Hashids::decode($petugas_udd_id);
250
+        if (!empty($petugas_udd_id)) {
251
+
252
+
253
+            $cek_data = petugas_udd::where('id', $petugas_udd_id[0])->first();
254
+
255
+            if ($cek_data) {
256
+
257
+                $role = Helper::get_roles();
258
+                $jumlah_role = $role->count();
259
+                $limit = 100;
260
+                $take = 0;
261
+                $jumlah_looping = ceil($jumlah_role / $limit);
262
+                $arr_role = [];
263
+                for ($i = 0; $i < $jumlah_looping; $i++) {
264
+                    $limit_data = 100;
265
+                    $role = $role->take($limit_data)->skip($take);
266
+                    $arr_role[$i] = $role;
267
+                    $take = $limit;
268
+                    $limit += 100;
269
+                }
270
+                $data = [
271
+                    //bawaan
272
+                    'title' => $this->title,
273
+                    'route' => $this->route,
274
+                    'roles' => $arr_role,
275
+                    'data'  => $cek_data,
276
+                ];
277
+                /**get udd jika role superadmin
278
+                 * ini dibagi 4 - 4
279
+                 */
280
+                $is_super_admin = Helper::is_super_admin();
281
+                if (!empty($is_super_admin)) {
282
+                    $udd = MasterUdd::All();
283
+                    $jumlah_udd = $udd->count();
284
+                    $limit = 4;
285
+                    $take = 0;
286
+                    $jumlah_looping = ceil($jumlah_udd / $limit);
287
+                    $arr_udd = [];
288
+                    for ($i = 0; $i < $jumlah_looping; $i++) {
289
+                        $limit_data = 4;
290
+                        $udd = $udd->take($limit_data)->skip($take);
291
+                        $arr_udd[$i] = $udd;
292
+                        $take = $limit;
293
+                        $limit += 4;
294
+                    }
295
+                    $data['udds'] = $arr_udd;
296
+                }
297
+                return view($this->route . 'update', $data);
298
+            }
299
+            $message = 'Id tidak ditemukan atau sudah dihapus';
300
+            return redirect()->back()->with('error', $message);
301
+        }
302
+        $message = 'Id tdak ditemukan';
303
+        return redirect()->back()->with('error', $message);
304
+    }
305
+
306
+    /**update_action POST
307
+     * Logikanya :
308
+     * 1. Cek Hashids::decode dari data_id apalah benar" di hash ?
309
+     * -iya
310
+     *  2. Cek ID yang didapatkan dari hash apakah benar adanya ?
311
+     *  -iya
312
+     *    3. proses validate
313
+     *    -iya
314
+     *      4. Proses update
315
+     *        - iya benar
316
+     *        - tidak salah
317
+     *    - tidak return error
318
+     *  - tidak return Id tdak ditemukan
319
+     * -tidak skip reutrn id null
320
+     */
321
+    public function update_action(Request $request)
322
+    {
323
+        $rules = [
324
+            'nama'                  => 'required|min:4',
325
+            'role_id'               => 'required',
326
+            // 'unit_donor_darah_id'   => 'required'
327
+        ];
328
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
329
+        $alert = [
330
+            'required'  => 'The :attribute harus diisi',
331
+            'min'       => ':attribute minimal :min  karakter'
332
+        ];
333
+        $validator = Validator::make($request->all(), $rules, $alert);
334
+
335
+        $petugas_udd_id = Hashids::decode($request['petugas_id']);
336
+
337
+        if (!empty($petugas_udd_id)) {
338
+            /**cek apakah data_idnya ada ? */
339
+            $cek_data = petugas_udd::where('id', $petugas_udd_id[0])->first();
340
+
341
+            if ($cek_data) {
342
+                $cek_email = User::where('id', '!=', $cek_data->user->id)
343
+                    ->where(function ($query) use ($request) {
344
+                        $query->where('email', $request['email']);
345
+                    })
346
+                    ->first();
347
+                if (!empty($cek_email)) {
348
+                    $message = 'Email sudah digunakan';
349
+                    return redirect()->back()->withInput()->with('error', $message);
350
+                }
351
+                /**cek apakah id data benar" ada di DB ? */
352
+                if ($validator->passes()) {
353
+                    /**validatornya */
354
+
355
+                    DB::beginTransaction();
356
+                    $data_user = [
357
+                        'name'  => $request['nama'],
358
+                        'email' => $request['email'],
359
+                    ];
360
+                    if ($request['password']) {
361
+                        $length = Str::of($request['password'])->length();
362
+                        if ($length < 6) {
363
+                            $message = 'Password minimal 6 karakter';
364
+                            return redirect()->back()->withInput()->with('error', $message);
365
+                        }
366
+                        $data_user['password'] = Hash::make($request['password']);
367
+                    }
368
+                    /**delete roles */
369
+                    ModelHasRoles::where('model_id', $cek_data->user->id)->delete();
370
+                    $find_user = User::findOrFail($cek_data->user->id);
371
+                    $update_user = $find_user->update($data_user);
372
+                    $find_user->assignRole($request['role_id']);
373
+                    $data_petugas = [
374
+                        'nama'                  => $request['nama'],
375
+                        'unit_donor_darah_id'   => $request['unit_donor_darah_id'] ?? Auth::user()->petugas->unit_donor_darah_id,
376
+                    ];
377
+                    $update_petugas = $cek_data->update($data_petugas);
378
+
379
+                    if ($update_petugas && $update_user) {
380
+                        DB::commit();
381
+                        $message = 'Berhasil';
382
+                        return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
383
+                    } else {
384
+                        DB::rollback();
385
+                        $message = 'Gagal';
386
+                        return redirect()->back()->with('error', Helper::parsing_alert($message));
387
+                    }
388
+                }
389
+
390
+                $message = Helper::parsing_alert($validator->errors()->all());
391
+
392
+                return redirect()->back()->with('error', $message);
393
+            } else {
394
+                $message = 'Id tdak ditemukan';
395
+                return redirect()->back()->with('error', $message);
396
+            }
397
+        } else {
398
+            $message = 'Id tidak boleh kosong';
399
+            return redirect()->back()->with('error', $message);
400
+        }
401
+    }
402
+
403
+    /**digunakan untuk delete
404
+     * Logikanya :
405
+     * 1. Cek hash id
406
+     * -ya
407
+     *  2. Cek id dari hash
408
+     *  - ya
409
+     *      3. Proses delete
410
+     *      -Ya
411
+     *      -Tidak
412
+     *  - tidak return Id tidak ditemukan atau sudah dihapus
413
+     * -tidak reutrn Id tdak ditemukan
414
+     */
415
+    public function delete_action($petugas_udd_id)
416
+    {
417
+        $petugas_udd_id = Hashids::decode($petugas_udd_id);
418
+        /**cek idnya apakah ada ? */
419
+
420
+        if (!empty($petugas_udd_id)) {
421
+
422
+            $cek_data = petugas_udd::where('id', $petugas_udd_id[0])->first();
423
+
424
+            if ($cek_data) {
425
+                DB::beginTransaction();
426
+                $delete = $cek_data->delete();
427
+                if ($delete) {
428
+                    DB::commit();
429
+                    $message = 'Succesfully';
430
+                    $response = [
431
+                        'message' => $message,
432
+                        'status'   => true,
433
+                    ];
434
+                    return response()->json($response);
435
+                } else {
436
+                    DB::rollback();
437
+                    $message = 'Gagal';
438
+                    $response = [
439
+                        'message' => $message,
440
+                        'status'   => false,
441
+                    ];
442
+                    return response()->json($response);
443
+                }
444
+            }
445
+            $message = 'Id tidak ditemukan atau sudah dihapus';
446
+            $response = [
447
+                'message' => $message,
448
+                'status'   => false,
449
+            ];
450
+            return response()->json($response);
451
+        }
452
+        $message = 'Id tdak ditemukan';
453
+        $response = [
454
+            'message' => $message,
455
+            'status'   => false,
456
+        ];
457
+        return response()->json($response);
458
+    }
459
+      //custom route
460
+
461
+      public function route()
462
+      {
463
+          return Route::group([
464
+              'as' => $this->route,
465
+              'prefix' => $this->url_prefix,
466
+              'namespace' => $this->namespace_controller
467
+          ], function () {
468
+            Route::get('/', ['as' => 'index', 'uses' => 'PetugasUddController@index']);
469
+            Route::get('/create', ['as' => 'create', 'uses' => 'PetugasUddController@create']);
470
+            Route::get('/update/{petugas_udd_id}', ['as' => 'update', 'uses' => 'PetugasUddController@update']);
471
+            Route::get('/delete-action/{petugas_udd_id}', ['as' => 'delete_action', 'uses' => 'PetugasUddController@delete_action']);
472
+            Route::get('/get-data', ['as' => 'get_data', 'uses' => 'PetugasUddController@getData']);
473
+
474
+            Route::post('/create-action', ['as' => 'create_action', 'uses' => 'PetugasUddController@create_action']);
475
+            Route::post('/update-action', ['as' => 'update_action', 'uses' => 'PetugasUddController@update_action']);
476
+          });
477
+      }
478
+
479
+      //end custom route
480
+}

+ 402
- 0
app/Http/Controllers/Admin/User_management/RoleController.php Dosyayı Görüntüle

@@ -0,0 +1,402 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Admin\User_management;
4
+
5
+use App\Helpers\Helper;
6
+use App\Http\Controllers\Controller;
7
+use Illuminate\Http\Request;
8
+use Illuminate\Support\Facades\DB;
9
+use Validator;
10
+use Hashids;
11
+use Auth;
12
+use Illuminate\Support\Facades\Route;
13
+
14
+/**model */
15
+
16
+use Spatie\Permission\Models\Permission;
17
+use Spatie\Permission\Models\Role;
18
+use App\Model\RoleHasPermission;
19
+use Yajra\Datatables\Datatables;
20
+
21
+class RoleController extends Controller
22
+{
23
+
24
+    /**
25
+     * Title untuk judul di web
26
+     * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
27
+     */
28
+    private $title = 'Admin User Magement | Role';
29
+    private $route = 'admin.user_management.role.'; //path awal foldernya ajah (misal folder di admin/dashboard) => 'admin.dashboard'
30
+    private $namespace_controller = 'Admin\User_management';
31
+    private $url_prefix = 'user-management/role/';
32
+    public function __construct()
33
+    {
34
+        // DB::getQueryLog();
35
+        // $this->middleware('permission:role-list|role-create|role-update|role-delete', ['only' => ['index', 'create', 'update']]);
36
+        // $this->middleware('permission:role-create', ['only' => ['create', 'create_action']]);
37
+        // $this->middleware('permission:role-update', ['only' => ['update', 'update_action']]);
38
+        // $this->middleware('permission:role-delete', ['only' => ['delete']]);
39
+    }
40
+
41
+    /**
42
+     * Ini contoh crud yang sudah jalan
43
+     * index digunakna untuk tampilan awal dari menu yang akan dibuat
44
+     * session" itu ambil dari sweetalert langsung jadi udah langsung digunakan
45
+     * untuk yang index susuannya begitu, kalau mau menambahkan silahkan
46
+     */
47
+    public function index()
48
+    {
49
+        if (session('success')) {
50
+            alert()->html('', session('success'), 'success');
51
+        }
52
+
53
+        if (session('error')) {
54
+            alert()->html('', session('error'), 'error');
55
+        }
56
+
57
+        $data = [
58
+            //bawaan
59
+            'title' => $this->title,
60
+            'route' => $this->route,
61
+        ];
62
+        return view($this->route . 'index', $data);
63
+    }
64
+
65
+    public function getData()
66
+    {
67
+        $query = Role::query();
68
+        return Datatables::of($query)
69
+            ->addIndexColumn()
70
+            ->addColumn('aksi', function ($query) {
71
+
72
+                /**cek role */
73
+                $aksi = '';
74
+                if (Auth::user()->can('role-update')) {
75
+                    $aksi .= "<a href='" . route($this->route . 'update', ['role_id' => Hashids::encode($query->id)]) . "' class='btn btn-sm btn-primary btn-edit'>Edit</a>";
76
+                }
77
+
78
+                if (Auth::user()->can('role-delete')) {
79
+                    // $aksi .= "<a href='javascript:;' data-route='" . route($this->route . 'delete_action', ['role_id' => Hashids::encode($query->id)]) . "' class='btn btn-danger btn-sm btn-delete'>Delete</a>";
80
+                }
81
+
82
+                return $aksi;
83
+            })
84
+            ->rawColumns(['aksi'])
85
+            ->toJson();
86
+    }
87
+
88
+    /**
89
+     * create digunakan untuk menampilkan tampilan buat
90
+     */
91
+    public function create()
92
+    {
93
+        /**set permission dengan cara dibagi 4 - 4 */
94
+        $permission = Helper::get_permission_by_role();
95
+        // if()
96
+
97
+        $jumlah_permission = $permission->count();
98
+        $limit = 4;
99
+        $take = 0;
100
+        $jumlah_looping = ceil($jumlah_permission / $limit);
101
+        $arr_permission = [];
102
+        for ($i = 0; $i < $jumlah_looping; $i++) {
103
+            // $cek_limit[] = $limit;
104
+            // $cek_take[] = $take;
105
+            $limit_data = 4;
106
+            $permission = Permission::take($limit_data)->skip($take)->get();
107
+            $cek_permission[] = $permission;
108
+            $arr_permission[$i] = $permission;
109
+            $take = $limit;
110
+            $limit += 4;
111
+        }
112
+        // dd($arr_permission);
113
+        /**end set permission */
114
+        $data = [
115
+            //bawaan
116
+            'title' => $this->title,
117
+            'route' => $this->route,
118
+            'data'  => $arr_permission,
119
+        ];
120
+
121
+        if (session('success')) {
122
+            alert()->html('', session('success'), 'success');
123
+        }
124
+
125
+        if (session('error')) {
126
+            alert()->html('', session('error'), 'error');
127
+        }
128
+
129
+        return view($this->route . 'create', $data);
130
+    }
131
+
132
+    /**
133
+     * create_action digunakan untuk aksi post
134
+     * lengkap dengan validatornya
135
+     */
136
+    public function create_action(Request $request)
137
+    {
138
+        /**digunakan untuk set rule validator */
139
+
140
+        $cek_permission_id = !empty($request['permission_id']);
141
+        // dd($cek_permission_id);
142
+
143
+        if ($cek_permission_id) {
144
+            $rules = [
145
+                'name' => 'required|min:2|unique:roles,name',
146
+            ];
147
+            /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
148
+            $alert = [
149
+                'required'  => 'The :attribute is required',
150
+                'min'       => ':attribute Min 2 Char'
151
+            ];
152
+            $validator = Validator::make($request->all(), $rules, $alert);
153
+
154
+            if ($validator->passes()) {
155
+                /**menggunakan transaction */
156
+                DB::beginTransaction();
157
+                $insert_role = Role::create($request->only('name'));
158
+                $data_has_role = [];
159
+                foreach ($request['permission_id'] as $key => $value) {
160
+                    $data_has_role[] = [
161
+                        'permission_id' => $value,
162
+                        'role_id'       => $insert_role->id,
163
+                    ];
164
+                }
165
+                $insert_has_role = RoleHasPermission::insert($data_has_role);
166
+
167
+                if ($insert_role && $insert_has_role) {
168
+                    DB::commit();
169
+                    $message = 'Berhasil';
170
+                    return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
171
+                } else {
172
+                    DB::rollback();
173
+                    $message = 'Gagal';
174
+                    return redirect()->back()->with('error', Helper::parsing_alert($message));
175
+                }
176
+            }
177
+            /**kenapa menggunakan back ? karena baliknya pasti ke halaman sebelumnya */
178
+            $message = Helper::parsing_alert($validator->errors()->all());
179
+            return redirect()->back()->with('error', $message)->withInput();
180
+        }
181
+        $message = 'Please filled the permission least one';
182
+        return redirect()->back()->with('error', $message)->withInput();
183
+    }
184
+
185
+    /** update sama seperti create hanya saja digunakan untuk update (viewnya saja) */
186
+    public function update($role_id)
187
+    {
188
+
189
+        if (session('success')) {
190
+            alert()->html('', session('success'), 'success');
191
+        }
192
+
193
+        if (session('error')) {
194
+            alert()->html('', session('error'), 'error');
195
+        }
196
+
197
+
198
+        $role_id = Hashids::decode($role_id);
199
+        if (!empty($role_id)) {
200
+
201
+            $cek_role = Role::where('id', $role_id[0])->first();
202
+            /**set permission dengan cara dibagi 4 - 4 */
203
+            $permission = Permission::get();
204
+            $jumlah_permission = $permission->count();
205
+            $limit = 4;
206
+            $take = 0;
207
+            $jumlah_looping = ceil($jumlah_permission / $limit);
208
+            $arr_permission = [];
209
+            for ($i = 0; $i < $jumlah_looping; $i++) {
210
+                // $cek_limit[] = $limit;
211
+                // $cek_take[] = $take;
212
+                $limit_data = 4;
213
+                $permission = Permission::take($limit_data)->skip($take)->get();
214
+                $cek_permission[] = $permission;
215
+                $arr_permission[$i] = $permission;
216
+                $take = $limit;
217
+                $limit += 4;
218
+            }
219
+            /**end set permission */
220
+            /**menambahkan object permission di dalam role, digunakan untuk cek diviewnya nanti permissionnya mana aja yang dipilih */
221
+            $cek_role->permission = RoleHasPermission::where('role_id', $cek_role->id)
222
+                ->get()
223
+                ->pluck('permission_id')
224
+                ->toArray();
225
+
226
+            if ($cek_role) {
227
+                $data = [
228
+                    //bawaan
229
+                    'title' => $this->title,
230
+                    'route' => $this->route,
231
+                    'data'  => $cek_role,
232
+                    'permission' => $arr_permission,
233
+                ];
234
+                return view($this->route . 'update', $data);
235
+            }
236
+            $message = 'Id role not found or has been deleted';
237
+            return redirect()->back()->with('error', $message);
238
+        }
239
+        $message = 'Id tdak ditemukan';
240
+        return redirect()->back()->with('error', $message);
241
+    }
242
+
243
+    /**update_action POST
244
+     * LOGIKANYA :
245
+     * 1. Cek Hashids::decode dari role_id apalah benar" di hash ?
246
+     * -iya
247
+     *  2. Cek ID yang didapatkan dari hash apakah benar adanya ?
248
+     *  -iya
249
+     *    3. proses validate
250
+     *    -iya
251
+     *      4. Proses update
252
+     *        - iya benar
253
+     *        - tidak salah
254
+     *    - tidak return error
255
+     *  - tidak return Id tdak ditemukan
256
+     * -tidak skip reutrn id null
257
+     */
258
+    public function update_action(Request $request)
259
+    {
260
+        $rules = [
261
+            'name' => 'required|min:2',
262
+        ];
263
+        $alert = [
264
+            'required'  => 'The :attribute is required',
265
+            'min'       => ':attribute Min 2 Char'
266
+        ];
267
+        $validator = Validator::make($request->all(), $rules, $alert);
268
+
269
+        $role_id = Hashids::decode($request['id']);
270
+
271
+        $cek_permission_id = !empty($request['permission_id']);
272
+
273
+        if ($cek_permission_id) {
274
+            if (!empty($role_id)) {
275
+                /**cek apakah role_idnya ada ? */
276
+                $cek_role = Role::where('id', $role_id[0])->first();
277
+
278
+                if ($cek_role) {
279
+                    /**cek apakah id rolenya benar" ada di DB ? */
280
+                    if ($validator->passes()) {
281
+                        /**validatornya */
282
+
283
+                        DB::beginTransaction();
284
+                        $update_role = $cek_role->update($request->only('name'));
285
+
286
+                        /**delete has role dlu */
287
+                        RoleHasPermission::where('role_id', $cek_role->id)->delete();
288
+                        /**proses input has role */
289
+                        $data_has_role = [];
290
+                        foreach ($request['permission_id'] as $key => $value) {
291
+                            $data_has_role[] = [
292
+                                'permission_id' => $value,
293
+                                'role_id'       => $cek_role->id
294
+                            ];
295
+                        }
296
+                        $insert_has_role = RoleHasPermission::insert($data_has_role);
297
+
298
+                        if ($update_role && $insert_has_role) {
299
+                            DB::commit();
300
+                            $message = 'Berhasil';
301
+                            return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
302
+                        } else {
303
+                            DB::rollback();
304
+                            $message = 'Gagal';
305
+                            return redirect()->back()->with('error', Helper::parsing_alert($message));
306
+                        }
307
+                    }
308
+
309
+                    $message = Helper::parsing_alert($validator->errors()->all());
310
+
311
+                    return redirect()->back()->with('error', $message);
312
+                } else {
313
+                    $message = 'Id tdak ditemukan';
314
+                    return redirect()->back()->with('error', $message);
315
+                }
316
+            } else {
317
+                $message = 'Id tidak boleh kosong';
318
+                return redirect()->back()->with('error', $message);
319
+            }
320
+        }
321
+        $message = 'Permission must be filled least one';
322
+        return redirect()->back()->with('error', $message);
323
+    }
324
+
325
+    /**digunakan untuk delete
326
+     * Logikanya :
327
+     * 1. Cek hash id
328
+     * -ya
329
+     *  2. Cek id dari hash
330
+     *  - ya
331
+     *      3. Proses delete
332
+     *      -Ya
333
+     *      -Tidak
334
+     *  - tidak return Id tidak ditemukan atau sudah dihapus
335
+     * -tidak reutrn Id tdak ditemukan
336
+     */
337
+    public function delete_action($role_id)
338
+    {
339
+        $role_id = Hashids::decode($role_id);
340
+        /**cek role idnya apakah ada ? */
341
+
342
+        if (!empty($role_id)) {
343
+
344
+            $cek_role = Role::where('id', $role_id[0])->first();
345
+
346
+            if ($cek_role) {
347
+                DB::beginTransaction();
348
+                $delete = $cek_role->delete();
349
+                if ($delete) {
350
+                    DB::commit();
351
+                    $message = 'Succesfully';
352
+                    $response = [
353
+                        'message' => $message,
354
+                        'status'   => true,
355
+                    ];
356
+                    return response()->json($response);
357
+                } else {
358
+                    DB::rollback();
359
+                    $message = 'Gagal';
360
+                    $response = [
361
+                        'message' => $message,
362
+                        'status'   => false,
363
+                    ];
364
+                    return response()->json($response);
365
+                }
366
+            }
367
+            $message = 'Id tidak di temukan atau sudah di hapus';
368
+            $response = [
369
+                'message' => $message,
370
+                'status'   => false,
371
+            ];
372
+            return response()->json($response);
373
+        }
374
+        $message = 'Id tdak ditemukan';
375
+        $response = [
376
+            'message' => $message,
377
+            'status'   => false,
378
+        ];
379
+        return response()->json($response);
380
+    }
381
+     //custom route
382
+
383
+     public function route()
384
+     {
385
+         return Route::group([
386
+             'as' => $this->route,
387
+             'prefix' => $this->url_prefix,
388
+             'namespace' => $this->namespace_controller
389
+         ], function () {
390
+            Route::get('/', ['as' => 'index', 'uses' => 'RoleController@index']);
391
+            Route::get('/create', ['as' => 'create', 'uses' => 'RoleController@create']);
392
+            Route::get('/update/{role_id}', ['as' => 'update', 'uses' => 'RoleController@update']);
393
+            Route::get('/delete-action/{role_id}', ['as' => 'delete_action', 'uses' => 'RoleController@delete_action']);
394
+            Route::get('/get-data', ['as' => 'get_data', 'uses' => 'RoleController@getData']);
395
+
396
+            Route::post('/create-action', ['as' => 'create_action', 'uses' => 'RoleController@create_action']);
397
+            Route::post('/update-action', ['as' => 'update_action', 'uses' => 'RoleController@update_action']);
398
+         });
399
+     }
400
+
401
+     //end custom route
402
+}

+ 448
- 0
app/Http/Controllers/Admin/User_management/RumahSakitController.php Dosyayı Görüntüle

@@ -0,0 +1,448 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Admin\User_management;
4
+
5
+use App\Helpers\Helper;
6
+use App\Http\Controllers\Controller;
7
+use App\Model\Master\MasterRumahSakitKepememilikans;
8
+use App\Model\Master\MasterRumahSakitType;
9
+use App\Model\ModelHasRoles;
10
+use Hashids;
11
+use Illuminate\Http\Request;
12
+use Illuminate\Support\Facades\DB;
13
+use Validator;
14
+use Yajra\Datatables\Datatables;
15
+use Auth;
16
+use Illuminate\Support\Facades\Route;
17
+
18
+//load modelmu
19
+use Illuminate\Support\Str;
20
+use App\Model\User\MasterRumahSakits as user_rs;
21
+use App\User;
22
+use Spatie\Permission\Models\Role;
23
+use Hash;
24
+
25
+
26
+class RumahSakitController extends Controller
27
+{
28
+    /**
29
+     * Title untuk judul di web
30
+     * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
31
+     */
32
+    private $title = 'User Managemen | Rumah Sakit';
33
+    /**jangan lupa diganti*/
34
+    private $route = 'admin.user_management.rumah_sakit.'; //path awal foldernya ajah (misal folder di admin/dashboard) => 'admin.dashboard' | jangan lupa diganti
35
+    private $namespace_controller = 'Admin\User_management';
36
+    private $url_prefix = 'user-management/rumah-sakit/';
37
+
38
+    public function __construct()
39
+    {
40
+        DB::enableQueryLog();
41
+        /** nyalakan jika sudah set rolenya, jika ini dinyalakan halaman ini tidak akan keluar */
42
+        $this->middleware('permission:rumah_sakit-list|rumah_sakit-create|rumah_sakit-update|rumah_sakit-delete', ['only' => ['index', 'create', 'update']]);
43
+        $this->middleware('permission:rumah_sakit-create', ['only' => ['create', 'create_action']]);
44
+        $this->middleware('permission:rumah_sakit-update', ['only' => ['update', 'update_action']]);
45
+        $this->middleware('permission:rumah_sakit-delete', ['only' => ['delete']]);
46
+    }
47
+
48
+    /**
49
+     * Ini contoh crud yang sudah jalan
50
+     * index digunakna untuk tampilan awal dari menu yang akan dibuat
51
+     * Untuk CRUD Biar cepat
52
+     * Silahkan ganti
53
+     * user_rs:: => dengan model anda
54
+     * $rumah_sakit_id => ganti dengan id di model anda
55
+     * rumah_sakit_id => jangan lupa disesuaikan dengan yang dideclare di route
56
+     */
57
+
58
+
59
+    public function index()
60
+    {
61
+        if (session('success')) {
62
+            alert()->html('', session('success'), 'success');
63
+        }
64
+
65
+        if (session('error')) {
66
+            alert()->html('', session('error'), 'error');
67
+        }
68
+
69
+        $data = [
70
+            //bawaan
71
+            'title' => $this->title,
72
+            'route' => $this->route,
73
+        ];
74
+        // dd($data);
75
+        return view($this->route . 'index', $data);
76
+    }
77
+    /**
78
+     *digunakan untuk datatable yajra
79
+     *querynya bisa ganti" sesuai hati
80
+     */
81
+    public function getData()
82
+    {
83
+        $query = user_rs::All();
84
+        foreach ($query as $key => $value) {
85
+            $value->no = ($key + 1);
86
+            $value->email = $value->user->email ?? null;
87
+        }
88
+        return Datatables::of($query)
89
+            ->addColumn('aksi', function ($query) {
90
+                $aksi = '';
91
+                if (Auth::user()->can('rumah_sakit-update')) {
92
+                    $aksi .= "<a href='" . route($this->route . 'update', ['rumah_sakit_id' => Hashids::encode($query->id)]) . "' class='btn btn-sm btn-primary btn-edit'>Edit</a>";
93
+                }
94
+
95
+                if (Auth::user()->can('rumah_sakit-delete')) {
96
+                    // $aksi .= "<a href='javascript:;' data-route='" . route($this->route . 'delete_action', ['rumah_sakit_id' => Hashids::encode($query->id)]) . "' class='btn btn-danger btn-sm btn-delete'>Delete</a>";
97
+                }
98
+
99
+                return $aksi;
100
+            })
101
+            ->rawColumns(['aksi'])
102
+            ->toJson();
103
+    }
104
+
105
+    /**
106
+     * create digunakan untuk menampilkan tampilan buat
107
+     */
108
+    public function create()
109
+    {
110
+        $data = [
111
+            //bawaan
112
+            'title'     => $this->title,
113
+            'route'     => $this->route,
114
+            'roles'     => Role::where('id',5)->get(),
115
+        ];
116
+
117
+        if (session('success')) {
118
+            alert()->html('', session('success'), 'success');
119
+        }
120
+
121
+        if (session('error')) {
122
+            alert()->html('', session('error'), 'error');
123
+        }
124
+
125
+        return view($this->route . 'create', $data);
126
+    }
127
+
128
+    /**
129
+     * create_action digunakan untuk aksi post
130
+     * lengkap dengan validatornya
131
+     */
132
+    public function create_action(Request $request)
133
+    {
134
+        //declare post untuk simpan semua request yang diinputkan oleh form name=""
135
+        $post = $request->all();
136
+        // dd($post);
137
+        /**digunakan untuk set rule validator */
138
+        $rules = [
139
+            'role_id'          => 'required',
140
+            'nama'             => 'required',
141
+            'deskripsi'        => 'required',
142
+            'email'            => 'required|unique:users,email',
143
+            'password'         => 'required:min:6',
144
+            'alamat'           => 'required',
145
+            'nama_bank_darah'  => 'required',
146
+            'kode_rumah_sakit' => 'required',
147
+            'jenis'            => 'required',
148
+            'kepemilikan'      => 'required',
149
+        ];
150
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
151
+        $alert = [
152
+            'required' => ':attribute',
153
+            'unique'   => ':attribute telah terpakai',
154
+            'min'      => ':attribute :min karakter',
155
+        ];
156
+        $validator = Validator::make($post, $rules, $alert);
157
+
158
+        if ($validator->passes()) {
159
+            /**menggunakan transaction */
160
+            DB::beginTransaction();
161
+            $user_rs = [
162
+                'email'    => $post['email'],
163
+                'name'     => $post['nama'],
164
+                'password' => Hash::make($post['password']),
165
+            ];
166
+            $insert_user = User::create($user_rs);
167
+            $insert_user->assignRole($request['role_id']);
168
+
169
+                          $data_user_rs     = $request->only(['nama', 'deskripsi', 'alamat', 'nama_bank_darah', 'kode_rumah_sakit']);
170
+            $data_user_rs['user_login_id']  = $insert_user->id;
171
+            $data_user_rs['type_id']        = $post['jenis'];
172
+            $data_user_rs['kepemilikan_id'] = $post['kepemilikan'];
173
+                          $insert_user_rs   = user_rs::create($data_user_rs);
174
+
175
+            if ($insert_user_rs) {
176
+                DB::commit();
177
+                $message = 'Berhasil';
178
+                return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
179
+            } else {
180
+                DB::rollback();
181
+                $message = 'Gagal';
182
+                return redirect()->back()->with('error', Helper::parsing_alert($message));
183
+            }
184
+        }
185
+        /**kenapa menggunakan back ? karena baliknya pasti ke halaman sebelumnya */
186
+        $message = Helper::parsing_alert($validator->errors()->all());
187
+        return redirect()->back()->with('error', $message)->withInput();
188
+    }
189
+
190
+    /** update sama seperti create hanya saja digunakan untuk update (viewnya saja) */
191
+    public function update($rumah_sakit_id)
192
+    {
193
+
194
+        if (session('success')) {
195
+            alert()->html('', session('success'), 'success');
196
+        }
197
+
198
+        if (session('error')) {
199
+            alert()->html('', session('error'), 'error');
200
+        }
201
+
202
+
203
+        $rumah_sakit_id = Hashids::decode($rumah_sakit_id);
204
+        if (!empty($rumah_sakit_id)) {
205
+
206
+            $cek_data = user_rs::where('id', $rumah_sakit_id[0])->first();
207
+
208
+            if ($cek_data) {
209
+                $data = [
210
+                    //bawaan
211
+                    'title' => $this->title,
212
+                    'route' => $this->route,
213
+                    'data'  => $cek_data,
214
+                    'roles'     => Role::where('id',5)->get()
215
+                ];
216
+                return view($this->route . 'update', $data);
217
+            }
218
+            $message = 'Id tidak ditemukan atau sudah dihapus';
219
+            return redirect()->back()->with('error', $message);
220
+        }
221
+        $message = 'Id tdak ditemukan';
222
+        return redirect()->back()->with('error', $message);
223
+    }
224
+
225
+    /**update_action POST
226
+     * Logikanya :
227
+     * 1. Cek Hashids::decode dari data_id apalah benar" di hash ?
228
+     * -iya
229
+     *  2. Cek ID yang didapatkan dari hash apakah benar adanya ?
230
+     *  -iya
231
+     *    3. proses validate
232
+     *    -iya
233
+     *      4. Proses update
234
+     *        - iya benar
235
+     *        - tidak salah
236
+     *    - tidak return error
237
+     *  - tidak return Id tdak ditemukan
238
+     * -tidak skip reutrn id null
239
+     */
240
+    public function update_action(Request $request)
241
+    {
242
+        $post = $request->all();
243
+        /**digunakan untuk set rule validator */
244
+        // dd($post);
245
+        $rules = [
246
+            'role_id'         => 'required',
247
+            'nama'            => 'required',
248
+            'deskripsi'       => 'required',
249
+            'email'           => 'required',
250
+            'alamat'          => 'required',
251
+            'nama_bank_darah' => 'required',
252
+            'jenis'           => 'required',
253
+            'kepemilikan'     => 'required',
254
+        ];
255
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
256
+        $alert = [
257
+            'required' => ':attribute',
258
+        ];
259
+        $validator = Validator::make($post, $rules, $alert);
260
+
261
+        $rumah_sakit_id = Hashids::decode($request['id']);
262
+
263
+        if (!empty($rumah_sakit_id)) {
264
+            /**cek apakah data_idnya ada ? */
265
+            $cek_data = user_rs::where('id', $rumah_sakit_id[0])->first();
266
+
267
+            if ($cek_data) {
268
+                /**cek apakah id data benar" ada di DB ? */
269
+                if ($validator->passes()) {
270
+                    // dd($post);
271
+                    /**validatornya */
272
+
273
+                    DB::beginTransaction();
274
+                    $data_user = [
275
+                        'name'  => $request['nama'],
276
+                        'email' => $request['email'],
277
+                    ];
278
+                    if ($request['password']) {
279
+                        $length = Str::of($request['password'])->length();
280
+                        if ($length < 6) {
281
+                            $message = 'Password minimal 6 karakter';
282
+                            return redirect()->back()->withInput()->with('error', $message);
283
+                        }
284
+                        $data_user['password'] = Hash::make($request['password']);
285
+                    }
286
+                    /**delete roles */
287
+                    ModelHasRoles::where('model_id', $cek_data->user->id)->delete();
288
+                    $find_user = User::findOrFail($cek_data->user->id);
289
+                    $update_user = $find_user->update($data_user);
290
+                    $find_user->assignRole($request['role_id']);
291
+
292
+                    $data_rs = $request->only(['nama', 'deskripsi', 'alamat', 'nama_bank_darah','kode_rumah_sakit']);
293
+                    $data_rs['type_id']        = $post['jenis'];
294
+                    $data_rs['kepemilikan_id'] = $post['kepemilikan'];
295
+                    $update_rs = $cek_data->update($data_rs);
296
+
297
+                    if ($update_user && $update_rs) {
298
+                        DB::commit();
299
+                        $message = 'Berhasil';
300
+                        return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
301
+                    } else {
302
+                        DB::rollback();
303
+                        $message = 'Gagal';
304
+                        return redirect()->back()->with('error', Helper::parsing_alert($message));
305
+                    }
306
+                }
307
+
308
+                $message = Helper::parsing_alert($validator->errors()->all());
309
+
310
+                return redirect()->back()->with('error', $message);
311
+            } else {
312
+                $message = 'Id tdak ditemukan';
313
+                return redirect()->back()->with('error', $message);
314
+            }
315
+        } else {
316
+            $message = 'Id tidak boleh kosong';
317
+            return redirect()->back()->with('error', $message);
318
+        }
319
+    }
320
+
321
+    /**digunakan untuk delete
322
+     * Logikanya :
323
+     * 1. Cek hash id
324
+     * -ya
325
+     *  2. Cek id dari hash
326
+     *  - ya
327
+     *      3. Proses delete
328
+     *      -Ya
329
+     *      -Tidak
330
+     *  - tidak return Id tidak ditemukan atau sudah dihapus
331
+     * -tidak reutrn Id tdak ditemukan
332
+     */
333
+    public function delete_action($rumah_sakit_id)
334
+    {
335
+        $rumah_sakit_id = Hashids::decode($rumah_sakit_id);
336
+        /**cek idnya apakah ada ? */
337
+
338
+        if (!empty($rumah_sakit_id)) {
339
+
340
+            $cek_data = user_rs::where('id', $rumah_sakit_id[0])->first();
341
+
342
+            if ($cek_data) {
343
+                DB::beginTransaction();
344
+                $delete = $cek_data->delete();
345
+                if ($delete) {
346
+                    DB::commit();
347
+                    $message = 'Succesfully';
348
+                    $response = [
349
+                        'message' => $message,
350
+                        'status'   => true,
351
+                    ];
352
+                    return response()->json($response);
353
+                } else {
354
+                    DB::rollback();
355
+                    $message = 'Gagal';
356
+                    $response = [
357
+                        'message' => $message,
358
+                        'status'   => false,
359
+                    ];
360
+                    return response()->json($response);
361
+                }
362
+            }
363
+            $message = 'Id tidak ditemukan atau sudah dihapus';
364
+            $response = [
365
+                'message' => $message,
366
+                'status'   => false,
367
+            ];
368
+            return response()->json($response);
369
+        }
370
+        $message = 'Id tdak ditemukan';
371
+        $response = [
372
+            'message' => $message,
373
+            'status'   => false,
374
+        ];
375
+        return response()->json($response);
376
+    }
377
+
378
+    public function selectJenisRs(Request $request){
379
+        if (session('error')) {
380
+            alert()->html('', session('error'), 'error');
381
+        }
382
+        $term = trim($request['petugas']);
383
+        $query = MasterRumahSakitType::take(5);
384
+
385
+        if (!empty($request['not_in'])) {
386
+            $query = $query->whereNotIn('id', [$request['not_in']]);
387
+        }
388
+        if (!empty($term)) {
389
+            $query = $query->where('nama', 'like', '%' . $term . '%');
390
+        }
391
+        $query = $query->get();
392
+
393
+        $response = [];
394
+
395
+        foreach ($query as $key => $value) {
396
+            $response[] = ['id' => $value->id, 'text' => $value->nama];
397
+        }
398
+
399
+        return response()->json($response);
400
+    }
401
+
402
+    public function selectKepemilikanRs(Request $request){
403
+        if (session('error')) {
404
+            alert()->html('', session('error'), 'error');
405
+        }
406
+        $term = trim($request['petugas']);
407
+        $query = MasterRumahSakitKepememilikans::take(5);
408
+
409
+        if (!empty($request['not_in'])) {
410
+            $query = $query->whereNotIn('id', [$request['not_in']]);
411
+        }
412
+        if (!empty($term)) {
413
+            $query = $query->where('nama', 'like', '%' . $term . '%');
414
+        }
415
+        $query = $query->get();
416
+
417
+        $response = [];
418
+
419
+        foreach ($query as $key => $value) {
420
+            $response[] = ['id' => $value->id, 'text' => $value->nama];
421
+        }
422
+
423
+        return response()->json($response);
424
+    }
425
+     //custom route
426
+
427
+     public function route()
428
+     {
429
+         return Route::group([
430
+             'as' => $this->route,
431
+             'prefix' => $this->url_prefix,
432
+             'namespace' => $this->namespace_controller
433
+         ], function () {
434
+            Route::get('/', ['as' => 'index', 'uses' => 'RumahSakitController@index']);
435
+            Route::get('/create', ['as' => 'create', 'uses' => 'RumahSakitController@create']);
436
+            Route::get('/update/{rumah_sakit_id}', ['as' => 'update', 'uses' => 'RumahSakitController@update']);
437
+            Route::get('/delete-action/{rumah_sakit_id}', ['as' => 'delete_action', 'uses' => 'RumahSakitController@delete_action']);
438
+            Route::get('/get-data', ['as' => 'get_data', 'uses' => 'RumahSakitController@getData']);
439
+            Route::get('/select_jenis_rs', ['as' => 'select_jenis_rs', 'uses' => 'RumahSakitController@selectJenisRs']);
440
+            Route::get('/select_jenis_kepemilikan', ['as' => 'select_jenis_kepemilikan', 'uses' => 'RumahSakitController@selectKepemilikanRs']);
441
+
442
+            Route::post('/create-action', ['as' => 'create_action', 'uses' => 'RumahSakitController@create_action']);
443
+            Route::post('/update-action', ['as' => 'update_action', 'uses' => 'RumahSakitController@update_action']);
444
+         });
445
+     }
446
+
447
+     //end custom route
448
+}

+ 400
- 0
app/Http/Controllers/Admin/User_management/UserController.php Dosyayı Görüntüle

@@ -0,0 +1,400 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Admin\User_management;
4
+
5
+use App\Helpers\Helper;
6
+use App\Http\Controllers\Controller;
7
+
8
+use Hashids;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Support\Facades\DB;
11
+use Validator;
12
+use Illuminate\Support\Facades\Route;
13
+
14
+//load modelmu
15
+use App\User;
16
+use Illuminate\Support\Facades\Hash;
17
+use Spatie\Permission\Models\Role;
18
+use App\Model\Master\MasterUdd;
19
+use App\Model\ModelHasRoles;
20
+use Yajra\Datatables\Datatables;
21
+use Auth;
22
+
23
+class UserController extends Controller
24
+{
25
+    /**
26
+     * Untuk CRUD Biar cepat
27
+     * Silahkan ganti
28
+     * User:: => dengan model anda
29
+     * $user_id => ganti dengan id di model anda
30
+     */
31
+
32
+    /**
33
+     * Title untuk judul di web
34
+     * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
35
+     */
36
+    private $title = 'App User Management | User';
37
+    /**jangan lupa diganti*/
38
+    private $route = 'admin.user_management.user.'; //path awal foldernya ajah (misal folder di admin/dashboard) => 'admin.dashboard' | jangan lupa diganti
39
+    private $namespace_controller = 'Admin\User_management';
40
+    private $url_prefix = 'user-management/user/';
41
+
42
+    public function __construct()
43
+    {
44
+        // DB::enableQueryLog();
45
+        // $this->middleware('permission:user-list|user-create|user-update|user-delete', ['only' => ['index', 'create', 'update']]);
46
+        // $this->middleware('permission:user-create', ['only' => ['create', 'create_action']]);
47
+        // $this->middleware('permission:user-update', ['only' => ['update', 'update_action']]);
48
+        // $this->middleware('permission:user-delete', ['only' => ['delete']]);
49
+    }
50
+
51
+    /**
52
+     * Ini contoh crud yang sudah jalan
53
+     * index digunakna untuk tampilan awal dari menu yang akan dibuat
54
+     */
55
+    public function index()
56
+    {
57
+        if (session('success')) {
58
+            alert()->html('', session('success'), 'success');
59
+        }
60
+
61
+        if (session('error')) {
62
+            alert()->html('', session('error'), 'error');
63
+        }
64
+
65
+        // if (empty(Helper::is_super_admin())) {
66
+
67
+        //     return redirect('logout');
68
+        // }
69
+
70
+        $data = [
71
+            //bawaan
72
+            'title' => $this->title,
73
+            'route' => $this->route,
74
+            'data'  => User::get(),
75
+        ];
76
+        // dd($data);
77
+        return view($this->route . 'index', $data);
78
+    }
79
+
80
+    public function getData()
81
+    {
82
+        $query = User::join('model_has_roles as model_role', 'model_role.model_id', 'users.id')
83
+            ->where('role_id', 1); //super admin
84
+
85
+        return Datatables::of($query)
86
+            ->addIndexColumn()
87
+            ->addColumn('role_name', function ($query) {
88
+
89
+                $role_name = $query->roles()->get()->pluck('name')->toArray();
90
+                $jumlah_data = count($role_name);
91
+                foreach ($role_name as $key => $value) {
92
+                    $semicolon = '';
93
+                    if (($key + 1) > $jumlah_data) {
94
+                        $semicolon = ',';
95
+                    }
96
+
97
+                    $name = $value . $semicolon;
98
+                }
99
+
100
+                return $name;
101
+            })
102
+            ->addColumn('aksi', function ($query) {
103
+
104
+                /**cek role */
105
+                $aksi = '';
106
+                if (Auth::user()->can('user-update')) {
107
+                    $aksi .= "<a href='" . route($this->route . 'update', ['user_id' => Hashids::encode($query->id)]) . "' class='btn btn-sm btn-primary btn-edit'>Edit</a>";
108
+                }
109
+
110
+                if (Auth::user()->can('user-delete')) {
111
+                    // $aksi .= "<a href='javascript:;' data-route='" . route($this->route . 'delete_action', ['user_id' => Hashids::encode($query->id)]) . "' class='btn btn-danger btn-sm btn-delete'>Delete</a>";
112
+                }
113
+
114
+                return $aksi;
115
+            })
116
+            ->rawColumns(['aksi'])
117
+            ->toJson();
118
+    }
119
+
120
+    /**
121
+     * create digunakan untuk menampilkan tampilan buat
122
+     */
123
+    public function create()
124
+    {
125
+        /**set role dengan cara dibagi 4 - 4 */
126
+        $data = [
127
+            //bawaan
128
+            'title' => $this->title,
129
+            'route' => $this->route,
130
+        ];
131
+        if (session('success')) {
132
+            alert()->html('', session('success'), 'success');
133
+        }
134
+
135
+        if (session('error')) {
136
+            alert()->html('', session('error'), 'error');
137
+        }
138
+
139
+        return view($this->route . 'create', $data);
140
+    }
141
+
142
+    /**
143
+     * create_action digunakan untuk aksi post
144
+     * lengkap dengan validatornya
145
+     */
146
+    public function create_action(Request $request)
147
+    {
148
+        /**digunakan untuk set rule validator */
149
+        $rules = [
150
+            'name'          => 'required|min:4|unique:users,name',
151
+            'email'         => 'required|unique:users,email',
152
+            'password'      => 'required|min:6',
153
+        ];
154
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
155
+        $alert = [
156
+            'unique'    => ':attribute sudah tersedia',
157
+            'required'  => 'The :attribute harus diisi',
158
+            'min'       => ':attribute minimal :min  karakter'
159
+        ];
160
+
161
+        $validator = Validator::make($request->all(), $rules, $alert);
162
+
163
+        if ($validator->passes()) {
164
+            /**menggunakan transaction */
165
+            DB::beginTransaction();
166
+            $insert = [
167
+                'name'      => $request['name'],
168
+                'password'  => Hash::make($request['password']),
169
+                'email'     => $request['email']
170
+            ];
171
+            $query = User::create($insert);
172
+            $data_role['role_id'] = 1; //super admin
173
+            $query->assignRole($data_role);
174
+
175
+            if ($query) {
176
+                DB::commit();
177
+                $message = 'Berhasil';
178
+                return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
179
+            } else {
180
+                DB::rollback();
181
+                $message = 'Gagal';
182
+                return redirect()->back()->with('error', Helper::parsing_alert($message));
183
+            }
184
+        }
185
+        /**kenapa menggunakan back ? karena baliknya pasti ke halaman sebelumnya */
186
+        $message = Helper::parsing_alert($validator->errors()->all());
187
+        return redirect()->back()->with('error', $message)->withInput();
188
+    }
189
+
190
+    /** update sama seperti create hanya saja digunakan untuk update (viewnya saja) */
191
+    public function update($user_id)
192
+    {
193
+
194
+        if (session('success')) {
195
+            alert()->html('', session('success'), 'success');
196
+        }
197
+
198
+        if (session('error')) {
199
+            alert()->html('', session('error'), 'error');
200
+        }
201
+
202
+
203
+        $user_id = Hashids::decode($user_id);
204
+        $data_udd = MasterUdd::get();
205
+        if (!empty($user_id)) {
206
+            $role = Role::get();
207
+            $jumlah_role = $role->count();
208
+            $limit = 4;
209
+            $take = 0;
210
+            $jumlah_looping = ceil($jumlah_role / $limit);
211
+            $arr_role = [];
212
+            for ($i = 0; $i < $jumlah_looping; $i++) {
213
+                // $cek_limit[] = $limit;
214
+                // $cek_take[] = $take;
215
+                $limit_data = 4;
216
+                $role = Role::take($limit_data)->skip($take)->get();
217
+                $cek_data[] = $role;
218
+                $arr_role[$i] = $role;
219
+                $take = $limit;
220
+                $limit += 4;
221
+            }
222
+
223
+            $cek_data          = User::where('id', $user_id[0])->first();
224
+            $cek_data->role    = $cek_data->roles->pluck('id')->toArray();
225
+            $cek_data->udd_id  = $cek_data->petugas->unit_donor_darah_id ?? null;
226
+            if ($cek_data) {
227
+                $data = [
228
+                    //bawaan
229
+                    'title' => $this->title,
230
+                    'route' => $this->route,
231
+                    'data'  => $cek_data,
232
+                    'role'  => $arr_role,
233
+                    'udd'   => $data_udd,
234
+                ];
235
+                return view($this->route . 'update', $data);
236
+            }
237
+            $message = 'Id tidak ditemukan atau sudah dihapus';
238
+            return redirect()->back()->with('error', $message);
239
+        }
240
+        $message = 'Id tdak ditemukan';
241
+        return redirect()->back()->with('error', $message);
242
+    }
243
+
244
+    /**update_action POST
245
+     * Logikanya :
246
+     * 1. Cek Hashids::decode dari role_id apalah benar" di hash ?
247
+     * -iya
248
+     *  2. Cek ID yang didapatkan dari hash apakah benar adanya ?
249
+     *  -iya
250
+     *    3. proses validate
251
+     *    -iya
252
+     *      4. Proses update
253
+     *        - iya benar
254
+     *        - tidak salah
255
+     *    - tidak return error
256
+     *  - tidak return Id tdak ditemukan
257
+     * -tidak skip reutrn id null
258
+     */
259
+    public function update_action(Request $request)
260
+    {
261
+        /**digunakan untuk set rule validator */
262
+        $rules = [
263
+            'name'  => 'required|min:4',
264
+            'email' => 'required',
265
+        ];
266
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
267
+        $alert = [
268
+            'required'  => 'The :attribute harus diisi',
269
+            'min'       => ':attribute minimal :min  karakter'
270
+        ];
271
+        $validator = Validator::make($request->all(), $rules, $alert);
272
+
273
+        $user_id = Hashids::decode($request['id']);
274
+
275
+        if (!empty($user_id)) {
276
+            /**cek apakah id ada ? */
277
+            $cek_data = User::where('id', $user_id[0])->first();
278
+
279
+            if ($cek_data) {
280
+                /**cek apakah id rolenya benar" ada di DB ? */
281
+                if ($validator->passes()) {
282
+                    /**validatornya */
283
+                    $update = [
284
+                        'name'  => $request['name'],
285
+                        'email' => $request['email'],
286
+                    ];
287
+
288
+                    /**jika passwordnya disii */
289
+                    if ($request['password']) {
290
+                        $update['password'] = Hash::make($request['password']);
291
+                    }
292
+
293
+                    DB::beginTransaction();
294
+                    ModelHasRoles::where('model_id', $user_id)->delete();
295
+                    $query = $cek_data->update($update);
296
+                    $role['role_id'] = 1;
297
+                    $cek_data->assignRole($role['role_id']);
298
+
299
+                    if ($query) {
300
+                        DB::commit();
301
+                        $message = 'Berhasil';
302
+                        return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
303
+                    } else {
304
+                        DB::rollback();
305
+                        $message = 'Gagal';
306
+                        return redirect()->back()->with('error', Helper::parsing_alert($message));
307
+                    }
308
+                }
309
+
310
+                $message = Helper::parsing_alert($validator->errors()->all());
311
+
312
+                return redirect()->back()->with('error', $message);
313
+            } else {
314
+                $message = 'Id tdak ditemukan';
315
+                return redirect()->back()->with('error', $message);
316
+            }
317
+        } else {
318
+            $message = 'Id tidak boleh kosong';
319
+            return redirect()->back()->with('error', $message);
320
+        }
321
+    }
322
+
323
+    /**digunakan untuk delete
324
+     * Logikanya :
325
+     * 1. Cek hash id
326
+     * -ya
327
+     *  2. Cek id dari hash
328
+     *  - ya
329
+     *      3. Proses delete
330
+     *      -Ya
331
+     *      -Tidak
332
+     *  - tidak return Id tidak ditemukan atau sudah dihapus
333
+     * -tidak reutrn Id tdak ditemukan
334
+     */
335
+    public function delete_action($user_id)
336
+    {
337
+        $user_id = Hashids::decode($user_id);
338
+        /**cek role idnya apakah ada ? */
339
+
340
+        if (!empty($user_id)) {
341
+
342
+            $cek_data = User::where('id', $user_id[0])->first();
343
+
344
+            if ($cek_data) {
345
+                DB::beginTransaction();
346
+                $delete = $cek_data->delete();
347
+                if ($delete) {
348
+                    DB::commit();
349
+                    $message = 'Succesfully';
350
+                    $response = [
351
+                        'message' => $message,
352
+                        'status'   => true,
353
+                    ];
354
+                    return response()->json($response);
355
+                } else {
356
+                    DB::rollback();
357
+                    $message = 'Gagal';
358
+                    $response = [
359
+                        'message' => $message,
360
+                        'status'   => false,
361
+                    ];
362
+                    return response()->json($response);
363
+                }
364
+            }
365
+            $message = 'Id tidak di temukan atau sudah di hapus';
366
+            $response = [
367
+                'message' => $message,
368
+                'status'   => false,
369
+            ];
370
+            return response()->json($response);
371
+        }
372
+        $message = 'Id tdak ditemukan';
373
+        $response = [
374
+            'message' => $message,
375
+            'status'   => false,
376
+        ];
377
+        return response()->json($response);
378
+    }
379
+      //custom route
380
+
381
+      public function route()
382
+      {
383
+          return Route::group([
384
+              'as' => $this->route,
385
+              'prefix' => $this->url_prefix,
386
+              'namespace' => $this->namespace_controller
387
+          ], function () {
388
+            Route::get('/', ['as' => 'index', 'uses' => 'UserController@index']);
389
+            Route::get('/create', ['as' => 'create', 'uses' => 'UserController@create']);
390
+            Route::get('/update/{user_id}', ['as' => 'update', 'uses' => 'UserController@update']);
391
+            Route::get('/delete-action/{user_id}', ['as' => 'delete_action', 'uses' => 'UserController@delete_action']);
392
+            Route::get('/get-data', ['as' => 'get_data', 'uses' => 'UserController@getData']);
393
+
394
+            Route::post('/create-action', ['as' => 'create_action', 'uses' => 'UserController@create_action']);
395
+            Route::post('/update-action', ['as' => 'update_action', 'uses' => 'UserController@update_action']);
396
+          });
397
+      }
398
+
399
+      //end custom route
400
+}

+ 56
- 0
app/Http/Controllers/Api/V1/KelompokDriverController.php Dosyayı Görüntüle

@@ -0,0 +1,56 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Api\V1;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use App\Model\Raharja\KelompokDriver;
8
+use Illuminate\Support\Facades\Auth;
9
+
10
+class KelompokDriverController extends Controller
11
+{
12
+    public function __construct()
13
+    {
14
+        DB::enableQueryLog();
15
+    }
16
+
17
+    public function getAll()
18
+    {
19
+        $query = KelompokDriver::get();
20
+
21
+        if($query){
22
+            $result = $query;
23
+
24
+            $res_status = true;
25
+            $msg = 'Mendapatkan Data';
26
+            $status_msg = $msg;
27
+
28
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
29
+
30
+        }else {
31
+
32
+            $res_status = false;
33
+            $msg = 'Data tidak ditemukan';
34
+            $status_msg = $msg;
35
+
36
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
37
+        }
38
+    }
39
+
40
+    public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null)
41
+    {
42
+        $response['response'] = array(
43
+            'status'     => $status,
44
+            'message'    => $msg,
45
+            'status_msg' => $status_msg,
46
+        );
47
+        $response['param'] = !empty($param) ? $param : '';
48
+
49
+        $response['results'] = $result;
50
+
51
+        return response()->json($response, 200);
52
+    }
53
+
54
+   
55
+
56
+}

+ 182
- 0
app/Http/Controllers/Api/V1/MessageController.php Dosyayı Görüntüle

@@ -0,0 +1,182 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Api\V1;
4
+
5
+use App\Helpers\Helper;
6
+use App\Http\Controllers\Controller;
7
+use App\Model\Raharja\Message;
8
+use Illuminate\Support\Facades\DB;
9
+use App\Model\Raharja\UserReceive;
10
+use Illuminate\Support\Facades\Auth;
11
+
12
+class MessageController extends Controller
13
+{
14
+    public function __construct()
15
+    {
16
+        DB::enableQueryLog();
17
+    }
18
+
19
+    public function getAll()
20
+    {
21
+        $query  = UserReceive::get();
22
+        $arr_id = collect($query)->pluck('id')->toArray();
23
+        $query = array_map(function ($item)use ($arr_id) {
24
+            $arr_message = Message::whereIn('id', $arr_id)->with('categoryMessage')->get();
25
+            $item['title']    = $arr_message->where('id', $item['message_id'])->first()['title'];
26
+            $item['content']  = $arr_message->where('id', $item['message_id'])->first()['content'];
27
+            $item['category'] = $arr_message->where('id', $item['message_id'])->first()['categoryMessage']['name'];
28
+            return $item;
29
+        }, $query->toArray());
30
+
31
+        if($query){
32
+            $result = $query;
33
+
34
+            $res_status = true;
35
+            $msg = 'Mendapatkan Data';
36
+            $status_msg = $msg;
37
+
38
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
39
+
40
+        }else {
41
+
42
+            $res_status = false;
43
+            $msg = 'Data tidak ditemukan';
44
+            $status_msg = $msg;
45
+
46
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
47
+        }
48
+    }
49
+    public function getSingle($data_id)
50
+    {
51
+        $query = UserReceive::where('message_id', Helper::hash($data_id, 'decode'))->get();
52
+        $arr_id = collect($query)->pluck('message_id')->toArray();
53
+        $query = array_map(function ($item)use ($arr_id) {
54
+            $arr_message = Message::whereIn('id', $arr_id)->with('categoryMessage')->get();
55
+            $item['title']    = $arr_message->where('id', $item['message_id'])->first()['title'];
56
+            $item['content']  = $arr_message->where('id', $item['message_id'])->first()['content'];
57
+            $item['category'] = $arr_message->where('id', $item['message_id'])->first()['categoryMessage']['name'];
58
+            $item['is_check'] = $item['is_check'];
59
+            return $item;
60
+        }, $query->toArray());
61
+
62
+        if($query){
63
+            $result = $query;
64
+
65
+            $res_status = true;
66
+            $msg = 'Mendapatkan Data';
67
+            $status_msg = $msg;
68
+
69
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
70
+
71
+        }else {
72
+
73
+            $res_status = false;
74
+            $msg = 'Data tidak ditemukan';
75
+            $status_msg = $msg;
76
+
77
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
78
+        }
79
+    }
80
+    public function userViewMessage($message_id, $user_id)
81
+    {
82
+        $query = UserReceive::where('message_id', $message_id)
83
+        ->where('user_id', $user_id)
84
+        ->get();
85
+        $update_status = $query->first()->update(['is_check' => 1]);
86
+
87
+        $arr_id = collect($query)->pluck('message_id')->toArray();
88
+        $query = array_map(function ($item)use ($arr_id) {
89
+            $arr_message = Message::whereIn('id', $arr_id)->with('categoryMessage')->get();
90
+            $item['title']    = $arr_message->where('id', $item['message_id'])->first()['title'];
91
+            $item['content']  = $arr_message->where('id', $item['message_id'])->first()['content'];
92
+            $item['category'] = $arr_message->where('id', $item['message_id'])->first()['categoryMessage']['name'];
93
+            $item['is_check'] = $item['is_check'];
94
+            return $item;
95
+        }, $query->toArray());
96
+
97
+
98
+        if($query && $update_status){
99
+            $result = $query;
100
+
101
+            $res_status = true;
102
+            $msg = 'Mendapatkan Data';
103
+            $status_msg = $msg;
104
+
105
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
106
+
107
+        }else {
108
+
109
+            $res_status = false;
110
+            $msg = 'Data tidak ditemukan';
111
+            $status_msg = $msg;
112
+
113
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
114
+        }
115
+    }
116
+    public function countUserMessage($data_id)
117
+    {
118
+        $query = UserReceive::where('user_id', $data_id)
119
+        ->where('is_check', 0)
120
+        ->count();
121
+
122
+        if($query){
123
+            $result = $query;
124
+
125
+            $res_status = true;
126
+            $msg = 'Mendapatkan Data';
127
+            $status_msg = $msg;
128
+
129
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
130
+
131
+        }else {
132
+
133
+            $res_status = false;
134
+            $msg = 'Data tidak ditemukan';
135
+            $status_msg = $msg;
136
+
137
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
138
+        }
139
+    }
140
+
141
+    public function getByUser($user_id)
142
+    {
143
+        $query = Message::whereHas('userReceive', function($item) use ($user_id) {
144
+            $item->where('user_id', Helper::hash($user_id, 'decode'));
145
+        })->get();
146
+
147
+        if($query){
148
+            $result = $query;
149
+
150
+            $res_status = true;
151
+            $msg = 'Mendapatkan Data';
152
+            $status_msg = $msg;
153
+
154
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
155
+
156
+        }else {
157
+
158
+            $res_status = false;
159
+            $msg = 'Data tidak ditemukan';
160
+            $status_msg = $msg;
161
+
162
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
163
+        }
164
+    }
165
+
166
+
167
+
168
+    public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null)
169
+    {
170
+        $response['response'] = array(
171
+            'status'     => $status,
172
+            'message'    => $msg,
173
+            'status_msg' => $status_msg,
174
+        );
175
+        $response['param'] = !empty($param) ? $param : '';
176
+
177
+        $response['results'] = $result;
178
+
179
+        return response()->json($response, 200);
180
+    }
181
+
182
+}

+ 182
- 0
app/Http/Controllers/Api/V1/NewsController.php Dosyayı Görüntüle

@@ -0,0 +1,182 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Api\V1;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use App\Model\Raharja\News;
8
+use App\Model\NewsLog;
9
+use App\Model\PointLog;
10
+use App\Model\Raharja\NewsLikes;
11
+use Carbon\Carbon;
12
+use Illuminate\Support\Facades\Auth;
13
+use Helper;
14
+use Request;
15
+use Validator;
16
+
17
+class NewsController extends Controller
18
+{
19
+    public function __construct()
20
+    {
21
+        DB::enableQueryLog();
22
+    }
23
+
24
+    public function getAll()
25
+    {
26
+        $query = News::where('date_publish', '>=', Carbon::now()->format('Y-m-d'))
27
+        ->get();
28
+        $query = array_map(function ($item) {
29
+            $value['thumbnail']    = $item['thumbnail'];
30
+            $value['title']        = $item['title'];
31
+            $value['publish_date'] = $item['date_publish'];
32
+            return $value;
33
+        }, $query->toArray());
34
+
35
+        if($query){
36
+            $result = $query;
37
+
38
+            $res_status = true;
39
+            $msg = 'Mendapatkan Data';
40
+            $status_msg = $msg;
41
+
42
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
43
+
44
+        }else {
45
+
46
+            $res_status = false;
47
+            $msg = 'Data tidak ditemukan';
48
+            $status_msg = $msg;
49
+
50
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
51
+        }
52
+    }
53
+    public function getSingle($data_id)
54
+    {
55
+        $query = News::where('id', Helper::hash($data_id, 'decode'))->get();
56
+        $query = array_map(function ($item) {
57
+            $item['likes'] = NewsLikes::where('news_id', $item['id'])->count();
58
+            return $item;
59
+        }, $query->toArray());
60
+
61
+        if($query){
62
+            $result = $query;
63
+
64
+            $res_status = true;
65
+            $msg = 'Mendapatkan Data';
66
+            $status_msg = $msg;
67
+
68
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
69
+
70
+        }else {
71
+
72
+            $res_status = false;
73
+            $msg = 'Data tidak ditemukan';
74
+            $status_msg = $msg;
75
+
76
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
77
+        }
78
+    }
79
+    
80
+    public function postLog(Request $request)
81
+    {
82
+        $validator = Validator::make(Request::all(), [
83
+            'user_id' => ['required'],
84
+            'news_id' => ['required'],
85
+            'point' => ['required'],
86
+        ]);
87
+
88
+        if(!$validator->fails()){
89
+            $news_log = new NewsLog;
90
+            $news_log->user_id = Helper::hash(Request::all()['user_id'], 'decode');
91
+            $news_log->news_id = Helper::hash(Request::all()['news_id'], 'decode');
92
+            $news_log->point = Request::all()['point'];
93
+            $news_log->save();
94
+            $news_log->user_id = Request::all()['user_id'];
95
+            $news_log->news_id = Request::all()['news_id'];
96
+            $news_log->hash_id = Helper::hash($news_log->id, 'encode');
97
+
98
+            $total = Request::all()['point'];
99
+            
100
+            $point = new PointLog();
101
+            $point->user_id = Helper::hash($news_log->user_id, 'decode');
102
+            $point->type_point = 'reading_news';
103
+            $point->point = $total;
104
+            $point->save();
105
+            $point->user_id = Helper::hash($point->user_id, 'encode');
106
+            $point->hash_id = Helper::hash($point->id, 'encode');
107
+
108
+            if ($news_log && $point) {
109
+                $res_status = true;
110
+                $msg = 'Mendapatkan Data';
111
+                $status_msg = $msg;
112
+                $result = [
113
+                    'news_log' => $news_log,
114
+                    'point' => $point
115
+                ];
116
+    
117
+                return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
118
+            }else{
119
+                $res_status = false;
120
+                $msg = 'Data tidak ditemukan';
121
+                $status_msg = $msg;
122
+
123
+                return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
124
+            }
125
+        }else {
126
+
127
+            $res_status = false;
128
+            $msg = 'Error';
129
+            $status_msg = $validator->errors();
130
+
131
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
132
+        }
133
+    }
134
+
135
+    public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null)
136
+    {
137
+        $response['response'] = array(
138
+            'status'     => $status,
139
+            'message'    => $msg,
140
+            'status_msg' => $status_msg,
141
+        );
142
+        $response['param'] = !empty($param) ? $param : '';
143
+
144
+        $response['results'] = $result;
145
+
146
+        return response()->json($response, 200);
147
+    }
148
+
149
+    public function postLike($data_id){
150
+        $arr_news = News::where('id', Helper::hash($data_id, 'decode'))->first();
151
+
152
+        if($arr_news){
153
+            $get_news_by_user = NewsLikes::where('news_id', $arr_news->id)->where('user_id', 123456)->first();
154
+
155
+            if($get_news_by_user){
156
+                $query = $get_news_by_user->delete();
157
+            }else {
158
+                $query = NewsLikes::create([
159
+                    'news_id' => $arr_news->id,
160
+                    'user_id' => 123456,
161
+                ]);
162
+            }
163
+
164
+            $result = $query;
165
+
166
+            $res_status = true;
167
+            $msg = 'Berasil likes atau unlikes news';
168
+            $status_msg = $msg;
169
+
170
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
171
+
172
+        }else {
173
+
174
+            $res_status = false;
175
+            $msg = 'Data tidak ditemukan';
176
+            $status_msg = $msg;
177
+
178
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
179
+        }
180
+    }
181
+
182
+}

+ 107
- 0
app/Http/Controllers/Api/V1/PointLogController.php Dosyayı Görüntüle

@@ -0,0 +1,107 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Api\V1;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use App\Model\PointLog;
8
+use App\User;
9
+use Illuminate\Support\Facades\Auth;
10
+use Illuminate\Http\Request;
11
+use Illuminate\Support\Facades\Storage;
12
+use Validator;
13
+use Helper;
14
+
15
+
16
+class PointLogController extends Controller
17
+{
18
+    public function __construct()
19
+    {
20
+        DB::enableQueryLog();
21
+    }
22
+
23
+    public function getAll()
24
+    {
25
+        $query = User::select('users.name', 'users.id as user_id', DB::raw('SUM(point_logs.point) as total_point'))->rightJoin('point_logs', 'point_logs.user_id', 'users.id')->groupBy('point_logs.user_id')->orderBy('total_point', 'desc')->get();
26
+
27
+        if($query){
28
+            $result = $query;
29
+
30
+            $res_status = true;
31
+            $msg = 'Mendapatkan Data';
32
+            $status_msg = $msg;
33
+
34
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
35
+
36
+        }else {
37
+
38
+            $res_status = false;
39
+            $msg = 'Data tidak ditemukan';
40
+            $status_msg = $msg;
41
+
42
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
43
+        }
44
+    }
45
+    
46
+    public function getNonEvent()
47
+    {
48
+        $query = User::select('users.name', 'users.id as user_id', DB::raw('SUM(point_logs.point) as total_point'))->rightJoin('point_logs', 'point_logs.user_id', 'users.id')->where('event_id', '=', 0)->groupBy('point_logs.user_id')->orderBy('total_point', 'desc')->get();
49
+
50
+        if($query){
51
+            $result = $query;
52
+
53
+            $res_status = true;
54
+            $msg = 'Mendapatkan Data';
55
+            $status_msg = $msg;
56
+
57
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
58
+
59
+        }else {
60
+
61
+            $res_status = false;
62
+            $msg = 'Data tidak ditemukan';
63
+            $status_msg = $msg;
64
+
65
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
66
+        }
67
+    }
68
+
69
+    public function getWithEvent()
70
+    {
71
+        $query = User::select('users.name', 'users.id as user_id', DB::raw('SUM(point_logs.point) as total_point'))->rightJoin('point_logs', 'point_logs.user_id', 'users.id')->where('event_id', '=', 1)->groupBy('point_logs.user_id')->orderBy('total_point', 'desc')->get();
72
+
73
+        if($query){
74
+            $result = $query;
75
+
76
+            $res_status = true;
77
+            $msg = 'Mendapatkan Data';
78
+            $status_msg = $msg;
79
+
80
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
81
+
82
+        }else {
83
+
84
+            $res_status = false;
85
+            $msg = 'Data tidak ditemukan';
86
+            $status_msg = $msg;
87
+
88
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
89
+        }
90
+    }
91
+    
92
+    public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null)
93
+    {
94
+        $response['response'] = array(
95
+            'status'     => $status,
96
+            'message'    => $msg,
97
+            'status_msg' => $status_msg,
98
+        );
99
+        $response['param'] = !empty($param) ? $param : '';
100
+
101
+        $response['results'] = $result;
102
+
103
+        return response()->json($response, 200);
104
+    }
105
+
106
+
107
+}

+ 25
- 0
app/Http/Controllers/Api/V1/TestController.php Dosyayı Görüntüle

@@ -0,0 +1,25 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Api\V1;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use Illuminate\Support\Facades\Auth;
8
+use Hash;
9
+use Helper;
10
+use Validator;
11
+use Request;
12
+
13
+class TestController extends Controller
14
+{
15
+    public function __construct()
16
+    {
17
+        DB::enableQueryLog();
18
+    }
19
+
20
+    public function hash(Request $request)
21
+    {
22
+        Helper::hash($request::all()['value'], $request::all()['type'], $request::all()['is_json']);
23
+    }
24
+
25
+}

+ 0
- 0
app/Http/Controllers/Api/V1/TimelineController.php Dosyayı Görüntüle


+ 183
- 0
app/Http/Controllers/Api/V1/TipsController.php Dosyayı Görüntüle

@@ -0,0 +1,183 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Api\V1;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use App\Model\Raharja\Tips;
8
+use App\Model\TipsLog;
9
+use App\Model\PointLog;
10
+use App\Model\Raharja\TipsLikes;
11
+use Carbon\Carbon;
12
+use Illuminate\Support\Facades\Auth;
13
+use Helper;
14
+use Request;
15
+use Validator;
16
+
17
+class TipsController extends Controller
18
+{
19
+    public function __construct()
20
+    {
21
+        DB::enableQueryLog();
22
+    }
23
+
24
+    public function getAll()
25
+    {
26
+        $query = Tips::where('date_publish', '>=', Carbon::now()->format('Y-m-d'))
27
+        ->get();
28
+
29
+        $query = array_map(function ($item) {
30
+            $value['thumbnail']    = $item['thumbnail'];
31
+            $value['title']        = $item['title'];
32
+            $value['publish_date'] = $item['date_publish'];
33
+            return $value;
34
+        }, $query->toArray());
35
+
36
+        if($query){
37
+            $result = $query;
38
+
39
+            $res_status = true;
40
+            $msg = 'Mendapatkan Data';
41
+            $status_msg = $msg;
42
+
43
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
44
+
45
+        }else {
46
+
47
+            $res_status = false;
48
+            $msg = 'Data tidak ditemukan';
49
+            $status_msg = $msg;
50
+
51
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
52
+        }
53
+    }
54
+    public function getSingle($data_id)
55
+    {
56
+        $query = Tips::where('id', Helper::hash($data_id, 'decode'))->get();
57
+
58
+        $query = array_map(function ($item) {
59
+            $item['likes'] = TipsLikes::where('tips_id', $item['id'])->count();
60
+            return $item;
61
+        }, $query->toArray());
62
+
63
+        if($query){
64
+            $result = $query;
65
+
66
+            $res_status = true;
67
+            $msg = 'Mendapatkan Data';
68
+            $status_msg = $msg;
69
+
70
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
71
+
72
+        }else {
73
+
74
+            $res_status = false;
75
+            $msg = 'Data tidak ditemukan';
76
+            $status_msg = $msg;
77
+
78
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
79
+        }
80
+    }
81
+    
82
+    public function postLog(Request $request)
83
+    {
84
+        $validator = Validator::make(Request::all(), [
85
+            'user_id' => ['required'],
86
+            'tips_id' => ['required'],
87
+            'point' => ['required'],
88
+        ]);
89
+
90
+        if(!$validator->fails()){
91
+            $tips_logs = new TipsLog;
92
+            $tips_logs->user_id = Helper::hash(Request::all()['user_id'], 'decode');
93
+            $tips_logs->tips_id = Helper::hash(Request::all()['tips_id'], 'decode');
94
+            $tips_logs->point = Request::all()['point'];
95
+            $tips_logs->save();
96
+            $tips_logs->user_id = Request::all()['user_id'];
97
+            $tips_logs->tips_id = Request::all()['tips_id'];
98
+            $tips_logs->hash_id = Helper::hash($tips_logs->id, 'encode');
99
+
100
+            $total = Request::all()['point'];
101
+            
102
+            $point = new PointLog();
103
+            $point->user_id = Helper::hash($tips_logs->user_id, 'decode');
104
+            $point->type_point = 'reading_news';
105
+            $point->point = $total;
106
+            $point->save();
107
+            $point->user_id = Helper::hash($point->user_id, 'encode');
108
+            $point->hash_id = Helper::hash($point->id, 'encode');
109
+
110
+            if ($tips_logs && $point) {
111
+                $res_status = true;
112
+                $msg = 'Mendapatkan Data';
113
+                $status_msg = $msg;
114
+                $result = [
115
+                    'tips_logs' => $tips_logs,
116
+                    'point' => $point
117
+                ];
118
+    
119
+                return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
120
+            }else{
121
+                $res_status = false;
122
+                $msg = 'Data tidak ditemukan';
123
+                $status_msg = $msg;
124
+
125
+                return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
126
+            }
127
+        }else {
128
+
129
+            $res_status = false;
130
+            $msg = 'Error';
131
+            $status_msg = $validator->errors();
132
+
133
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
134
+        }
135
+    }
136
+    public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null)
137
+    {
138
+        $response['response'] = array(
139
+            'status'     => $status,
140
+            'message'    => $msg,
141
+            'status_msg' => $status_msg,
142
+        );
143
+        $response['param'] = !empty($param) ? $param : '';
144
+
145
+        $response['results'] = $result;
146
+
147
+        return response()->json($response, 200);
148
+    }
149
+
150
+    public function postLike($data_id){
151
+        $arr_tips = Tips::where('id', Helper::hash($data_id, 'decode'))->first();
152
+
153
+        if($arr_tips){
154
+            $get_tips_by_user = TipsLikes::where('tips_id', $arr_tips->id)->where('user_id', 123456)->first();
155
+
156
+            if($get_tips_by_user){
157
+                $query = $get_tips_by_user->delete();
158
+            }else {
159
+                $query = TipsLikes::create([
160
+                    'tips_id' => $arr_tips->id,
161
+                    'user_id' => 123456,
162
+                ]);
163
+            }
164
+
165
+            $result = $query;
166
+
167
+            $res_status = true;
168
+            $msg = 'Berasil likes atau unlikes tips';
169
+            $status_msg = $msg;
170
+
171
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
172
+
173
+        }else {
174
+
175
+            $res_status = false;
176
+            $msg = 'Data tidak ditemukan';
177
+            $status_msg = $msg;
178
+
179
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
180
+        }
181
+    }
182
+
183
+}

+ 138
- 0
app/Http/Controllers/Api/V1/TransportationController.php Dosyayı Görüntüle

@@ -0,0 +1,138 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Api\V1;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use App\Model\Transportation;
8
+use Illuminate\Support\Facades\Auth;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Support\Facades\Storage;
11
+use Validator;
12
+use Helper;
13
+
14
+
15
+class TransportationController extends Controller
16
+{
17
+    public function __construct()
18
+    {
19
+        DB::enableQueryLog();
20
+    }
21
+
22
+    public function getAll()
23
+    {
24
+        $query = Transportation::get();
25
+
26
+        if($query){
27
+            $result = $query;
28
+
29
+            $res_status = true;
30
+            $msg = 'Mendapatkan Data';
31
+            $status_msg = $msg;
32
+
33
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
34
+
35
+        }else {
36
+
37
+            $res_status = false;
38
+            $msg = 'Data tidak ditemukan';
39
+            $status_msg = $msg;
40
+
41
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
42
+        }
43
+    }
44
+
45
+    public function getByUser($user_id)
46
+    {
47
+        $query = Transportation::where('user_id', Helper::hash($user_id, 'decode'))->findOrFail();
48
+
49
+        if($query){
50
+            $result = $query;
51
+
52
+            $res_status = true;
53
+            $msg = 'Mendapatkan Data';
54
+            $status_msg = $msg;
55
+
56
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
57
+
58
+        }else {
59
+
60
+            $res_status = false;
61
+            $msg = 'Data tidak ditemukan';
62
+            $status_msg = $msg;
63
+
64
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
65
+        }
66
+    }
67
+
68
+    public function postStore(Request $request)
69
+    {
70
+        $post = $request->all();
71
+        // $file = $request->file('gambar');
72
+        //dd($post);
73
+        /**digunakan untuk set rule validator */
74
+        $rules = [
75
+            'gambar' => 'required',
76
+            // 'gambar' => 'required|file|max:1000',
77
+        ];
78
+        /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
79
+        // $alert = [
80
+        //     'file'  => 'File maksimal 1MB'
81
+        // ];
82
+        // $validator = Validator::make($post, $rules, $alert);
83
+        $validator = Validator::make($post, $rules);
84
+
85
+        if ($validator->passes()) {
86
+            /**menggunakan transaction */
87
+            DB::beginTransaction();
88
+
89
+            // $nama_file = time()."_".$file->getClientOriginalName();
90
+
91
+            // $tujuan_upload = 'gambar';
92
+
93
+            // //$file->move($tujuan_upload,$nama_file);
94
+            // Storage::putFileAs('public/images/transportation/', $file, $nama_file );
95
+
96
+            $query                              = new Transportation();
97
+            $query->name                        = $request->name;
98
+            $query->transportation_identity     = $request->transportation_identity;
99
+            $query->transportation_type         = $request->transportation_type;
100
+            $query->transportation_photo        = Helper::base64_to_image($request->gambar, 'transportation');
101
+            $query->user_id                     = 123456;
102
+            $query->save();
103
+            if($query){
104
+                $result = $query;
105
+    
106
+                $res_status = true;
107
+                $msg = 'Mendapatkan Data';
108
+                $status_msg = $msg;
109
+    
110
+                return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
111
+    
112
+            }else {
113
+    
114
+                $res_status = false;
115
+                $msg = 'Data tidak ditemukan';
116
+                $status_msg = $msg;
117
+    
118
+                return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
119
+            }
120
+        }
121
+    }
122
+
123
+    public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null)
124
+    {
125
+        $response['response'] = array(
126
+            'status'     => $status,
127
+            'message'    => $msg,
128
+            'status_msg' => $status_msg,
129
+        );
130
+        $response['param'] = !empty($param) ? $param : '';
131
+
132
+        $response['results'] = $result;
133
+
134
+        return response()->json($response, 200);
135
+    }
136
+
137
+
138
+}

+ 241
- 0
app/Http/Controllers/Api/V1/TravelController.php Dosyayı Görüntüle

@@ -0,0 +1,241 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Api\V1;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use App\Model\Travel;
8
+use App\Model\TravelLog;
9
+use App\Model\PointLog;
10
+use App\Model\Profile;
11
+use App\Model\Raharja\EventOrganisasiMembers;
12
+use App\Model\Raharja\EventOrganisasi;
13
+use Illuminate\Support\Facades\Auth;
14
+use Hash;
15
+use Helper;
16
+use Validator;
17
+use Request;
18
+use Carbon\Carbon;
19
+
20
+class TravelController extends Controller
21
+{
22
+    public function __construct()
23
+    {
24
+        DB::enableQueryLog();
25
+    }
26
+
27
+    public function getTravel()
28
+    {
29
+        $query = Travel::get();
30
+        $query = array_map(function ($item) {
31
+            $item['log'] = TravelLog::where('travel_id', $item['id'])->get();
32
+            return $item;
33
+        }, $query->toArray());
34
+
35
+        if($query){
36
+            $result = $query;
37
+
38
+            $res_status = true;
39
+            $msg = 'Mendapatkan Data';
40
+            $status_msg = $msg;
41
+
42
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
43
+
44
+        }else {
45
+
46
+            $res_status = false;
47
+            $msg = 'Data tidak ditemukan';
48
+            $status_msg = $msg;
49
+
50
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
51
+        }
52
+    }
53
+
54
+    public function getSingleTravel($travel_id)
55
+    {
56
+        $query = Travel::where('travel_id', Helper::hash($travel_id, 'decode'))->get();
57
+        $query = array_map(function ($item) {
58
+            $item['log'] = TravelLog::where('travel_id', $item['id'])->get();
59
+            return $item;
60
+        }, $query->toArray());
61
+
62
+        if($query){
63
+            $result = $query;
64
+
65
+            $res_status = true;
66
+            $msg = 'Mendapatkan Data';
67
+            $status_msg = $msg;
68
+
69
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
70
+
71
+        }else {
72
+
73
+            $res_status = false;
74
+            $msg = 'Data tidak ditemukan';
75
+            $status_msg = $msg;
76
+
77
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
78
+        }
79
+    }
80
+
81
+    public function getLog($travel_id)
82
+    {
83
+        $query = TravelLog::where('travel_id', Helper::hash($travel_id, 'decode'))->get();
84
+
85
+        if($query){
86
+            $result = $query;
87
+
88
+            $res_status = true;
89
+            $msg = 'Mendapatkan Data';
90
+            $status_msg = $msg;
91
+
92
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
93
+
94
+        }else {
95
+
96
+            $res_status = false;
97
+            $msg = 'Data tidak ditemukan';
98
+            $status_msg = $msg;
99
+
100
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
101
+        }
102
+    }
103
+    
104
+    public function postRequest(Request $request)
105
+    {
106
+        $validator = Validator::make(Request::all(), [
107
+            'user_id' => ['required'],
108
+        ]);
109
+        // dd(Helper::hash(Request::all()['user_id'], 'decode'));
110
+
111
+        if(!$validator->fails()){
112
+            $travel = new Travel();
113
+            $travel->user_id = Helper::hash(Request::all()['user_id'], 'decode');
114
+            $travel->save();
115
+            // dd(Helper::hash($travel->id, 'encode'));
116
+
117
+            if ($travel) {
118
+                $res_status = true;
119
+                $msg = 'Mendapatkan Data';
120
+                $status_msg = $msg;
121
+                $travel->hash_id = Helper::hash($travel->id, 'encode');
122
+                $travel->user_id = Helper::hash($travel->user_id, 'encode');
123
+                $result = $travel;
124
+    
125
+                return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
126
+            }else{
127
+                $res_status = false;
128
+                $msg = 'Data tidak ditemukan';
129
+                $status_msg = $msg;
130
+
131
+                return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
132
+            }
133
+        }else {
134
+
135
+            $res_status = false;
136
+            $msg = 'Error';
137
+            $status_msg = $validator->errors();
138
+
139
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
140
+        }
141
+    }
142
+    
143
+    public function postLog(Request $request)
144
+    {
145
+        $validator = Validator::make(Request::all(), [
146
+            'travel_id' => ['required'],
147
+            'check_vehicle' => ['required'],
148
+            'take_call' => ['required'],
149
+            'speeding' => ['required'],
150
+            'sudden_brake' => ['required'],
151
+            'bonus_poin' => ['required'],
152
+            'long_distance' => ['required'],
153
+            'time_travel' => ['required'],
154
+        ]);
155
+
156
+        if(!$validator->fails()){
157
+            $list_type = ['check_vehicle','take_call','speeding','sudden_brake','bonus_poin'];
158
+            $total = 0;
159
+            foreach ($list_type as $key => $value) {
160
+                $travel_log[$key] = new TravelLog;
161
+                $travel_log[$key]->travel_id = Helper::hash(Request::all()['travel_id'], 'decode');
162
+                $travel_log[$key]->type_point = $value;
163
+                $travel_log[$key]->point = Request::all()[$value];
164
+                $travel_log[$key]->save();
165
+                $travel_log[$key]->travel_id = Request::all()['travel_id'];
166
+                $travel_log[$key]->hash_id = Helper::hash($travel_log[$key]->id, 'encode');
167
+
168
+                $total += Request::all()[$value];
169
+            }
170
+            $user = Travel::find(Helper::hash($travel_log[0]->travel_id, 'decode'))->user_id;
171
+            $is_org = Profile::where('user_id', $user)->pluck('is_have_organization')->first();
172
+            if($is_org == 'yes'){
173
+                $org_id = Profile::where('user_id', $user)->pluck('organization_id')->first();
174
+                $evn_id = EventOrganisasiMembers::where('kelompok_driver_id', $org_id)->pluck('event_organisasi_id')->last(); 
175
+                $evn_check = EventOrganisasi::where('id', $evn_id)->first();
176
+                
177
+                if($evn_check['start_date'] <= Carbon::now()->format('Y-m-d') && $evn_check['end_date'] >= Carbon::now()->format('Y-m-d')){
178
+                    $event_id = 1;
179
+                }else{
180
+                    $event_id = 0;
181
+                }
182
+            }else{
183
+                $event_id = 0;
184
+            }
185
+            $point = new PointLog();
186
+            $point->user_id = Travel::find(Helper::hash($travel_log[0]->travel_id, 'decode'))->user_id;
187
+            $point->type_point = 'safety_riding';
188
+            $point->point = $total;
189
+            $point->event_id = $event_id;
190
+            $point->save();
191
+            $point->user_id = Helper::hash($point->user_id, 'encode');
192
+            $point->hash_id = Helper::hash($point->id, 'encode');
193
+
194
+            $travel = Travel::find(Helper::hash($travel_log[0]->travel_id, 'decode'));
195
+            $travel->long_distance = Request::all()['long_distance'];
196
+            $travel->time_travel = Request::all()['time_travel'];
197
+            $travel->save();
198
+
199
+            if ($travel_log && $point && $travel) {
200
+                $res_status = true;
201
+                $msg = 'Mendapatkan Data';
202
+                $status_msg = $msg;
203
+                $result = [
204
+                    'travel_log' => $travel_log,
205
+                    'point' => $point,
206
+                    'travel' => $travel,
207
+                ];
208
+    
209
+                return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
210
+            }else{
211
+                $res_status = false;
212
+                $msg = 'Data tidak ditemukan';
213
+                $status_msg = $msg;
214
+
215
+                return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
216
+            }
217
+        }else {
218
+
219
+            $res_status = false;
220
+            $msg = 'Error';
221
+            $status_msg = $validator->errors();
222
+
223
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
224
+        }
225
+    }
226
+    
227
+    public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null)
228
+    {
229
+        $response['response'] = array(
230
+            'status'     => $status,
231
+            'message'    => $msg,
232
+            'status_msg' => $status_msg,
233
+        );
234
+        $response['param'] = !empty($param) ? $param : '';
235
+
236
+        $response['results'] = $result;
237
+
238
+        return response()->json($response, 200);
239
+    }
240
+
241
+}

+ 139
- 0
app/Http/Controllers/Api/V1/TriviaController.php Dosyayı Görüntüle

@@ -0,0 +1,139 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Api\V1;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use App\Model\Trivia;
8
+use App\Model\Points;
9
+use App\Model\TriviaAnswer;
10
+use App\Model\PointLog;
11
+use App\User;
12
+use Illuminate\Support\Facades\Auth;
13
+use Helper;
14
+use Request;
15
+use Validator;
16
+
17
+class TriviaController extends Controller
18
+{
19
+    public function __construct()
20
+    {
21
+        DB::enableQueryLog();
22
+    }
23
+
24
+    public function getAll()
25
+    {
26
+        $query = Trivia::get();
27
+        $query = array_map(function ($item) {
28
+            $item['answer'] = TriviaAnswer::where('trivia_id', $item['id'])->get();
29
+            return $item;
30
+        }, $query->toArray());
31
+
32
+        if($query){
33
+            $result = $query;
34
+
35
+            $res_status = true;
36
+            $msg = 'Mendapatkan Data';
37
+            $status_msg = $msg;
38
+
39
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
40
+
41
+        }else {
42
+
43
+            $res_status = false;
44
+            $msg = 'Data tidak ditemukan';
45
+            $status_msg = $msg;
46
+
47
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
48
+        }
49
+    }
50
+
51
+    public function getSingle($data_id)
52
+    {
53
+        $query = Trivia::where('id', Helper::hash($data_id, 'decode'))->get();
54
+        $query = array_map(function ($item) {
55
+            $item['answer'] = TriviaAnswer::where('trivia_id', $item['id'])->get();
56
+            return $item;
57
+        }, $query->toArray());
58
+
59
+        if($query){
60
+            $result = $query;
61
+
62
+            $res_status = true;
63
+            $msg = 'Mendapatkan Data';
64
+            $status_msg = $msg;
65
+
66
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
67
+
68
+        }else {
69
+
70
+            $res_status = false;
71
+            $msg = 'Data tidak ditemukan';
72
+            $status_msg = $msg;
73
+
74
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
75
+        }
76
+    }
77
+    
78
+    public function postSubmitAnswer()
79
+    {
80
+        $validator = Validator::make(Request::all(), [
81
+            'user_id' => ['required'],
82
+            'question_id' => ['required'],
83
+            'answer_id' => ['required'],
84
+        ]);
85
+
86
+        if(!$validator->fails()){
87
+            $trivia_answer = TriviaAnswer::find(Helper::hash(Request::all()['answer_id'], 'decode'));
88
+            if (($trivia_answer->trivia_id == Helper::hash(Request::all()['question_id'], 'decode')) && ($trivia_answer->is_right == 't')) {
89
+                // Start Perhitungan
90
+                $pointLog = new PointLog();
91
+                $pointLog->user_id = Helper::hash(Request::all()['user_id'], 'decode');
92
+                $pointLog->type_point = 'trivia';
93
+                $pointLog->point = Points::where('type', 'trivia')->pluck('value')->first();
94
+                $pointLog->save();
95
+                // End Perhitungan
96
+                
97
+                $pointLog->user_id = Helper::hash($pointLog->user_id, 'encode');
98
+                $pointLog->answer_id = Helper::hash($pointLog->answer_id, 'encode');
99
+                $pointLog->question_id = Helper::hash($pointLog->question_id, 'encode');
100
+                $pointLog->hash_id = Helper::hash($pointLog->id, 'encode');
101
+
102
+                $result = $pointLog;
103
+                $res_status = true;
104
+                $msg = 'Jawaban Benar';
105
+                $status_msg = $msg;
106
+    
107
+                return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
108
+            }else{
109
+                $res_status = false;
110
+                $msg = 'Jawaban Salah';
111
+                $status_msg = $msg;
112
+
113
+                return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
114
+            }
115
+        }else {
116
+
117
+            $res_status = false;
118
+            $msg = 'Jawaban Salah';
119
+            $status_msg = $validator->errors();
120
+
121
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
122
+        }
123
+    }
124
+    
125
+    public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null)
126
+    {
127
+        $response['response'] = array(
128
+            'status'     => $status,
129
+            'message'    => $msg,
130
+            'status_msg' => $status_msg,
131
+        );
132
+        $response['param'] = !empty($param) ? $param : '';
133
+
134
+        $response['results'] = $result;
135
+
136
+        return response()->json($response, 200);
137
+    }
138
+
139
+}

+ 260
- 0
app/Http/Controllers/Api/V1/UserController.php Dosyayı Görüntüle

@@ -0,0 +1,260 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Api\V1;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Support\Facades\DB;
7
+use App\User;
8
+use Illuminate\Support\Facades\Auth;
9
+use Illuminate\Http\Request;
10
+use Validator;
11
+use Hash;
12
+use Helper;
13
+use Illuminate\Support\Facades\Password;
14
+use App\Model\Profile;
15
+
16
+class UserController extends Controller
17
+{
18
+    public function __construct()
19
+    {
20
+        DB::enableQueryLog();
21
+    }
22
+
23
+    public function getAll()
24
+    {
25
+        $query = User::select('*', 'users.id as user_id', 'profiles.id as profile_id')->leftJoin('profiles', 'profiles.user_id', 'users.id')->get();
26
+
27
+        if($query){
28
+            $result = $query;
29
+
30
+            $res_status = true;
31
+            $msg = 'Mendapatkan Data';
32
+            $status_msg = $msg;
33
+
34
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
35
+
36
+        }else {
37
+
38
+            $res_status = false;
39
+            $msg = 'Data tidak ditemukan';
40
+            $status_msg = $msg;
41
+
42
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
43
+        }
44
+    }
45
+    
46
+    public function getSingle($data_id)
47
+    {
48
+        $query = User::select('users.*', 'profiles.*', 'users.id as user_id', 'profiles.id as profile_id', DB::raw('SUM(point_logs.point) as total_point'))->leftJoin('profiles', 'profiles.user_id', 'users.id')->leftJoin('point_logs', 'point_logs.user_id', 'users.id')->where('users.id', Helper::hash($data_id, 'decode'))->get();
49
+
50
+        if($query){
51
+            $result = $query;
52
+
53
+            $res_status = true;
54
+            $msg = 'Mendapatkan Data';
55
+            $status_msg = $msg;
56
+
57
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
58
+
59
+        }else {
60
+
61
+            $res_status = false;
62
+            $msg = 'Data tidak ditemukan';
63
+            $status_msg = $msg;
64
+
65
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
66
+        }
67
+    }
68
+
69
+    public function postLogin(Request $request)
70
+    {        
71
+        $auth = Auth::attempt($request->only('email', 'password'));
72
+
73
+        if($auth){
74
+            $result['user'] = Auth::user();
75
+
76
+            $res_status = true;
77
+            $msg = 'Mendapatkan Data';
78
+            $status_msg = $msg;
79
+
80
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
81
+
82
+        }else {
83
+
84
+            $res_status = false;
85
+            $msg = 'Data tidak ditemukan';
86
+            $status_msg = $msg;
87
+
88
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
89
+        }
90
+    }
91
+
92
+    public function postRegister(Request $request)
93
+    {        
94
+        $validator = Validator::make($request->all(), [
95
+            'name' => ['required', 'string', 'max:255'],
96
+            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
97
+            'password' => ['required', 'string', 'min:8', 'confirmed'],
98
+        ]);
99
+
100
+        if(!$validator->fails()){
101
+            $result = User::create([
102
+                'name' => $request->name,
103
+                'email' => $request->email,
104
+                'password' => Hash::make($request->password),
105
+                'gambar' => !empty($request->gambar)?Helper::base64_to_image($request->gambar, 'transportation'):'',
106
+            ]);
107
+
108
+            $data_role['role_id'] = 2; //driver role
109
+            $result->assignRole($data_role);
110
+            
111
+            // $file = $request->file('photo');
112
+            // if($file){
113
+            //     $user = User::find($result->id);
114
+            //     // $nama_file = time()."_".$file->getClientOriginalName();
115
+            //     // $tujuan_upload = 'photo';
116
+            //     // //$file->move($tujuan_upload,$nama_file);
117
+            //     // Storage::putFileAs('public/photo/user/', $file, $nama_file );
118
+            //     // //File::delete('image/'.$user->photo);
119
+            //     // Storage::delete('public/photo/user/'.$user->photo);
120
+            //     // $user->photo = $nama_file;
121
+
122
+            //     $user->save();
123
+            // }
124
+
125
+            $res_status = true;
126
+            $msg = 'Berhasil membuat user';
127
+            $status_msg = $msg;
128
+
129
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
130
+
131
+        }else {
132
+
133
+            $res_status = false;
134
+            $msg = 'Gagal Membuat user';
135
+            $status_msg = $validator->errors();
136
+
137
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
138
+        }
139
+    }
140
+
141
+    public function postCreateProfile(Request $request)
142
+    {        
143
+        $validator = Validator::make($request->all(), [
144
+            'user_id' => ['required'],
145
+            'fullname' => ['required'],
146
+            'phone_number' => ['required'],
147
+            'gender' => ['required'],
148
+            'is_have_organization' => ['required'],
149
+            'organization_id' => [],
150
+            'id_member' => [],
151
+        ]);
152
+
153
+        if(!$validator->fails()){
154
+            $result = Profile::create([
155
+                'user_id' => $request->user_id,
156
+                'fullname' => $request->fullname,
157
+                'phone_number' => $request->phone_number,
158
+                'gender' => $request->gender,
159
+                'is_have_organization' => $request->is_have_organization,
160
+                'organization_id' => !empty($request->organization_id)?$request->organization_id:NULL,
161
+                'id_member' => !empty($request->id_member)?$request->id_member:'',
162
+            ]);
163
+
164
+            $res_status = true;
165
+            $msg = 'Berhasil membuat user';
166
+            $status_msg = $msg;
167
+
168
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
169
+
170
+        }else {
171
+
172
+            $res_status = false;
173
+            $msg = 'Gagal Membuat user';
174
+            $status_msg = $validator->errors();
175
+
176
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
177
+        }
178
+    }
179
+
180
+    public function postUpdateProfile(Request $request)
181
+    {        
182
+        $validator = Validator::make($request->all(), [
183
+            'user_id' => ['required'],
184
+            'fullname' => ['required'],
185
+            'phone_number' => ['required'],
186
+            'gender' => ['required'],
187
+            'is_have_organization' => ['required'],
188
+            'organization_id' => [],
189
+            'id_member' => [],
190
+        ]);
191
+
192
+        if(!$validator->fails()){
193
+            $profile = Profile::where('user_id', $request->user_id)->firstOrFail();
194
+            
195
+            $profile->user_id = $request->user_id;
196
+            $profile->fullname = $request->fullname;
197
+            $profile->phone_number = $request->phone_number;
198
+            $profile->gender = $request->gender;
199
+            $profile->is_have_organization = $request->is_have_organization;
200
+            $profile->organization_id = !empty($request->organization_id)?$request->organization_id:'';
201
+            $profile->id_member = !empty($request->id_member)?$request->id_member:'';
202
+
203
+            $res_status = true;
204
+            $msg = 'Berhasil membuat user';
205
+            $status_msg = $msg;
206
+
207
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
208
+
209
+        }else {
210
+
211
+            $res_status = false;
212
+            $msg = 'Gagal Membuat user';
213
+            $status_msg = $validator->errors();
214
+
215
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
216
+        }
217
+    }
218
+
219
+    public function postForgotPassword() {
220
+        $credentials = request()->validate(['email' => 'required|email']);
221
+
222
+        Password::sendResetLink($credentials);
223
+
224
+        return response()->json(["msg" => 'Reset password link sent on your email id.']);
225
+    }
226
+
227
+    public function postResetPassword() {
228
+        $credentials = request()->validate([
229
+            'email' => 'required|email',
230
+            'token' => 'required|string',
231
+            'password' => 'required|string|confirmed'
232
+        ]);
233
+
234
+        $reset_password_status = Password::reset($credentials, function ($user, $password) {
235
+            $user->password = $password;
236
+            $user->save();
237
+        });
238
+
239
+        if ($reset_password_status == Password::INVALID_TOKEN) {
240
+            return response()->json(["msg" => "Invalid token provided"], 400);
241
+        }
242
+
243
+        return response()->json(["msg" => "Password has been successfully changed"]);
244
+    }
245
+    
246
+    public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null)
247
+    {
248
+        $response['response'] = array(
249
+            'status'     => $status,
250
+            'message'    => $msg,
251
+            'status_msg' => $status_msg,
252
+        );
253
+        $response['param'] = !empty($param) ? $param : '';
254
+
255
+        $response['results'] = $result;
256
+
257
+        return response()->json($response, 200);
258
+    }
259
+
260
+}

+ 40
- 0
app/Http/Controllers/Auth/ConfirmPasswordController.php Dosyayı Görüntüle

@@ -0,0 +1,40 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Auth;
4
+
5
+use App\Http\Controllers\Controller;
6
+use App\Providers\RouteServiceProvider;
7
+use Illuminate\Foundation\Auth\ConfirmsPasswords;
8
+
9
+class ConfirmPasswordController extends Controller
10
+{
11
+    /*
12
+    |--------------------------------------------------------------------------
13
+    | Confirm Password Controller
14
+    |--------------------------------------------------------------------------
15
+    |
16
+    | This controller is responsible for handling password confirmations and
17
+    | uses a simple trait to include the behavior. You're free to explore
18
+    | this trait and override any functions that require customization.
19
+    |
20
+    */
21
+
22
+    use ConfirmsPasswords;
23
+
24
+    /**
25
+     * Where to redirect users when the intended url fails.
26
+     *
27
+     * @var string
28
+     */
29
+    protected $redirectTo = RouteServiceProvider::HOME;
30
+
31
+    /**
32
+     * Create a new controller instance.
33
+     *
34
+     * @return void
35
+     */
36
+    public function __construct()
37
+    {
38
+        $this->middleware('auth');
39
+    }
40
+}

+ 22
- 0
app/Http/Controllers/Auth/ForgotPasswordController.php Dosyayı Görüntüle

@@ -0,0 +1,22 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Auth;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
7
+
8
+class ForgotPasswordController extends Controller
9
+{
10
+    /*
11
+    |--------------------------------------------------------------------------
12
+    | Password Reset Controller
13
+    |--------------------------------------------------------------------------
14
+    |
15
+    | This controller is responsible for handling password reset emails and
16
+    | includes a trait which assists in sending these notifications from
17
+    | your application to your users. Feel free to explore this trait.
18
+    |
19
+    */
20
+
21
+    use SendsPasswordResetEmails;
22
+}

+ 108
- 0
app/Http/Controllers/Auth/LoginController.php Dosyayı Görüntüle

@@ -0,0 +1,108 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Auth;
4
+
5
+use App\Helpers\Helper;
6
+use App\Http\Controllers\Controller;
7
+use App\Model\Auditrail\HistoryLogs;
8
+use App\Providers\RouteServiceProvider;
9
+use App\User;
10
+use Illuminate\Foundation\Auth\AuthenticatesUsers;
11
+use Illuminate\Http\Request;
12
+use Illuminate\Support\Facades\DB;
13
+use Illuminate\Support\Facades\Hash;
14
+use Auth;
15
+use Carbon\Carbon;
16
+use Illuminate\Support\Facades\Validator;
17
+
18
+class LoginController extends Controller
19
+{
20
+    /*
21
+    |--------------------------------------------------------------------------
22
+    | Login Controller
23
+    |--------------------------------------------------------------------------
24
+    |
25
+    | This controller handles authenticating users for the application and
26
+    | redirecting them to your home screen. The controller uses a trait
27
+    | to conveniently provide its functionality to your applications.
28
+    |
29
+    */
30
+
31
+    use AuthenticatesUsers;
32
+
33
+    /**
34
+     * Where to redirect users after login.
35
+     *
36
+     * @var string
37
+     */
38
+    protected $redirectTo = '/dashboard';
39
+    private $title = 'Login Page | Admin Jasa Raharja';
40
+
41
+    /**
42
+     * Create a new controller instance.
43
+     *
44
+     * @return void
45
+     */
46
+
47
+    public function __construct()
48
+    {
49
+        DB::getQueryLog();
50
+        $this->middleware('guest')->except('logout');
51
+    }
52
+
53
+    public function index()
54
+    {
55
+        $data = [
56
+            //bawaan
57
+            'title' => $this->title,
58
+        ];
59
+        return view('auth.login', $data);
60
+    }
61
+
62
+    public function action_login(Request $request)
63
+    {
64
+        $rule = [
65
+            'email' => 'required|exists:users,email',
66
+            'password' => 'required'
67
+        ];
68
+        $message = [
69
+            'required' => 'The :attribute is required',
70
+            'exists'    => ':attribute not found',
71
+        ];
72
+        $validator = Validator::make($request->input(), $rule, $message);
73
+
74
+        if ($validator->passes()) {
75
+            $auth = Auth::attempt($request->only('email', 'password'));
76
+
77
+            if ($auth) {
78
+                // $request->session()->put('credential', Auth::user());
79
+                // return redirect(route('admin.dashboard'));
80
+                if (empty(Auth::user()->rumah_sakit)) {
81
+                    // $data_history_logs  = [
82
+                    //     'type_id'         => '1',
83
+                    //     'user_id'         => Auth::user()->id,
84
+                    //     'log'             => 'Login(SIDONI LAB)',
85
+                    //     'waktu'           => Carbon::now()->format('Y-m-d H:i:s'),
86
+                    //     'ip_address'      => Helper::get_ip_user(),
87
+                    //     'created_at'      => Carbon::now()->format('Y-m-d H:i:s'),
88
+                    // ];
89
+                    // $insert_data_item_kantongs = HistoryLogs::insert($data_history_logs);
90
+
91
+                    $request->session()->put('credential', Auth::user());
92
+                    return redirect(route('admin.dashboard'));
93
+                } else {
94
+                    Auth::logout();
95
+                    session()->flush();
96
+                    session()->invalidate();
97
+                    // return back()->with('error', 'Akun yang anda gunakan salah, Silahkan menggunakan Akun Rumah Sakit')->withInput();
98
+                    return redirect(route('auth.index'))->with('message', Helper::failed_alert('Akun yang anda gunakan salah, Silahkan menggunakan Akun Admin'))->withInput();
99
+                }
100
+            } else {
101
+
102
+                return redirect(route('auth.index'))->with('message', Helper::failed_alert('Password Salah'))->withInput();
103
+            }
104
+        } else {
105
+            return redirect(route('auth.index'))->with('message', Helper::failed_alert('Email Belum Terdaftar'))->withInput();;
106
+        }
107
+    }
108
+}

+ 73
- 0
app/Http/Controllers/Auth/RegisterController.php Dosyayı Görüntüle

@@ -0,0 +1,73 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Auth;
4
+
5
+use App\Http\Controllers\Controller;
6
+use App\Providers\RouteServiceProvider;
7
+use App\User;
8
+use Illuminate\Foundation\Auth\RegistersUsers;
9
+use Illuminate\Support\Facades\Hash;
10
+use Illuminate\Support\Facades\Validator;
11
+
12
+class RegisterController extends Controller
13
+{
14
+    /*
15
+    |--------------------------------------------------------------------------
16
+    | Register Controller
17
+    |--------------------------------------------------------------------------
18
+    |
19
+    | This controller handles the registration of new users as well as their
20
+    | validation and creation. By default this controller uses a trait to
21
+    | provide this functionality without requiring any additional code.
22
+    |
23
+    */
24
+
25
+    use RegistersUsers;
26
+
27
+    /**
28
+     * Where to redirect users after registration.
29
+     *
30
+     * @var string
31
+     */
32
+    protected $redirectTo = RouteServiceProvider::HOME;
33
+
34
+    /**
35
+     * Create a new controller instance.
36
+     *
37
+     * @return void
38
+     */
39
+    public function __construct()
40
+    {
41
+        $this->middleware('guest');
42
+    }
43
+
44
+    /**
45
+     * Get a validator for an incoming registration request.
46
+     *
47
+     * @param  array  $data
48
+     * @return \Illuminate\Contracts\Validation\Validator
49
+     */
50
+    protected function validator(array $data)
51
+    {
52
+        return Validator::make($data, [
53
+            'name' => ['required', 'string', 'max:255'],
54
+            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
55
+            'password' => ['required', 'string', 'min:8', 'confirmed'],
56
+        ]);
57
+    }
58
+
59
+    /**
60
+     * Create a new user instance after a valid registration.
61
+     *
62
+     * @param  array  $data
63
+     * @return \App\User
64
+     */
65
+    protected function create(array $data)
66
+    {
67
+        return User::create([
68
+            'name' => $data['name'],
69
+            'email' => $data['email'],
70
+            'password' => Hash::make($data['password']),
71
+        ]);
72
+    }
73
+}

+ 30
- 0
app/Http/Controllers/Auth/ResetPasswordController.php Dosyayı Görüntüle

@@ -0,0 +1,30 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Auth;
4
+
5
+use App\Http\Controllers\Controller;
6
+use App\Providers\RouteServiceProvider;
7
+use Illuminate\Foundation\Auth\ResetsPasswords;
8
+
9
+class ResetPasswordController extends Controller
10
+{
11
+    /*
12
+    |--------------------------------------------------------------------------
13
+    | Password Reset Controller
14
+    |--------------------------------------------------------------------------
15
+    |
16
+    | This controller is responsible for handling password reset requests
17
+    | and uses a simple trait to include this behavior. You're free to
18
+    | explore this trait and override any methods you wish to tweak.
19
+    |
20
+    */
21
+
22
+    use ResetsPasswords;
23
+
24
+    /**
25
+     * Where to redirect users after resetting their password.
26
+     *
27
+     * @var string
28
+     */
29
+    protected $redirectTo = RouteServiceProvider::HOME;
30
+}

+ 42
- 0
app/Http/Controllers/Auth/VerificationController.php Dosyayı Görüntüle

@@ -0,0 +1,42 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Auth;
4
+
5
+use App\Http\Controllers\Controller;
6
+use App\Providers\RouteServiceProvider;
7
+use Illuminate\Foundation\Auth\VerifiesEmails;
8
+
9
+class VerificationController extends Controller
10
+{
11
+    /*
12
+    |--------------------------------------------------------------------------
13
+    | Email Verification Controller
14
+    |--------------------------------------------------------------------------
15
+    |
16
+    | This controller is responsible for handling email verification for any
17
+    | user that recently registered with the application. Emails may also
18
+    | be re-sent if the user didn't receive the original email message.
19
+    |
20
+    */
21
+
22
+    use VerifiesEmails;
23
+
24
+    /**
25
+     * Where to redirect users after verification.
26
+     *
27
+     * @var string
28
+     */
29
+    protected $redirectTo = RouteServiceProvider::HOME;
30
+
31
+    /**
32
+     * Create a new controller instance.
33
+     *
34
+     * @return void
35
+     */
36
+    public function __construct()
37
+    {
38
+        $this->middleware('auth');
39
+        $this->middleware('signed')->only('verify');
40
+        $this->middleware('throttle:6,1')->only('verify', 'resend');
41
+    }
42
+}

+ 13
- 0
app/Http/Controllers/Controller.php Dosyayı Görüntüle

@@ -0,0 +1,13 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
6
+use Illuminate\Foundation\Bus\DispatchesJobs;
7
+use Illuminate\Foundation\Validation\ValidatesRequests;
8
+use Illuminate\Routing\Controller as BaseController;
9
+
10
+class Controller extends BaseController
11
+{
12
+    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
13
+}

+ 125
- 0
app/Http/Controllers/FetchController.php Dosyayı Görüntüle

@@ -0,0 +1,125 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use App\Models\Purchase_request\ListPr;
6
+use Illuminate\Support\Facades\Auth;
7
+use Illuminate\Http\Request;
8
+use App\Models\User;
9
+
10
+use Validator;
11
+use Helper;
12
+use DB;
13
+use Hashids;
14
+use Session;
15
+
16
+class FetchController extends Controller
17
+{
18
+	private $pagetitle = 'Fetch Controller';
19
+	private $route     = 'fetch';
20
+    /**
21
+     * Display a listing of the resource.
22
+     *
23
+     * @return \Illuminate\Http\Response
24
+     */
25
+    public function index()
26
+    {
27
+		$data['pagetitle']  = $this->pagetitle;
28
+		$data['breadcrumb'] = [$this->pagetitle => route($this->route.'.create')];
29
+		$data['route']      = $this->route;
30
+
31
+        return view($this->route.'.index', $data);
32
+    }
33
+
34
+
35
+    //security yang telah di kembangkan
36
+    public function globalfetch(Request $param )
37
+    {
38
+        DB::enableQueryLog();
39
+        $q          = $param->post('q');
40
+        $parameter  = $param->post('parameter');
41
+        $query      = DB::table(decrypt($parameter['t']));
42
+        $except     = $param->post('except');
43
+        $onlyin     = $param->post('onlyin');
44
+        $select     = explode(',', decrypt($parameter['s']));
45
+        // dd($parameter);
46
+
47
+        $query->select($select);
48
+
49
+        if (@$parameter['j'] != '' && @$parameter['j'] != NULL) {
50
+            foreach ($parameter['j'] as $key => $value) {
51
+                if ($value['type'] == 'inner') {
52
+                    $query->join($value['t'] ,$value['fieldA'], $value['operator'], $value['fieldB']);
53
+                }elseif ($value['type'] == 'left') {
54
+                    $query->leftJoin($value['t'] ,$value['fieldA'], $value['operator'], $value['fieldB']);
55
+                }elseif ($value['type'] == 'right') {
56
+                    $query->rightJoin($value['t'] ,$value['fieldA'], $value['operator'], $value['fieldB']);
57
+                }
58
+            }
59
+        }
60
+        if (@$parameter['w'] != '' && @$parameter['w'] != NULL) {
61
+            foreach ($parameter['w'] as $key => $value) {
62
+                // print_r($value['value']);exit();
63
+                $likeornot = '';
64
+                $thefield  = '';
65
+                if ($value['operator'] == 'LIKE' || $value['operator'] == 'Like' || $value['operator'] == 'like' ||
66
+                    $value['operator'] == 'ILIKE' || $value['operator'] == 'Ilike' || $value['operator'] == 'ilike') {
67
+                    $likeornot = '%';
68
+                }
69
+                if (strpos($value['field'], 'select-index-') !== false) {
70
+                    $thefield  = $select[str_replace('select-index-', '', $value['field'])];
71
+                }else{
72
+                    $thefield  = decrypt($value['field']);
73
+                }
74
+                $query->where($thefield, $value['operator'], $likeornot.($value['value'] == '-NMSearch-' ? $q : $value['value']).$likeornot);
75
+            }
76
+        }
77
+
78
+        $id        = explode(',', decrypt($parameter['s']) );
79
+        $exceptarr = explode(',', $except);
80
+        if ($except != '') {
81
+            $query->whereNOTIn($id[0],array_filter($exceptarr));
82
+        }
83
+
84
+        $onlyinarr = explode(',', $onlyin);
85
+        $onlyinarr = array_filter($onlyinarr);
86
+        foreach ($onlyinarr as $key => $value) {
87
+            $onlyinarr[$key] = Hashids::decode($value)[0];
88
+        }
89
+        if ($onlyin != '') {
90
+            $query->whereIn($id[0],array_filter($onlyinarr));
91
+        }
92
+        // $query->where(decrypt($value['field']), $value['operator'], $value);
93
+
94
+        $query->offset((@$parameter['field'] != '' && @$parameter['field'] != NULL ? $parameter['field'] : 0));
95
+        $query->limit((@$parameter['field'] != '' && @$parameter['field'] != NULL ? $parameter['field'] : 5));
96
+
97
+        $result = $query->get();
98
+        // print_r(
99
+        //    DB::getQueryLog()
100
+        // );
101
+        // print_r($result);exit();
102
+        
103
+        $data = array();
104
+        $i    = 0;
105
+        foreach ($result as $keyres => $valueres) {
106
+            $j = 0;
107
+            foreach (explode(',', decrypt($parameter['s']) ) as $key => $value) {
108
+                if ($j == 0) {
109
+                    $data[$i]['id'] = $valueres->{$value};
110
+                }elseif($j == 1){
111
+                    $data[$i]['text'] = $valueres->{$value};
112
+                }else{
113
+                    $data[$i][$value] = $valueres->{$value};
114
+                }
115
+                $j++;
116
+            }
117
+            $i++;
118
+        }
119
+        // echo "<pre>";
120
+        // print_r($data);exit();
121
+
122
+        echo json_encode( ['item' => $data] );
123
+    }
124
+
125
+}

+ 28
- 0
app/Http/Controllers/HomeController.php Dosyayı Görüntüle

@@ -0,0 +1,28 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+
7
+class HomeController extends Controller
8
+{
9
+    /**
10
+     * Create a new controller instance.
11
+     *
12
+     * @return void
13
+     */
14
+    public function __construct()
15
+    {
16
+        $this->middleware('auth');
17
+    }
18
+
19
+    /**
20
+     * Show the application dashboard.
21
+     *
22
+     * @return \Illuminate\Contracts\Support\Renderable
23
+     */
24
+    public function index()
25
+    {
26
+        return view('home');
27
+    }
28
+}

+ 112
- 0
app/Http/Controllers/UploadController.php Dosyayı Görüntüle

@@ -0,0 +1,112 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Image;
7
+use Storage;
8
+use App\Exceptions\Handler;
9
+
10
+//load modelmu
11
+class UploadController extends Controller
12
+{
13
+    public static function upload($config)
14
+    {
15
+        /**tempat simpan storagenya ada di ... */
16
+        $patern_path = '../storage/app/' . $config['path'];
17
+        /**ini khusus storage ya */
18
+        Storage::disk('local')->makeDirectory($config['path'], 0777, true);
19
+        /**buat variabel untuk simpan responnya */
20
+        $result = [];
21
+        if (isset($config['file'])) { //apakah filenya ada ?
22
+            if (is_array($config['file'])) {
23
+
24
+                /**jika array / multiple */
25
+                foreach ($config['file'] as $key_file =>  $value_file) {
26
+
27
+                    if (!empty($config['rename'])) {
28
+                        $rename = $config['rename'] . '-' . $key_file;
29
+                    } else {
30
+                        $rename = $config['file'] . '-' . $key_file;
31
+                    }
32
+                    $filename = self::rename($rename, $value_file);
33
+                    $resize = self::is_resize($config['resize'], $value_file, $patern_path, $filename);
34
+                    $result['file_name'][] = $filename;
35
+                    $result['path'][]      = $config['path'];
36
+                }
37
+                $result['type'] = 'multiple';
38
+                $result['status'] = true;
39
+            } else {
40
+                // dd($config, $patern_path);
41
+                /**jika single file */
42
+                /**rename filenya */
43
+                $filename = self::rename($config['file'], ($config['rename'] ?? null));
44
+                /**jika ada resize */
45
+                if (!empty($config['resize'])) {
46
+                    $resize = self::is_resize($config['resize'], $config['file'], $patern_path, $filename);
47
+                } else {
48
+                    /**jika tidak langsung dimasukkan ke storage */
49
+                    $file = $config['file']->storeAs($config['path'], $filename);
50
+                }
51
+                // dd($filename, $resize);
52
+
53
+                $result['file_name']     = $filename;
54
+                $result['path']          = $config['path'];
55
+                $result['type']          = 'single';
56
+                $result['status']        = true;
57
+            }
58
+        } else {
59
+            $result['status']  = FALSE;
60
+        }
61
+        // dd($result);
62
+        return $result;
63
+    }
64
+
65
+    public static function rename($file, $rename = null)
66
+    {
67
+        try {
68
+            /**rename space dengan - */
69
+            $filename = implode('-', explode(' ', $file->getClientOriginalName()));
70
+            /**jika rename tersedia maka pakai nama renamenya */
71
+            if (!empty($rename)) {
72
+
73
+                $filename = $rename . '.' . $file->extension();
74
+            }
75
+            return $filename;
76
+        } catch (\Throwable $th) {
77
+            Handler::report($th);
78
+        }
79
+    }
80
+
81
+    public static function is_resize($resize, $file, $patern_path, $filename)
82
+    {
83
+        try {
84
+
85
+            /**cek, apakah resize ada  */
86
+            if (!empty($resize)) {
87
+                /**cek apakah format resize array, jika iya bisa digunakan */
88
+                if (is_array($resize)) {
89
+
90
+                    /**resize bisa digunakan jika formatnya png, jpg / jpeg, selain itu no */
91
+                    if (in_array($file->extension(), ['png', 'jpg', 'jpeg'])) {
92
+
93
+                        $img = Image::make($file->path());
94
+                        $img->resize($resize[0], $resize[1])->save($patern_path . '/' . $filename);
95
+                        return $img;
96
+                    } else {
97
+                        dd('format harus png, jpg atau jpeg');
98
+                    }
99
+                } else {
100
+                    dd('format resize harus array, exp => [300,400]');
101
+                }
102
+            }
103
+        } catch (\Throwable $th) {
104
+            Handler::report($th);
105
+        }
106
+    }
107
+
108
+    public static function get_image($file)
109
+    {
110
+        return response()->file(storage_path('app/' . ($file)));
111
+    }
112
+}

+ 74
- 0
app/Http/Kernel.php Dosyayı Görüntüle

@@ -0,0 +1,74 @@
1
+<?php
2
+
3
+namespace App\Http;
4
+
5
+use Illuminate\Foundation\Http\Kernel as HttpKernel;
6
+
7
+class Kernel extends HttpKernel
8
+{
9
+    /**
10
+     * The application's global HTTP middleware stack.
11
+     *
12
+     * These middleware are run during every request to your application.
13
+     *
14
+     * @var array
15
+     */
16
+    protected $middleware = [
17
+        \App\Http\Middleware\TrustProxies::class,
18
+        \Fruitcake\Cors\HandleCors::class,
19
+        \App\Http\Middleware\CheckForMaintenanceMode::class,
20
+        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
21
+        \App\Http\Middleware\TrimStrings::class,
22
+        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
23
+    ];
24
+
25
+    /**
26
+     * The application's route middleware groups.
27
+     *
28
+     * @var array
29
+     */
30
+    protected $middlewareGroups = [
31
+        'web' => [
32
+            \App\Http\Middleware\EncryptCookies::class,
33
+            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
34
+            \Illuminate\Session\Middleware\StartSession::class,
35
+            // \Illuminate\Session\Middleware\AuthenticateSession::class,
36
+            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
37
+            \App\Http\Middleware\VerifyCsrfToken::class,
38
+            \Illuminate\Routing\Middleware\SubstituteBindings::class,
39
+            \RealRashid\SweetAlert\ToSweetAlert::class,
40
+        ],
41
+
42
+        'api' => [
43
+            'throttle:60,1',
44
+            \Illuminate\Routing\Middleware\SubstituteBindings::class,
45
+        ],
46
+    ];
47
+
48
+    /**
49
+     * The application's route middleware.
50
+     *
51
+     * These middleware may be assigned to groups or used individually.
52
+     *
53
+     * @var array
54
+     */
55
+    protected $routeMiddleware = [
56
+        'auth' => \App\Http\Middleware\Authenticate::class,
57
+        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
58
+        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
59
+        'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
60
+        'can' => \Illuminate\Auth\Middleware\Authorize::class,
61
+        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
62
+        'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
63
+        'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
64
+        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
65
+        'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
66
+
67
+        /**auth cek */
68
+        'auth_cek' => \App\Http\Middleware\AuthCheckLogin::class,
69
+        /**spatie */
70
+        'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
71
+        'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
72
+        'api_version' => \App\Http\Middleware\APIVersion::class,
73
+    ];
74
+}

+ 23
- 0
app/Http/Middleware/APIVersion.php Dosyayı Görüntüle

@@ -0,0 +1,23 @@
1
+<?php
2
+namespace App\Http\Middleware;
3
+use Closure;
4
+/**
5
+ * Class APIVersion
6
+ * @package App\Http\Middleware
7
+ */
8
+class APIVersion
9
+{
10
+    /**
11
+     * Handle an incoming request.
12
+     *
13
+     * @param  Request $request
14
+     * @param  Closure $next
15
+     *
16
+     * @return mixed
17
+     */
18
+    public function handle($request, Closure $next, $guard)
19
+    {
20
+        config(['app.api.version' => $guard]);
21
+        return $next($request);
22
+    }
23
+}

+ 24
- 0
app/Http/Middleware/AuthCheckLogin.php Dosyayı Görüntüle

@@ -0,0 +1,24 @@
1
+<?php
2
+
3
+namespace App\Http\Middleware;
4
+
5
+use Closure;
6
+use Auth;
7
+
8
+class AuthCheckLogin
9
+{
10
+    /**
11
+     * Handle an incoming request.
12
+     *
13
+     * @param  \Illuminate\Http\Request  $request
14
+     * @param  \Closure  $next
15
+     * @return mixed
16
+     */
17
+    public function handle($request, Closure $next)
18
+    {
19
+        if (empty(Auth::id())) {
20
+            return redirect(route('auth.index'));
21
+        }
22
+        return $next($request);
23
+    }
24
+}

+ 21
- 0
app/Http/Middleware/Authenticate.php Dosyayı Görüntüle

@@ -0,0 +1,21 @@
1
+<?php
2
+
3
+namespace App\Http\Middleware;
4
+
5
+use Illuminate\Auth\Middleware\Authenticate as Middleware;
6
+
7
+class Authenticate extends Middleware
8
+{
9
+    /**
10
+     * Get the path the user should be redirected to when they are not authenticated.
11
+     *
12
+     * @param  \Illuminate\Http\Request  $request
13
+     * @return string|null
14
+     */
15
+    protected function redirectTo($request)
16
+    {
17
+        if (! $request->expectsJson()) {
18
+            return route('login');
19
+        }
20
+    }
21
+}

+ 17
- 0
app/Http/Middleware/CheckForMaintenanceMode.php Dosyayı Görüntüle

@@ -0,0 +1,17 @@
1
+<?php
2
+
3
+namespace App\Http\Middleware;
4
+
5
+use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;
6
+
7
+class CheckForMaintenanceMode extends Middleware
8
+{
9
+    /**
10
+     * The URIs that should be reachable while maintenance mode is enabled.
11
+     *
12
+     * @var array
13
+     */
14
+    protected $except = [
15
+        //
16
+    ];
17
+}

+ 17
- 0
app/Http/Middleware/EncryptCookies.php Dosyayı Görüntüle

@@ -0,0 +1,17 @@
1
+<?php
2
+
3
+namespace App\Http\Middleware;
4
+
5
+use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
6
+
7
+class EncryptCookies extends Middleware
8
+{
9
+    /**
10
+     * The names of the cookies that should not be encrypted.
11
+     *
12
+     * @var array
13
+     */
14
+    protected $except = [
15
+        //
16
+    ];
17
+}

+ 27
- 0
app/Http/Middleware/RedirectIfAuthenticated.php Dosyayı Görüntüle

@@ -0,0 +1,27 @@
1
+<?php
2
+
3
+namespace App\Http\Middleware;
4
+
5
+use App\Providers\RouteServiceProvider;
6
+use Closure;
7
+use Illuminate\Support\Facades\Auth;
8
+
9
+class RedirectIfAuthenticated
10
+{
11
+    /**
12
+     * Handle an incoming request.
13
+     *
14
+     * @param  \Illuminate\Http\Request  $request
15
+     * @param  \Closure  $next
16
+     * @param  string|null  $guard
17
+     * @return mixed
18
+     */
19
+    public function handle($request, Closure $next, $guard = null)
20
+    {
21
+        if (Auth::guard($guard)->check()) {
22
+            return redirect(RouteServiceProvider::HOME);
23
+        }
24
+
25
+        return $next($request);
26
+    }
27
+}

+ 18
- 0
app/Http/Middleware/TrimStrings.php Dosyayı Görüntüle

@@ -0,0 +1,18 @@
1
+<?php
2
+
3
+namespace App\Http\Middleware;
4
+
5
+use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
6
+
7
+class TrimStrings extends Middleware
8
+{
9
+    /**
10
+     * The names of the attributes that should not be trimmed.
11
+     *
12
+     * @var array
13
+     */
14
+    protected $except = [
15
+        'password',
16
+        'password_confirmation',
17
+    ];
18
+}

+ 23
- 0
app/Http/Middleware/TrustProxies.php Dosyayı Görüntüle

@@ -0,0 +1,23 @@
1
+<?php
2
+
3
+namespace App\Http\Middleware;
4
+
5
+use Fideloper\Proxy\TrustProxies as Middleware;
6
+use Illuminate\Http\Request;
7
+
8
+class TrustProxies extends Middleware
9
+{
10
+    /**
11
+     * The trusted proxies for this application.
12
+     *
13
+     * @var array|string
14
+     */
15
+    protected $proxies;
16
+
17
+    /**
18
+     * The headers that should be used to detect proxies.
19
+     *
20
+     * @var int
21
+     */
22
+    protected $headers = Request::HEADER_X_FORWARDED_ALL;
23
+}

+ 17
- 0
app/Http/Middleware/VerifyCsrfToken.php Dosyayı Görüntüle

@@ -0,0 +1,17 @@
1
+<?php
2
+
3
+namespace App\Http\Middleware;
4
+
5
+use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
6
+
7
+class VerifyCsrfToken extends Middleware
8
+{
9
+    /**
10
+     * The URIs that should be excluded from CSRF verification.
11
+     *
12
+     * @var array
13
+     */
14
+    protected $except = [
15
+        //
16
+    ];
17
+}

+ 70
- 0
app/Imports/StockReleaseImport.php Dosyayı Görüntüle

@@ -0,0 +1,70 @@
1
+<?php
2
+
3
+namespace App\Imports;
4
+
5
+use App\Model\Data\StockRelease;
6
+use Maatwebsite\Excel\Concerns\ToModel;
7
+// use Illuminate\Support\Collection;
8
+// use Maatwebsite\Excel\Concerns\ToCollection;
9
+use Maatwebsite\Excel\Concerns\WithHeadingRow;
10
+use Maatwebsite\Excel\Concerns\WithStartRow;
11
+// use Maatwebsite\Excel\Concerns\WithBatchInserts;
12
+// use Maatwebsite\Excel\Concerns\WithChunkReading;
13
+use App\Helpers\Helper;
14
+use Auth;
15
+
16
+
17
+class StockReleaseImport implements ToModel, WithHeadingRow, WithStartRow
18
+// class StockReleaseImport implements ToCollection, WithHeadingRow
19
+{
20
+    private $route = 'admin.data.stock_darah.';
21
+    /**
22
+    * @param array $row
23
+    *
24
+    * @return \Illuminate\Database\Eloquent\Model|null
25
+    */
26
+    public function headingRow(): int
27
+    {
28
+        return 17;
29
+    }
30
+
31
+    public function startRow(): int
32
+{
33
+    return 18;
34
+}
35
+
36
+    public function model(Array $row)
37
+    {
38
+        // foreach ($rows as $row) 
39
+        // {   
40
+            return new StockRelease([
41
+                'no_release'            => $row['no_release'],
42
+                'no_kantong'            => $row['no_kantong'],
43
+                'produk_id'             => $row['produk_id'],
44
+                'golongan_darah_id'     => $row['golongan_darah_id'],
45
+                'status_keterangan'     => $row['status_keterangan'],
46
+                'user_checker_id'       => Auth::user()->id,
47
+                'user_pengesah_id'      => Auth::user()->id,
48
+                'is_delivery'           => $row['is_delivery'],
49
+                'tanggal_release'       => $row['tanggal_release'],
50
+                'tanggal_aftap'         => $row['tanggal_aftap'],
51
+                'volume_release'        => $row['volume_release'],
52
+                'rhesus_id'             => $row['rhesus_id'],
53
+                'unit_donor_darah_id'   => $row['unit_donor_darah_id'],
54
+                'expired_date'          => $row['expired_date'],
55
+                'status_id'             => $row['status_id'],
56
+                'tanggal_olah'          => $row['tanggal_olah'],
57
+            ]);
58
+
59
+    }
60
+
61
+    // public function batchSize(): int
62
+    // {
63
+    //     return 1000;
64
+    // }
65
+
66
+    // public function chunkSize(): int
67
+    // {
68
+    //     return 1000;
69
+    // }
70
+}

+ 15
- 0
app/Model/ModelHasRoles.php Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace App\Model;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class ModelHasRoles extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'model_has_roles';
12
+    protected $fillable = [];
13
+    //public $incrementing = false; //jika primary keynya string
14
+    //public $timestamps = false; //matiin created_at, updated_at
15
+}

+ 15
- 0
app/Model/NewsLog.php Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace App\Model;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class NewsLog extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'news_logs';
12
+    protected $fillable = [];
13
+    //public $incrementing = false; //jika primary keynya string
14
+    //public $timestamps = false; //matiin created_at, updated_at
15
+}

+ 15
- 0
app/Model/PointLog.php Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace App\Model;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class PointLog extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'point_logs';
12
+    protected $fillable = [];
13
+    //public $incrementing = false; //jika primary keynya string
14
+    //public $timestamps = false; //matiin created_at, updated_at
15
+}

+ 15
- 0
app/Model/Points.php Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace App\Model;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class Points extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'master_points';
12
+    protected $fillable = [];
13
+    //public $incrementing = false; //jika primary keynya string
14
+    //public $timestamps = false; //matiin created_at, updated_at
15
+}

+ 24
- 0
app/Model/Profile.php Dosyayı Görüntüle

@@ -0,0 +1,24 @@
1
+<?php
2
+
3
+namespace App\Model;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class Profile extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'profiles';
12
+    protected $fillable = ['user_id', 'fullname', 'phone_number', 'gender', 'is_have_organization', 'organization_id', 'id_member'];
13
+    //public $incrementing = false; //jika primary keynya string
14
+    //public $timestamps = false; //matiin created_at, updated_at
15
+
16
+    public function user()
17
+    {
18
+        return $this->belongsTo('App\User');
19
+    }
20
+    public function kd()
21
+    {
22
+        return $this->belongsTo('App\Model\Raharja\KelompokDriver');
23
+    }
24
+}

+ 18
- 0
app/Model/Raharja/CategoryMesssage.php Dosyayı Görüntüle

@@ -0,0 +1,18 @@
1
+<?php
2
+
3
+namespace App\Model\Raharja;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class CategoryMesssage extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'category_message';
12
+    protected $fillable = [
13
+        'name',
14
+        'deskripsi',
15
+    ];
16
+    //public $incrementing = false; //jika primary keynya string
17
+    //public $timestamps = false; //matiin created_at, updated_at
18
+}

+ 21
- 0
app/Model/Raharja/EventOrganisasi.php Dosyayı Görüntüle

@@ -0,0 +1,21 @@
1
+<?php
2
+
3
+namespace App\Model\Raharja;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class EventOrganisasi extends Model
8
+{
9
+    protected $table = 'event_organisasi';
10
+    protected $fillable = [
11
+        'start_date',
12
+        'end_date',
13
+        'banner',
14
+        'deskripsi',
15
+    ];
16
+
17
+    public function kelompokMember(){
18
+        return $this->hasMany(EventOrganisasiMembers::class, 'event_organisasi_id', 'id');
19
+    }
20
+
21
+}

+ 18
- 0
app/Model/Raharja/EventOrganisasiMembers.php Dosyayı Görüntüle

@@ -0,0 +1,18 @@
1
+<?php
2
+
3
+namespace App\Model\Raharja;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class EventOrganisasiMembers extends Model
8
+{
9
+    protected $table = 'event_organisasi_members';
10
+    protected $fillable = [
11
+        'event_organisasi_id',
12
+        'kelompok_driver_id',
13
+    ];
14
+
15
+    public function kelompokDriver(){
16
+        return $this->belongsTo(KelompokDriver::class, 'kelompok_driver_id', 'id');
17
+    }
18
+}

+ 20
- 0
app/Model/Raharja/KelompokDriver.php Dosyayı Görüntüle

@@ -0,0 +1,20 @@
1
+<?php
2
+
3
+namespace App\Model\Raharja;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class KelompokDriver extends Model
8
+{
9
+    protected $table = 'kelompok_driver';
10
+    protected $fillable = [
11
+        'logo',
12
+        'nama',
13
+        'website',
14
+        'deskripsi',
15
+    ];
16
+
17
+    public function profile(){
18
+        return $this->hasMany(Profile::class, 'organization_id', 'id');
19
+    }
20
+}

+ 28
- 0
app/Model/Raharja/Message.php Dosyayı Görüntüle

@@ -0,0 +1,28 @@
1
+<?php
2
+
3
+namespace App\Model\Raharja;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class Message extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'message';
12
+    protected $fillable = [
13
+        'category_message_id',
14
+        'title',
15
+        'content',
16
+        'user_id',
17
+    ];
18
+
19
+    public function userReceive(){
20
+        return $this->hasMany(UserReceive::class, 'message_id', 'id');
21
+    }
22
+
23
+    public function categoryMessage(){
24
+        return $this->belongsTo(CategoryMesssage::class, 'category_message_id', 'id');
25
+    }
26
+    //public $incrementing = false; //jika primary keynya string
27
+    //public $timestamps = false; //matiin created_at, updated_at
28
+}

+ 26
- 0
app/Model/Raharja/News.php Dosyayı Görüntüle

@@ -0,0 +1,26 @@
1
+<?php
2
+
3
+namespace App\Model\Raharja;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class News extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'news';
12
+    protected $fillable = [
13
+        'title',
14
+        'content',
15
+        'user_id',
16
+        'thumbnail',
17
+        'date_publish',
18
+        'sub_title',
19
+    ];
20
+
21
+    public function newsLikes(){
22
+        return $this->hasMany(NewsLikes::class, 'news_id', 'id');
23
+    }
24
+    //public $incrementing = false; //jika primary keynya string
25
+    //public $timestamps = false; //matiin created_at, updated_at
26
+}

+ 18
- 0
app/Model/Raharja/NewsLikes.php Dosyayı Görüntüle

@@ -0,0 +1,18 @@
1
+<?php
2
+
3
+namespace App\Model\Raharja;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class NewsLikes extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'news_likes';
12
+    protected $fillable = [
13
+        'news_id',
14
+        'user_id',
15
+    ];
16
+    //public $incrementing = false; //jika primary keynya string
17
+    //public $timestamps = false; //matiin created_at, updated_at
18
+}

+ 26
- 0
app/Model/Raharja/Tips.php Dosyayı Görüntüle

@@ -0,0 +1,26 @@
1
+<?php
2
+
3
+namespace App\Model\Raharja;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class Tips extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'tips';
12
+    protected $fillable = [
13
+        'title',
14
+        'content',
15
+        'user_id',
16
+        'thumbnail',
17
+        'sub_title',
18
+        'date_publish',
19
+    ];
20
+
21
+    public function tipsLike(){
22
+        return $this->hasMany(TipsLikes::class, 'tips_id', 'id');
23
+    }
24
+    //public $incrementing = false; //jika primary keynya string
25
+    //public $timestamps = false; //matiin created_at, updated_at
26
+}

+ 18
- 0
app/Model/Raharja/TipsLikes.php Dosyayı Görüntüle

@@ -0,0 +1,18 @@
1
+<?php
2
+
3
+namespace App\Model\Raharja;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class TipsLikes extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'tips_likes';
12
+    protected $fillable = [
13
+        'tips_id',
14
+        'user_id',
15
+    ];
16
+    //public $incrementing = false; //jika primary keynya string
17
+    //public $timestamps = false; //matiin created_at, updated_at
18
+}

+ 23
- 0
app/Model/Raharja/UserReceive.php Dosyayı Görüntüle

@@ -0,0 +1,23 @@
1
+<?php
2
+
3
+namespace App\Model\Raharja;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class UserReceive extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'user_receive';
12
+    protected $fillable = [
13
+        'message_id',
14
+        'user_id',
15
+        'is_check',
16
+    ];
17
+
18
+    public function getMessage(){
19
+        return $this->belongsTo(Message::class, 'message_id', 'id');
20
+    }
21
+    //public $incrementing = false; //jika primary keynya string
22
+    //public $timestamps = false; //matiin created_at, updated_at
23
+}

+ 14
- 0
app/Model/RoleHasPermission.php Dosyayı Görüntüle

@@ -0,0 +1,14 @@
1
+<?php
2
+
3
+namespace App\Model;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class RoleHasPermission extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    protected $table = 'role_has_permissions';
11
+    protected $fillable = ['permission_id', 'role_id'];
12
+    public $incrementing = false; //jika primary keynya string
13
+    public $timestamps = false; //matiin created_at, updated_at
14
+}

+ 15
- 0
app/Model/TipsLog.php Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace App\Model;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class TipsLog extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'tips_logs';
12
+    protected $fillable = [];
13
+    //public $incrementing = false; //jika primary keynya string
14
+    //public $timestamps = false; //matiin created_at, updated_at
15
+}

+ 21
- 0
app/Model/Transportation.php Dosyayı Görüntüle

@@ -0,0 +1,21 @@
1
+<?php
2
+
3
+namespace App\Model;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class Transportation extends Model
8
+{
9
+    //
10
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
11
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
12
+    protected $table = 'transportation';
13
+    protected $fillable = [
14
+      'user_id',
15
+      'transportation_photo',
16
+      'name',
17
+      'transportation_identity',
18
+      'transportation_type'
19
+    ];
20
+
21
+}

+ 15
- 0
app/Model/Travel.php Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace App\Model;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class Travel extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'travel';
12
+    protected $fillable = [];
13
+    //public $incrementing = false; //jika primary keynya string
14
+    //public $timestamps = false; //matiin created_at, updated_at
15
+}

+ 15
- 0
app/Model/TravelLog.php Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace App\Model;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class TravelLog extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'travel_logs';
12
+    protected $fillable = [];
13
+    //public $incrementing = false; //jika primary keynya string
14
+    //public $timestamps = false; //matiin created_at, updated_at
15
+}

+ 15
- 0
app/Model/Trivia.php Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace App\Model;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class Trivia extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'trivia';
12
+    protected $fillable = [];
13
+    //public $incrementing = false; //jika primary keynya string
14
+    //public $timestamps = false; //matiin created_at, updated_at
15
+}

+ 15
- 0
app/Model/TriviaAnswer.php Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace App\Model;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class TriviaAnswer extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'trivia_answer';
12
+    protected $fillable = [];
13
+    //public $incrementing = false; //jika primary keynya string
14
+    //public $timestamps = false; //matiin created_at, updated_at
15
+}

+ 39
- 0
app/Model/User/MasterRumahSakits.php Dosyayı Görüntüle

@@ -0,0 +1,39 @@
1
+<?php
2
+
3
+namespace App\Model\User;
4
+
5
+use Illuminate\Database\Eloquent\SoftDeletes;
6
+
7
+
8
+use Illuminate\Database\Eloquent\Model;
9
+
10
+class MasterRumahSakits extends Model
11
+{
12
+    use SoftDeletes;
13
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
14
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
15
+    protected $table = 'master_rumah_sakits';
16
+    protected $fillable = [
17
+        'nama',
18
+        'kode_rumah_sakit',
19
+        'deskripsi',
20
+        'alamat',
21
+        'latitude',
22
+        'longtitude',
23
+        'nama_bank_darah',
24
+        'user_login_id',
25
+        'provinsi_id',
26
+        'kabupaten_kota_id'
27
+    ];
28
+    //public $incrementing = false; //jika primary keynya string
29
+    //public $timestamps = false; //matiin created_at, updated_at
30
+
31
+    public function user()
32
+    {
33
+        return $this->belongsTo('App\User', 'user_login_id', 'id');
34
+    }
35
+    public function kota()
36
+    {
37
+        return $this->belongsTo('App\Model\Master\KabupatenKota', 'kabupaten_kota_id', 'id');
38
+    }
39
+}

+ 30
- 0
app/Model/User/PetugasUnitDonorDarahUdds.php Dosyayı Görüntüle

@@ -0,0 +1,30 @@
1
+<?php
2
+
3
+namespace App\Model\User;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class PetugasUnitDonorDarahUdds extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'petugas_unit_donor_darah_udds';
12
+    protected $fillable = [
13
+        'nama',
14
+        'unit_donor_darah_id',
15
+        'user_login_id'
16
+    ];
17
+    //public $incrementing = false; //jika primary keynya string
18
+    //public $timestamps = false; //matiin created_at, updated_at
19
+
20
+    public function user()
21
+    {
22
+        //localkeymu, idnya
23
+        return $this->belongsTo('App\User', 'user_login_id', 'id');
24
+    }
25
+
26
+    public function udd()
27
+    {
28
+        return $this->belongsTo('App\Model\Master\MasterUdd', 'unit_donor_darah_id', 'id');
29
+    }
30
+}

+ 29
- 0
app/Providers/AppServiceProvider.php Dosyayı Görüntüle

@@ -0,0 +1,29 @@
1
+<?php
2
+
3
+namespace App\Providers;
4
+
5
+use Illuminate\Support\ServiceProvider;
6
+
7
+class AppServiceProvider extends ServiceProvider
8
+{
9
+    /**
10
+     * Register any application services.
11
+     *
12
+     * @return void
13
+     */
14
+    public function register()
15
+    {
16
+        //
17
+    }
18
+
19
+    /**
20
+     * Bootstrap any application services.
21
+     *
22
+     * @return void
23
+     */
24
+    public function boot()
25
+    {
26
+        config(['app.locale' => 'id']);
27
+        \Carbon\Carbon::setLocale('id');
28
+    }
29
+}

+ 30
- 0
app/Providers/AuthServiceProvider.php Dosyayı Görüntüle

@@ -0,0 +1,30 @@
1
+<?php
2
+
3
+namespace App\Providers;
4
+
5
+use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
6
+use Illuminate\Support\Facades\Gate;
7
+
8
+class AuthServiceProvider extends ServiceProvider
9
+{
10
+    /**
11
+     * The policy mappings for the application.
12
+     *
13
+     * @var array
14
+     */
15
+    protected $policies = [
16
+        // 'App\Model' => 'App\Policies\ModelPolicy',
17
+    ];
18
+
19
+    /**
20
+     * Register any authentication / authorization services.
21
+     *
22
+     * @return void
23
+     */
24
+    public function boot()
25
+    {
26
+        $this->registerPolicies();
27
+
28
+        //
29
+    }
30
+}

+ 21
- 0
app/Providers/BroadcastServiceProvider.php Dosyayı Görüntüle

@@ -0,0 +1,21 @@
1
+<?php
2
+
3
+namespace App\Providers;
4
+
5
+use Illuminate\Support\Facades\Broadcast;
6
+use Illuminate\Support\ServiceProvider;
7
+
8
+class BroadcastServiceProvider extends ServiceProvider
9
+{
10
+    /**
11
+     * Bootstrap any application services.
12
+     *
13
+     * @return void
14
+     */
15
+    public function boot()
16
+    {
17
+        Broadcast::routes();
18
+
19
+        require base_path('routes/channels.php');
20
+    }
21
+}

+ 34
- 0
app/Providers/EventServiceProvider.php Dosyayı Görüntüle

@@ -0,0 +1,34 @@
1
+<?php
2
+
3
+namespace App\Providers;
4
+
5
+use Illuminate\Auth\Events\Registered;
6
+use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
7
+use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
8
+use Illuminate\Support\Facades\Event;
9
+
10
+class EventServiceProvider extends ServiceProvider
11
+{
12
+    /**
13
+     * The event listener mappings for the application.
14
+     *
15
+     * @var array
16
+     */
17
+    protected $listen = [
18
+        Registered::class => [
19
+            SendEmailVerificationNotification::class,
20
+        ],
21
+    ];
22
+
23
+    /**
24
+     * Register any events for your application.
25
+     *
26
+     * @return void
27
+     */
28
+    public function boot()
29
+    {
30
+        parent::boot();
31
+
32
+        //
33
+    }
34
+}

+ 84
- 0
app/Providers/RouteServiceProvider.php Dosyayı Görüntüle

@@ -0,0 +1,84 @@
1
+<?php
2
+
3
+namespace App\Providers;
4
+
5
+use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
6
+use Illuminate\Support\Facades\Route;
7
+
8
+class RouteServiceProvider extends ServiceProvider
9
+{
10
+    /**
11
+     * This namespace is applied to your controller routes.
12
+     *
13
+     * In addition, it is set as the URL generator's root namespace.
14
+     *
15
+     * @var string
16
+     */
17
+    protected $namespace = 'App\Http\Controllers';
18
+    protected $apiNamespace ='App\Http\Controllers\Api';
19
+
20
+    /**
21
+     * The path to the "home" route for your application.
22
+     *
23
+     * @var string
24
+     */
25
+    public const HOME = '/dashboard';
26
+
27
+    /**
28
+     * Define your route model bindings, pattern filters, etc.
29
+     *
30
+     * @return void
31
+     */
32
+    public function boot()
33
+    {
34
+        //
35
+
36
+        parent::boot();
37
+    }
38
+
39
+    /**
40
+     * Define the routes for the application.
41
+     *
42
+     * @return void
43
+     */
44
+    public function map()
45
+    {
46
+        $this->mapApiRoutes();
47
+
48
+        $this->mapWebRoutes();
49
+
50
+        //
51
+    }
52
+
53
+    /**
54
+     * Define the "web" routes for the application.
55
+     *
56
+     * These routes all receive session state, CSRF protection, etc.
57
+     *
58
+     * @return void
59
+     */
60
+    protected function mapWebRoutes()
61
+    {
62
+        Route::middleware('web')
63
+            ->namespace($this->namespace)
64
+            ->group(base_path('routes/web.php'));
65
+    }
66
+
67
+    /**
68
+     * Define the "api" routes for the application.
69
+     *
70
+     * These routes are typically stateless.
71
+     *
72
+     * @return void
73
+     */
74
+    protected function mapApiRoutes()
75
+    {
76
+        Route::group([
77
+            'middleware' => ['api', 'api_version:v1'],
78
+            'namespace'  => "{$this->apiNamespace}\V1",
79
+            'prefix'     => 'api/v1',
80
+        ], function ($router) {
81
+            require base_path('routes/api_v1.php');
82
+        });    
83
+    }
84
+}

+ 15
- 0
app/Roles.php Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace App;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class Roles extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'Roles';
12
+    protected $fillable = [];
13
+    //public $incrementing = false; //jika primary keynya string
14
+    //public $timestamps = false; //matiin created_at, updated_at
15
+}

+ 26
- 0
app/StockLogs.php Dosyayı Görüntüle

@@ -0,0 +1,26 @@
1
+<?php
2
+
3
+namespace App\Model\Data;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class StockLogs extends Model
8
+{
9
+    //protected $connection = 'connection-name'; //jika menggunakan 2 DB modelnya harus dikasih ini
10
+    //protected $primaryKey = 'your_key_name'; // set primarykeymu jika bukan ID
11
+    protected $table = 'stock_logs';
12
+    protected $fillable = [
13
+        'user_id',
14
+        'log',
15
+        'quantity_kantong',
16
+        'is_stock_in',
17
+        'is_stock_out',
18
+    ];
19
+    //public $incrementing = false; //jika primary keynya string
20
+    //public $timestamps = false; //matiin created_at, updated_at
21
+
22
+    public function user()
23
+    {
24
+        return $this->belongsTo('App\User', 'user_id', 'id');
25
+    }
26
+}

+ 58
- 0
app/User.php Dosyayı Görüntüle

@@ -0,0 +1,58 @@
1
+<?php
2
+
3
+namespace App;
4
+
5
+use Illuminate\Contracts\Auth\MustVerifyEmail;
6
+use Illuminate\Foundation\Auth\User as Authenticatable;
7
+use Illuminate\Notifications\Notifiable;
8
+use Spatie\Permission\Traits\HasRoles;
9
+
10
+class User extends Authenticatable
11
+{
12
+    use Notifiable, HasRoles;
13
+
14
+    /**
15
+     * The attributes that are mass assignable.
16
+     *
17
+     * @var array
18
+     */
19
+    protected $table = 'users';
20
+    protected $fillable = [
21
+        'name',
22
+        'password',
23
+        'email',
24
+    ];
25
+
26
+    /**
27
+     * The attributes that should be hidden for arrays.
28
+     *
29
+     * @var array
30
+     */
31
+    protected $hidden = [
32
+        'password',
33
+    ];
34
+    public $timestamps = false; //matiin created_at, updated_at
35
+    /**
36
+     * The attributes that should be cast to native types.
37
+     *
38
+     * @var array
39
+     */
40
+    protected $casts = [
41
+        'email_verified_at' => 'datetime',
42
+    ];
43
+
44
+    public function profile()
45
+    {
46
+        return $this->hasOne('App\Profile');
47
+    }
48
+
49
+    // public function petugas()
50
+    // {
51
+    //     return $this->belongsTo('App\Model\User\PetugasUnitDonorDarahUdds', 'id', 'user_login_id');
52
+    // }
53
+
54
+    // public function rumah_sakit()
55
+    // {
56
+    //     return $this->belongsTo('App\Model\User\MasterRumahSakits', 'id', 'user_login_id');
57
+    // }
58
+}

+ 68
- 0
app/Utils/DashboardUtil.php Dosyayı Görüntüle

@@ -0,0 +1,68 @@
1
+<?php
2
+
3
+namespace App\Utils;
4
+
5
+use DB;
6
+use Illuminate\Support\Carbon;
7
+use App\Model\Master\ItemKantongs;
8
+use Auth;
9
+
10
+class DashboardUtil
11
+{
12
+    public function getDataLast30Days($param, $petugas_udd_id, $date_at)
13
+    {
14
+        $query = ItemKantongs::where('status_id', $param)
15
+                    ->where('unit_donor_darah_id', $petugas_udd_id)
16
+                    ->whereBetween(DB::raw('date(kantong_items.'.$date_at.')'), [\Carbon::now()->subDays(30), \Carbon::now()])
17
+                    ->orderBy($date_at, 'ASC');
18
+        $query->select(
19
+            DB::raw("DATE_FORMAT(kantong_items.".$date_at.", '%Y-%m-%d') as date, count(*) as total"),
20
+        )
21
+        ->groupBy(DB::raw('Date(kantong_items.'.$date_at.')'));
22
+        $data = $query->get();
23
+
24
+        $arr= [];
25
+        for ($i = 29; $i >= 0; $i--) {
26
+            $date = \Carbon::now()->subDays($i)->format('Y-m-d');
27
+            $arr[$date] = 0;
28
+        }
29
+
30
+        for ($i = 29; $i >= 0; $i--) {
31
+            $date = \Carbon::now()->subDays($i)->format('Y-m-d');
32
+
33
+            if(!empty($data[$i])){ //cek data histori pendonor
34
+                $tanggal = $data[$i]->date;
35
+                $arr[$tanggal] = $data[$i]->total;
36
+            }
37
+        }
38
+
39
+        ksort($arr);
40
+        return $arr;
41
+    }
42
+
43
+    public function getDataLast1Years($param, $petugas_udd_id)
44
+    {
45
+        $now = Carbon::now();
46
+        $year = $now->year;
47
+
48
+        $query = DB::select("SELECT COUNT(*) as jumlah, MONTH(updated_at) as bulan FROM kantong_items WHERE YEAR(updated_at) = $year and status_id = $param and unit_donor_darah_id = $petugas_udd_id GROUP BY MONTH(updated_at)");
49
+
50
+        $data = array();
51
+        for($i=0; $i<=12; $i++)
52
+        {
53
+            if(!empty($query[$i])){
54
+                if($query[$i]->bulan != $i+1){
55
+                    $data[$i] = 0;
56
+                }
57
+                $bulan = $query[$i]->bulan;
58
+                $data[$bulan] = $query[$i]->jumlah;
59
+            }else{
60
+                if(empty($data[$i])){
61
+                    $data[$i] = 0;
62
+                }
63
+            }
64
+        }
65
+        ksort($data);
66
+        return $data;
67
+    }
68
+}

+ 53
- 0
artisan Dosyayı Görüntüle

@@ -0,0 +1,53 @@
1
+#!/usr/bin/env php
2
+<?php
3
+
4
+define('LARAVEL_START', microtime(true));
5
+
6
+/*
7
+|--------------------------------------------------------------------------
8
+| Register The Auto Loader
9
+|--------------------------------------------------------------------------
10
+|
11
+| Composer provides a convenient, automatically generated class loader
12
+| for our application. We just need to utilize it! We'll require it
13
+| into the script here so that we do not have to worry about the
14
+| loading of any our classes "manually". Feels great to relax.
15
+|
16
+*/
17
+
18
+require __DIR__.'/vendor/autoload.php';
19
+
20
+$app = require_once __DIR__.'/bootstrap/app.php';
21
+
22
+/*
23
+|--------------------------------------------------------------------------
24
+| Run The Artisan Application
25
+|--------------------------------------------------------------------------
26
+|
27
+| When we run the console application, the current CLI command will be
28
+| executed in this console and the response sent back to a terminal
29
+| or another output device for the developers. Here goes nothing!
30
+|
31
+*/
32
+
33
+$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
34
+
35
+$status = $kernel->handle(
36
+    $input = new Symfony\Component\Console\Input\ArgvInput,
37
+    new Symfony\Component\Console\Output\ConsoleOutput
38
+);
39
+
40
+/*
41
+|--------------------------------------------------------------------------
42
+| Shutdown The Application
43
+|--------------------------------------------------------------------------
44
+|
45
+| Once Artisan has finished running, we will fire off the shutdown events
46
+| so that any final work may be done by the application before we shut
47
+| down the process. This is the last thing to happen to the request.
48
+|
49
+*/
50
+
51
+$kernel->terminate($input, $status);
52
+
53
+exit($status);

+ 55
- 0
bootstrap/app.php Dosyayı Görüntüle

@@ -0,0 +1,55 @@
1
+<?php
2
+
3
+/*
4
+|--------------------------------------------------------------------------
5
+| Create The Application
6
+|--------------------------------------------------------------------------
7
+|
8
+| The first thing we will do is create a new Laravel application instance
9
+| which serves as the "glue" for all the components of Laravel, and is
10
+| the IoC container for the system binding all of the various parts.
11
+|
12
+*/
13
+
14
+$app = new Illuminate\Foundation\Application(
15
+    $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
16
+);
17
+
18
+/*
19
+|--------------------------------------------------------------------------
20
+| Bind Important Interfaces
21
+|--------------------------------------------------------------------------
22
+|
23
+| Next, we need to bind some important interfaces into the container so
24
+| we will be able to resolve them when needed. The kernels serve the
25
+| incoming requests to this application from both the web and CLI.
26
+|
27
+*/
28
+
29
+$app->singleton(
30
+    Illuminate\Contracts\Http\Kernel::class,
31
+    App\Http\Kernel::class
32
+);
33
+
34
+$app->singleton(
35
+    Illuminate\Contracts\Console\Kernel::class,
36
+    App\Console\Kernel::class
37
+);
38
+
39
+$app->singleton(
40
+    Illuminate\Contracts\Debug\ExceptionHandler::class,
41
+    App\Exceptions\Handler::class
42
+);
43
+
44
+/*
45
+|--------------------------------------------------------------------------
46
+| Return The Application
47
+|--------------------------------------------------------------------------
48
+|
49
+| This script returns the application instance. The instance is given to
50
+| the calling script so we can separate the building of the instances
51
+| from the actual running of the application and sending responses.
52
+|
53
+*/
54
+
55
+return $app;

+ 2
- 0
bootstrap/cache/.gitignore Dosyayı Görüntüle

@@ -0,0 +1,2 @@
1
+*
2
+!.gitignore

+ 74
- 0
composer.json Dosyayı Görüntüle

@@ -0,0 +1,74 @@
1
+{
2
+    "name": "laravel/laravel",
3
+    "type": "project",
4
+    "description": "The Laravel Framework.",
5
+    "keywords": [
6
+        "framework",
7
+        "laravel"
8
+    ],
9
+    "license": "MIT",
10
+    "require": {
11
+        "php": "^7.2.5",
12
+        "barryvdh/laravel-dompdf": "^0.8.6",
13
+        "doctrine/dbal": "^2.10",
14
+        "fideloper/proxy": "^4.2",
15
+        "fruitcake/laravel-cors": "^1.0",
16
+        "guzzlehttp/guzzle": "^6.3",
17
+        "intervention/image": "^2.5",
18
+        "laravel/framework": "^7.0",
19
+        "laravel/tinker": "^2.0",
20
+        "laravel/ui": "^2.0",
21
+        "maatwebsite/excel": "^3.1",
22
+        "mavinoo/laravel-batch": "^2.1",
23
+        "milon/barcode": "^7.0",
24
+        "realrashid/sweet-alert": "^3.1",
25
+        "spatie/laravel-permission": "^3.11",
26
+        "vinkla/hashids": "^8.1",
27
+        "yajra/laravel-datatables": "^1.5"
28
+    },
29
+    "require-dev": {
30
+        "facade/ignition": "^2.0",
31
+        "fzaninotto/faker": "^1.9.1",
32
+        "mockery/mockery": "^1.3.1",
33
+        "nunomaduro/collision": "^4.1",
34
+        "phpunit/phpunit": "^8.5"
35
+    },
36
+    "config": {
37
+        "optimize-autoloader": true,
38
+        "preferred-install": "dist",
39
+        "sort-packages": true
40
+    },
41
+    "extra": {
42
+        "laravel": {
43
+            "dont-discover": []
44
+        }
45
+    },
46
+    "autoload": {
47
+        "psr-4": {
48
+            "App\\": "app/"
49
+        },
50
+        "classmap": [
51
+            "database/seeds",
52
+            "database/factories"
53
+        ]
54
+    },
55
+    "autoload-dev": {
56
+        "psr-4": {
57
+            "Tests\\": "tests/"
58
+        }
59
+    },
60
+    "minimum-stability": "dev",
61
+    "prefer-stable": true,
62
+    "scripts": {
63
+        "post-autoload-dump": [
64
+            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
65
+            "@php artisan package:discover --ansi"
66
+        ],
67
+        "post-root-package-install": [
68
+            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
69
+        ],
70
+        "post-create-project-cmd": [
71
+            "@php artisan key:generate --ansi"
72
+        ]
73
+    }
74
+}

+ 280
- 0
config/app.php Dosyayı Görüntüle

@@ -0,0 +1,280 @@
1
+<?php
2
+
3
+return [
4
+
5
+    /*
6
+    |--------------------------------------------------------------------------
7
+    | Application Name
8
+    |--------------------------------------------------------------------------
9
+    |
10
+    | This value is the name of your application. This value is used when the
11
+    | framework needs to place the application's name in a notification or
12
+    | any other location as required by the application or its packages.
13
+    |
14
+    */
15
+
16
+    'name' => env('APP_NAME', 'Raharja'),
17
+
18
+    /*
19
+    |-------------------------------------------
20
+    | Current API Version
21
+    |-------------------------------------------
22
+    | That is the default API version of your API (Last version).
23
+    | The idea is that if there is no version when calling the API, it  | will be used this one.
24
+    */
25
+    'api_latest'  => '1',
26
+
27
+    /*
28
+    |--------------------------------------------------------------------------
29
+    | Application Environment
30
+    |--------------------------------------------------------------------------
31
+    |
32
+    | This value determines the "environment" your application is currently
33
+    | running in. This may determine how you prefer to configure various
34
+    | services the application utilizes. Set this in your ".env" file.
35
+    |
36
+    */
37
+
38
+    'env' => env('APP_ENV', 'production'),
39
+    'APP_ID_SA' => env('APP_ID_SA', '1'),
40
+    'APP_URL_SIDONI' => env('APP_URL_SIDONI', 'http://dev-rs-admin.sidoni.xyz'),
41
+
42
+    /*
43
+    |--------------------------------------------------------------------------
44
+    | Application Debug Mode
45
+    |--------------------------------------------------------------------------
46
+    |
47
+    | When your application is in debug mode, detailed error messages with
48
+    | stack traces will be shown on every error that occurs within your
49
+    | application. If disabled, a simple generic error page is shown.
50
+    |
51
+    */
52
+
53
+    'debug' => env('APP_DEBUG', false),
54
+
55
+    /*
56
+    |--------------------------------------------------------------------------
57
+    | Application URL
58
+    |--------------------------------------------------------------------------
59
+    |
60
+    | This URL is used by the console to properly generate URLs when using
61
+    | the Artisan command line tool. You should set this to the root of
62
+    | your application so that it is used when running Artisan tasks.
63
+    |
64
+    */
65
+
66
+    'url' => env('APP_URL', 'http://localhost'),
67
+
68
+    'asset_url' => env('ASSET_URL', null),
69
+
70
+    /*
71
+    |--------------------------------------------------------------------------
72
+    | Application Timezone
73
+    |--------------------------------------------------------------------------
74
+    |
75
+    | Here you may specify the default timezone for your application, which
76
+    | will be used by the PHP date and date-time functions. We have gone
77
+    | ahead and set this to a sensible default for you out of the box.
78
+    |
79
+    */
80
+
81
+    'timezone' => 'Asia/Jakarta',
82
+
83
+    /*
84
+    |--------------------------------------------------------------------------
85
+    | Application Locale Configuration
86
+    |--------------------------------------------------------------------------
87
+    |
88
+    | The application locale determines the default locale that will be used
89
+    | by the translation service provider. You are free to set this value
90
+    | to any of the locales which will be supported by the application.
91
+    |
92
+    */
93
+
94
+    'locale' => 'id',
95
+
96
+    /*
97
+    |--------------------------------------------------------------------------
98
+    | Application Fallback Locale
99
+    |--------------------------------------------------------------------------
100
+    |
101
+    | The fallback locale determines the locale to use when the current one
102
+    | is not available. You may change the value to correspond to any of
103
+    | the language folders that are provided through your application.
104
+    |
105
+    */
106
+
107
+    'fallback_locale' => 'en',
108
+
109
+    /*
110
+    |--------------------------------------------------------------------------
111
+    | Faker Locale
112
+    |--------------------------------------------------------------------------
113
+    |
114
+    | This locale will be used by the Faker PHP library when generating fake
115
+    | data for your database seeds. For example, this will be used to get
116
+    | localized telephone numbers, street address information and more.
117
+    |
118
+    */
119
+
120
+    'faker_locale' => 'id_ID',
121
+
122
+    /*
123
+    |--------------------------------------------------------------------------
124
+    | Encryption Key
125
+    |--------------------------------------------------------------------------
126
+    |
127
+    | This key is used by the Illuminate encrypter service and should be set
128
+    | to a random, 32 character string, otherwise these encrypted strings
129
+    | will not be safe. Please do this before deploying an application!
130
+    |
131
+    */
132
+
133
+    'key' => env('APP_KEY'),
134
+
135
+    'cipher' => 'AES-256-CBC',
136
+
137
+    /*
138
+    |--------------------------------------------------------------------------
139
+    | Autoloaded Service Providers
140
+    |--------------------------------------------------------------------------
141
+    |
142
+    | The service providers listed here will be automatically loaded on the
143
+    | request to your application. Feel free to add your own services to
144
+    | this array to grant expanded functionality to your applications.
145
+    |
146
+    */
147
+
148
+    'providers' => [
149
+
150
+        /*
151
+         * Laravel Framework Service Providers...
152
+         */
153
+        Illuminate\Auth\AuthServiceProvider::class,
154
+        Illuminate\Broadcasting\BroadcastServiceProvider::class,
155
+        Illuminate\Bus\BusServiceProvider::class,
156
+        Illuminate\Cache\CacheServiceProvider::class,
157
+        Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
158
+        Illuminate\Cookie\CookieServiceProvider::class,
159
+        Illuminate\Database\DatabaseServiceProvider::class,
160
+        Illuminate\Encryption\EncryptionServiceProvider::class,
161
+        Illuminate\Filesystem\FilesystemServiceProvider::class,
162
+        Illuminate\Foundation\Providers\FoundationServiceProvider::class,
163
+        Illuminate\Hashing\HashServiceProvider::class,
164
+        Illuminate\Mail\MailServiceProvider::class,
165
+        Illuminate\Notifications\NotificationServiceProvider::class,
166
+        Illuminate\Pagination\PaginationServiceProvider::class,
167
+        Illuminate\Pipeline\PipelineServiceProvider::class,
168
+        Illuminate\Queue\QueueServiceProvider::class,
169
+        Illuminate\Redis\RedisServiceProvider::class,
170
+        Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
171
+        Illuminate\Session\SessionServiceProvider::class,
172
+        Illuminate\Translation\TranslationServiceProvider::class,
173
+        Illuminate\Validation\ValidationServiceProvider::class,
174
+        Illuminate\View\ViewServiceProvider::class,
175
+
176
+        /*
177
+         * Maat Excel
178
+         */
179
+        Maatwebsite\Excel\ExcelServiceProvider::class,
180
+
181
+        /*
182
+         * Package Service Providers...
183
+         */
184
+        Barryvdh\DomPDF\ServiceProvider::class,
185
+
186
+        /*
187
+         * Application Service Providers...
188
+         */
189
+        App\Providers\AppServiceProvider::class,
190
+        App\Providers\AuthServiceProvider::class,
191
+        // App\Providers\BroadcastServiceProvider::class,
192
+        App\Providers\EventServiceProvider::class,
193
+        App\Providers\RouteServiceProvider::class,
194
+
195
+        /**
196
+         * spatie
197
+         */
198
+        Spatie\Permission\PermissionServiceProvider::class,
199
+        /**alert */
200
+        RealRashid\SweetAlert\SweetAlertServiceProvider::class,
201
+        /**image */
202
+        'Intervention\Image\ImageServiceProvider',
203
+
204
+        /** Barcode */
205
+        Milon\Barcode\BarcodeServiceProvider::class,
206
+
207
+        /** Batch */
208
+        // Mavinoo\Batch\BatchServiceProvider::class,
209
+    ],
210
+
211
+    /*
212
+    |--------------------------------------------------------------------------
213
+    | Class Aliases
214
+    |--------------------------------------------------------------------------
215
+    |
216
+    | This array of class aliases will be registered when this application
217
+    | is started. However, feel free to register as many as you wish as
218
+    | the aliases are "lazy" loaded so they don't hinder performance.
219
+    |
220
+    */
221
+
222
+    'aliases' => [
223
+
224
+        'App' => Illuminate\Support\Facades\App::class,
225
+        'Arr' => Illuminate\Support\Arr::class,
226
+        'Artisan' => Illuminate\Support\Facades\Artisan::class,
227
+        'Auth' => Illuminate\Support\Facades\Auth::class,
228
+        'Blade' => Illuminate\Support\Facades\Blade::class,
229
+        'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
230
+        'Bus' => Illuminate\Support\Facades\Bus::class,
231
+        'Cache' => Illuminate\Support\Facades\Cache::class,
232
+        'Config' => Illuminate\Support\Facades\Config::class,
233
+        'Cookie' => Illuminate\Support\Facades\Cookie::class,
234
+        'Crypt' => Illuminate\Support\Facades\Crypt::class,
235
+        'DB' => Illuminate\Support\Facades\DB::class,
236
+        'Eloquent' => Illuminate\Database\Eloquent\Model::class,
237
+        'Event' => Illuminate\Support\Facades\Event::class,
238
+        'File' => Illuminate\Support\Facades\File::class,
239
+        'Gate' => Illuminate\Support\Facades\Gate::class,
240
+        'Hash' => Illuminate\Support\Facades\Hash::class,
241
+        'Http' => Illuminate\Support\Facades\Http::class,
242
+        'Lang' => Illuminate\Support\Facades\Lang::class,
243
+        'Log' => Illuminate\Support\Facades\Log::class,
244
+        'Mail' => Illuminate\Support\Facades\Mail::class,
245
+        'Notification' => Illuminate\Support\Facades\Notification::class,
246
+        'Password' => Illuminate\Support\Facades\Password::class,
247
+        'Queue' => Illuminate\Support\Facades\Queue::class,
248
+        'Redirect' => Illuminate\Support\Facades\Redirect::class,
249
+        'Redis' => Illuminate\Support\Facades\Redis::class,
250
+        'Request' => Illuminate\Support\Facades\Request::class,
251
+        'Response' => Illuminate\Support\Facades\Response::class,
252
+        'Route' => Illuminate\Support\Facades\Route::class,
253
+        'Schema' => Illuminate\Support\Facades\Schema::class,
254
+        'Session' => Illuminate\Support\Facades\Session::class,
255
+        'Storage' => Illuminate\Support\Facades\Storage::class,
256
+        'Str' => Illuminate\Support\Str::class,
257
+        'URL' => Illuminate\Support\Facades\URL::class,
258
+        'Validator' => Illuminate\Support\Facades\Validator::class,
259
+        'View' => Illuminate\Support\Facades\View::class,
260
+        /**Helper */
261
+        'Helper' => App\Helpers\Helper::class,
262
+        /**alert */
263
+        'Alert' => RealRashid\SweetAlert\Facades\Alert::class,
264
+        'Carbon' => 'Carbon\Carbon',
265
+        /**image resize */
266
+        'Image' => 'Intervention\Image\Facades\Image',
267
+        //**PDF */
268
+        'PDF' => Barryvdh\DomPDF\Facade::class,
269
+        //** Barcode */
270
+        'DNS1D' => Milon\Barcode\Facades\DNS1DFacade::class,
271
+        'DNS2D' => Milon\Barcode\Facades\DNS2DFacade::class,
272
+
273
+        //** Maat Excel */
274
+        'Excel' => Maatwebsite\Excel\Facades\Excel::class,
275
+
276
+        /**Batch */
277
+        // 'Batch' => Mavinoo\Batch\BatchFacade::class,
278
+    ],
279
+
280
+];

+ 117
- 0
config/auth.php Dosyayı Görüntüle

@@ -0,0 +1,117 @@
1
+<?php
2
+
3
+return [
4
+
5
+    /*
6
+    |--------------------------------------------------------------------------
7
+    | Authentication Defaults
8
+    |--------------------------------------------------------------------------
9
+    |
10
+    | This option controls the default authentication "guard" and password
11
+    | reset options for your application. You may change these defaults
12
+    | as required, but they're a perfect start for most applications.
13
+    |
14
+    */
15
+
16
+    'defaults' => [
17
+        'guard' => 'web',
18
+        'passwords' => 'users',
19
+    ],
20
+
21
+    /*
22
+    |--------------------------------------------------------------------------
23
+    | Authentication Guards
24
+    |--------------------------------------------------------------------------
25
+    |
26
+    | Next, you may define every authentication guard for your application.
27
+    | Of course, a great default configuration has been defined for you
28
+    | here which uses session storage and the Eloquent user provider.
29
+    |
30
+    | All authentication drivers have a user provider. This defines how the
31
+    | users are actually retrieved out of your database or other storage
32
+    | mechanisms used by this application to persist your user's data.
33
+    |
34
+    | Supported: "session", "token"
35
+    |
36
+    */
37
+
38
+    'guards' => [
39
+        'web' => [
40
+            'driver' => 'session',
41
+            'provider' => 'users',
42
+        ],
43
+
44
+        'api' => [
45
+            'driver' => 'token',
46
+            'provider' => 'users',
47
+            'hash' => false,
48
+        ],
49
+    ],
50
+
51
+    /*
52
+    |--------------------------------------------------------------------------
53
+    | User Providers
54
+    |--------------------------------------------------------------------------
55
+    |
56
+    | All authentication drivers have a user provider. This defines how the
57
+    | users are actually retrieved out of your database or other storage
58
+    | mechanisms used by this application to persist your user's data.
59
+    |
60
+    | If you have multiple user tables or models you may configure multiple
61
+    | sources which represent each model / table. These sources may then
62
+    | be assigned to any extra authentication guards you have defined.
63
+    |
64
+    | Supported: "database", "eloquent"
65
+    |
66
+    */
67
+
68
+    'providers' => [
69
+        'users' => [
70
+            'driver' => 'eloquent',
71
+            'model' => App\User::class,
72
+        ],
73
+
74
+        // 'users' => [
75
+        //     'driver' => 'database',
76
+        //     'table' => 'users',
77
+        // ],
78
+    ],
79
+
80
+    /*
81
+    |--------------------------------------------------------------------------
82
+    | Resetting Passwords
83
+    |--------------------------------------------------------------------------
84
+    |
85
+    | You may specify multiple password reset configurations if you have more
86
+    | than one user table or model in the application and you want to have
87
+    | separate password reset settings based on the specific user types.
88
+    |
89
+    | The expire time is the number of minutes that the reset token should be
90
+    | considered valid. This security feature keeps tokens short-lived so
91
+    | they have less time to be guessed. You may change this as needed.
92
+    |
93
+    */
94
+
95
+    'passwords' => [
96
+        'users' => [
97
+            'provider' => 'users',
98
+            'table' => 'password_resets',
99
+            'expire' => 60,
100
+            'throttle' => 60,
101
+        ],
102
+    ],
103
+
104
+    /*
105
+    |--------------------------------------------------------------------------
106
+    | Password Confirmation Timeout
107
+    |--------------------------------------------------------------------------
108
+    |
109
+    | Here you may define the amount of seconds before a password confirmation
110
+    | times out and the user is prompted to re-enter their password via the
111
+    | confirmation screen. By default, the timeout lasts for three hours.
112
+    |
113
+    */
114
+
115
+    'password_timeout' => 10800,
116
+
117
+];

+ 59
- 0
config/broadcasting.php Dosyayı Görüntüle

@@ -0,0 +1,59 @@
1
+<?php
2
+
3
+return [
4
+
5
+    /*
6
+    |--------------------------------------------------------------------------
7
+    | Default Broadcaster
8
+    |--------------------------------------------------------------------------
9
+    |
10
+    | This option controls the default broadcaster that will be used by the
11
+    | framework when an event needs to be broadcast. You may set this to
12
+    | any of the connections defined in the "connections" array below.
13
+    |
14
+    | Supported: "pusher", "redis", "log", "null"
15
+    |
16
+    */
17
+
18
+    'default' => env('BROADCAST_DRIVER', 'null'),
19
+
20
+    /*
21
+    |--------------------------------------------------------------------------
22
+    | Broadcast Connections
23
+    |--------------------------------------------------------------------------
24
+    |
25
+    | Here you may define all of the broadcast connections that will be used
26
+    | to broadcast events to other systems or over websockets. Samples of
27
+    | each available type of connection are provided inside this array.
28
+    |
29
+    */
30
+
31
+    'connections' => [
32
+
33
+        'pusher' => [
34
+            'driver' => 'pusher',
35
+            'key' => env('PUSHER_APP_KEY'),
36
+            'secret' => env('PUSHER_APP_SECRET'),
37
+            'app_id' => env('PUSHER_APP_ID'),
38
+            'options' => [
39
+                'cluster' => env('PUSHER_APP_CLUSTER'),
40
+                'useTLS' => true,
41
+            ],
42
+        ],
43
+
44
+        'redis' => [
45
+            'driver' => 'redis',
46
+            'connection' => 'default',
47
+        ],
48
+
49
+        'log' => [
50
+            'driver' => 'log',
51
+        ],
52
+
53
+        'null' => [
54
+            'driver' => 'null',
55
+        ],
56
+
57
+    ],
58
+
59
+];

+ 103
- 0
config/cache.php Dosyayı Görüntüle

@@ -0,0 +1,103 @@
1
+<?php
2
+
3
+use Illuminate\Support\Str;
4
+
5
+return [
6
+
7
+    /*
8
+    |--------------------------------------------------------------------------
9
+    | Default Cache Store
10
+    |--------------------------------------------------------------------------
11
+    |
12
+    | This option controls the default cache connection that gets used while
13
+    | using this caching library. This connection is used when another is
14
+    | not explicitly specified when executing a given caching function.
15
+    |
16
+    | Supported: "apc", "array", "database", "file",
17
+    |            "memcached", "redis", "dynamodb"
18
+    |
19
+    */
20
+
21
+    'default' => env('CACHE_DRIVER', 'file'),
22
+
23
+    /*
24
+    |--------------------------------------------------------------------------
25
+    | Cache Stores
26
+    |--------------------------------------------------------------------------
27
+    |
28
+    | Here you may define all of the cache "stores" for your application as
29
+    | well as their drivers. You may even define multiple stores for the
30
+    | same cache driver to group types of items stored in your caches.
31
+    |
32
+    */
33
+
34
+    'stores' => [
35
+
36
+        'apc' => [
37
+            'driver' => 'apc',
38
+        ],
39
+
40
+        'array' => [
41
+            'driver' => 'array',
42
+        ],
43
+
44
+        'database' => [
45
+            'driver' => 'database',
46
+            'table' => 'cache',
47
+            'connection' => null,
48
+        ],
49
+
50
+        'file' => [
51
+            'driver' => 'file',
52
+            'path' => storage_path('framework/cache/data'),
53
+        ],
54
+
55
+        'memcached' => [
56
+            'driver' => 'memcached',
57
+            'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
58
+            'sasl' => [
59
+                env('MEMCACHED_USERNAME'),
60
+                env('MEMCACHED_PASSWORD'),
61
+            ],
62
+            'options' => [
63
+                // Memcached::OPT_CONNECT_TIMEOUT => 2000,
64
+            ],
65
+            'servers' => [
66
+                [
67
+                    'host' => env('MEMCACHED_HOST', '127.0.0.1'),
68
+                    'port' => env('MEMCACHED_PORT', 11211),
69
+                    'weight' => 100,
70
+                ],
71
+            ],
72
+        ],
73
+
74
+        'redis' => [
75
+            'driver' => 'redis',
76
+            'connection' => 'cache',
77
+        ],
78
+
79
+        'dynamodb' => [
80
+            'driver' => 'dynamodb',
81
+            'key' => env('AWS_ACCESS_KEY_ID'),
82
+            'secret' => env('AWS_SECRET_ACCESS_KEY'),
83
+            'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
84
+            'table' => env('DYNAMODB_CACHE_TABLE', 'cache'),
85
+            'endpoint' => env('DYNAMODB_ENDPOINT'),
86
+        ],
87
+
88
+    ],
89
+
90
+    /*
91
+    |--------------------------------------------------------------------------
92
+    | Cache Key Prefix
93
+    |--------------------------------------------------------------------------
94
+    |
95
+    | When utilizing a RAM based store such as APC or Memcached, there might
96
+    | be other applications utilizing the same cache. So, we'll specify a
97
+    | value to get prefixed to all our keys so we can avoid collisions.
98
+    |
99
+    */
100
+
101
+    'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'),
102
+
103
+];

+ 34
- 0
config/cors.php Dosyayı Görüntüle

@@ -0,0 +1,34 @@
1
+<?php
2
+
3
+return [
4
+
5
+    /*
6
+    |--------------------------------------------------------------------------
7
+    | Cross-Origin Resource Sharing (CORS) Configuration
8
+    |--------------------------------------------------------------------------
9
+    |
10
+    | Here you may configure your settings for cross-origin resource sharing
11
+    | or "CORS". This determines what cross-origin operations may execute
12
+    | in web browsers. You are free to adjust these settings as needed.
13
+    |
14
+    | To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
15
+    |
16
+    */
17
+
18
+    'paths' => ['api/*'],
19
+
20
+    'allowed_methods' => ['*'],
21
+
22
+    'allowed_origins' => ['*'],
23
+
24
+    'allowed_origins_patterns' => [],
25
+
26
+    'allowed_headers' => ['*'],
27
+
28
+    'exposed_headers' => false,
29
+
30
+    'max_age' => false,
31
+
32
+    'supports_credentials' => false,
33
+
34
+];

+ 147
- 0
config/database.php Dosyayı Görüntüle

@@ -0,0 +1,147 @@
1
+<?php
2
+
3
+use Illuminate\Support\Str;
4
+
5
+return [
6
+
7
+    /*
8
+    |--------------------------------------------------------------------------
9
+    | Default Database Connection Name
10
+    |--------------------------------------------------------------------------
11
+    |
12
+    | Here you may specify which of the database connections below you wish
13
+    | to use as your default connection for all database work. Of course
14
+    | you may use many connections at once using the Database library.
15
+    |
16
+    */
17
+
18
+    'default' => env('DB_CONNECTION', 'mysql'),
19
+
20
+    /*
21
+    |--------------------------------------------------------------------------
22
+    | Database Connections
23
+    |--------------------------------------------------------------------------
24
+    |
25
+    | Here are each of the database connections setup for your application.
26
+    | Of course, examples of configuring each database platform that is
27
+    | supported by Laravel is shown below to make development simple.
28
+    |
29
+    |
30
+    | All database work in Laravel is done through the PHP PDO facilities
31
+    | so make sure you have the driver for your particular database of
32
+    | choice installed on your machine before you begin development.
33
+    |
34
+    */
35
+
36
+    'connections' => [
37
+
38
+        'sqlite' => [
39
+            'driver' => 'sqlite',
40
+            'url' => env('DATABASE_URL'),
41
+            'database' => env('DB_DATABASE', database_path('database.sqlite')),
42
+            'prefix' => '',
43
+            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
44
+        ],
45
+
46
+        'mysql' => [
47
+            'driver' => 'mysql',
48
+            'url' => env('DATABASE_URL'),
49
+            'host' => env('DB_HOST', '127.0.0.1'),
50
+            'port' => env('DB_PORT', '3306'),
51
+            'database' => env('DB_DATABASE', 'forge'),
52
+            'username' => env('DB_USERNAME', 'forge'),
53
+            'password' => env('DB_PASSWORD', ''),
54
+            'unix_socket' => env('DB_SOCKET', ''),
55
+            'charset' => 'utf8mb4',
56
+            'collation' => 'utf8mb4_unicode_ci',
57
+            'prefix' => '',
58
+            'prefix_indexes' => true,
59
+            'strict' => false, //default true
60
+            'engine' => null,
61
+            'options' => extension_loaded('pdo_mysql') ? array_filter([
62
+                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
63
+            ]) : [],
64
+        ],
65
+
66
+        'pgsql' => [
67
+            'driver' => 'pgsql',
68
+            'url' => env('DATABASE_URL'),
69
+            'host' => env('DB_HOST', '127.0.0.1'),
70
+            'port' => env('DB_PORT', '5432'),
71
+            'database' => env('DB_DATABASE', 'forge'),
72
+            'username' => env('DB_USERNAME', 'forge'),
73
+            'password' => env('DB_PASSWORD', ''),
74
+            'charset' => 'utf8',
75
+            'prefix' => '',
76
+            'prefix_indexes' => true,
77
+            'schema' => 'public',
78
+            'sslmode' => 'prefer',
79
+        ],
80
+
81
+        'sqlsrv' => [
82
+            'driver' => 'sqlsrv',
83
+            'url' => env('DATABASE_URL'),
84
+            'host' => env('DB_HOST', 'localhost'),
85
+            'port' => env('DB_PORT', '1433'),
86
+            'database' => env('DB_DATABASE', 'forge'),
87
+            'username' => env('DB_USERNAME', 'forge'),
88
+            'password' => env('DB_PASSWORD', ''),
89
+            'charset' => 'utf8',
90
+            'prefix' => '',
91
+            'prefix_indexes' => true,
92
+        ],
93
+
94
+    ],
95
+
96
+    /*
97
+    |--------------------------------------------------------------------------
98
+    | Migration Repository Table
99
+    |--------------------------------------------------------------------------
100
+    |
101
+    | This table keeps track of all the migrations that have already run for
102
+    | your application. Using this information, we can determine which of
103
+    | the migrations on disk haven't actually been run in the database.
104
+    |
105
+    */
106
+
107
+    'migrations' => 'migrations',
108
+
109
+    /*
110
+    |--------------------------------------------------------------------------
111
+    | Redis Databases
112
+    |--------------------------------------------------------------------------
113
+    |
114
+    | Redis is an open source, fast, and advanced key-value store that also
115
+    | provides a richer body of commands than a typical key-value system
116
+    | such as APC or Memcached. Laravel makes it easy to dig right in.
117
+    |
118
+    */
119
+
120
+    'redis' => [
121
+
122
+        'client' => env('REDIS_CLIENT', 'phpredis'),
123
+
124
+        'options' => [
125
+            'cluster' => env('REDIS_CLUSTER', 'redis'),
126
+            'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_') . '_database_'),
127
+        ],
128
+
129
+        'default' => [
130
+            'url' => env('REDIS_URL'),
131
+            'host' => env('REDIS_HOST', '127.0.0.1'),
132
+            'password' => env('REDIS_PASSWORD', null),
133
+            'port' => env('REDIS_PORT', '6379'),
134
+            'database' => env('REDIS_DB', '0'),
135
+        ],
136
+
137
+        'cache' => [
138
+            'url' => env('REDIS_URL'),
139
+            'host' => env('REDIS_HOST', '127.0.0.1'),
140
+            'password' => env('REDIS_PASSWORD', null),
141
+            'port' => env('REDIS_PORT', '6379'),
142
+            'database' => env('REDIS_CACHE_DB', '1'),
143
+        ],
144
+
145
+    ],
146
+
147
+];

+ 0
- 0
config/datatables.php Dosyayı Görüntüle


Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor

Loading…
İptal
Kaydet