AppServiceProvider.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Providers;
  3. use Illuminate\Support\Facades\Blade;
  4. use Illuminate\Support\Facades\Log;
  5. use Illuminate\Support\ServiceProvider;
  6. class AppServiceProvider extends ServiceProvider
  7. {
  8. /**
  9. * Register any application services.
  10. *
  11. * @return void
  12. */
  13. public function register()
  14. {
  15. //
  16. }
  17. /**
  18. * Bootstrap any application services.
  19. *
  20. * @return void
  21. */
  22. public function boot()
  23. {
  24. //
  25. // Blade::directive('hasAuth', function ($expression) {
  26. /* return "<?php echo ($expression); ?>";*/
  27. // });
  28. $this->registerBladeDirective();
  29. }
  30. protected function registerBladeDirective()
  31. {
  32. Blade::directive('hasAuth', function ($auth) {
  33. return "<?php if(auth()->user()->hasAuth({$auth})): ?>";
  34. });
  35. Blade::directive('endHasAuth', function () {
  36. return '<?php endif; ?>';
  37. });
  38. Blade::directive('notCustomer', function () {
  39. /* return "<?php if(auth()->user()->role_id!=\App\Http\Models\Role::TYPE_CUSTOMER): ?>";*/
  40. return "<?php if(!in_array(auth()->user()->role_id,[\App\Http\Models\Role::TYPE_CUSTOMER,\App\Http\Models\Role::TYPE_TYPE_CUSTOMER_STAFF])): ?>";
  41. });
  42. Blade::directive('endNotCustomer', function () {
  43. return '<?php endif; ?>';
  44. });
  45. // Blade::directive('roleCustomer', function ($bool) {
  46. /* return "<?php if((auth()->user()->role_id==\App\Http\Models\Role::TYPE_CUSTOMER)==={$bool}): ?>";*/
  47. // });
  48. // Blade::directive('endRoleCustomer', function () {
  49. /* return '<?php endif; ?>';*/
  50. // });
  51. // Blade::directive('roleWeb', function ($bool = true) {
  52. /* return "<?php if((auth()->user()->role_id==\App\Http\Models\Role::TYPE_WEB)==={$bool}): ?>";*/
  53. // });
  54. // Blade::directive('endRoleWeb', function () {
  55. /* return '<?php endif; ?>';*/
  56. // });
  57. // Blade::directive('roleAe', function ($bool = true) {
  58. /* return "<?php if((auth()->user()->role_id==\App\Http\Models\Role::TYPE_AE)==={$bool}): ?>";*/
  59. // });
  60. // Blade::directive('endRoleAe', function () {
  61. /* return '<?php endif; ?>';*/
  62. // });
  63. // Blade::if('demo', function ($roleId) {
  64. // return auth()->user()->role_id == $roleId;
  65. // });
  66. }
  67. }