setAbilitiesModel() public static method

Set the model to be used for abilities.
public static setAbilitiesModel ( string $model ) : void
$model string
return void
Esempio n. 1
0
 /**
  * Set the model to be used for abilities.
  *
  * @param string  $model
  */
 public static function useAbilityModel($model)
 {
     Models::setAbilitiesModel($model);
 }
Esempio n. 2
0
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Models::setRolesModel(Role::class);
        Models::setAbilitiesModel(Ability::class);
        if (app()->environment('production')) {
            // force production url since we're behind a load balancer
            URL::forceSchema('https');
            URL::forceRootUrl(config('app.url'));
            // Use Rollbar for exception handling
            $this->app->register(RollbarServiceProvider::class);
        }
        /*
         * specific library inclusion
         */
        Blade::directive('includeVueJs', function () {
            if (app()->environment('production', 'staging')) {
                return '<?php
                \\' . Html::class . '::$includeJs[] = "https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.10/vue.min.js";
                \\' . Html::class . '::$includeJs[] = "https://cdn.jsdelivr.net/vue.validator/2.0.0-alpha.6/vue-validator.min.js";
                ?>';
            } else {
                return '<?php
                \\' . Html::class . '::$includeJs[] = "/assets/plugins/vuejs/vue-1.0.10.min.js";
                \\' . Html::class . '::$includeJs[] = "/assets/plugins/vuejs/vue-2.0.0-alpha.6-validator.min.js";
                ?>';
            }
        });
        Blade::directive('includeMorris', function () {
            $html = '<?php' . PHP_EOL;
            if (app()->environment('local')) {
                $html .= '\\' . Html::class . '::$includeJs[] .= "/assets/plugins/raphael/raphael-2.1.0-min.js";';
            } else {
                $html .= '\\' . Html::class . '::$includeJs[] .= "https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js";';
            }
            $html .= '
                \\' . Html::class . '::$includeJs[] .= "/assets/plugins/jquery-morris-chart/js/morris.min.js";
                \\' . Html::class . '::$includeCss[] .= "/assets/plugins/jquery-morris-chart/css/morris.css";
                ?>';
            return $html;
        });
        Blade::directive('includeGoogleCharts', function () {
            $html = '<?php' . PHP_EOL;
            if (app()->environment('local')) {
                $html .= '\\' . Html::class . '::$includeJs[] .= "/assets/plugins/google-charts/loader.js";';
            } else {
                $html .= '\\' . Html::class . '::$includeJs[] .= "https://www.gstatic.com/charts/loader.js";';
            }
            return $html . '
                ?>';
        });
        Blade::directive('includeStripeJs', function () {
            return '<?php
                \\' . Html::class . '::$includeJs[] = "https://js.stripe.com/v2/";
                \\' . Html::class . "::\$js .= \"Stripe.setPublishableKey('" . getenv('STRIPE_PUBLIC_KEY') . "');\"\n                ?>";
        });
        Blade::directive('includeRichTextEditor', function () {
            return '<?php
                \\' . Html::class . '::$includeCss[] = "/assets/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.css";
                \\' . Html::class . '::$includeJs[] = "/assets/plugins/bootstrap-wysihtml5/wysihtml5-0.3.0.js";
                \\' . Html::class . '::$includeJs[] = "/assets/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.js";
                ?>';
        });
        Blade::directive('includeDatePicker', function () {
            return '<?php
                \\' . Html::class . '::$includeCss[] = "/assets/plugins/bootstrap-datepicker/css/datepicker.min.css";
                \\' . Html::class . '::$includeJs[] = "/assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js";
                ?>';
        });
        Blade::directive('includeNotifications', function () {
            return '<?php
                \\' . Html::class . '::$includeCss[] = "/css/notifications.css";
                \\' . Html::class . '::$includeJs[] = "/js/notifications.js";
                ?>';
        });
        /*
         * Generic reusable components
         */
        Blade::directive('includeCss', function ($path) {
            if (str_contains($path, 'elixir')) {
                return '<?php \\' . Html::class . '::$includeCss[] = ' . $path . '; ?>';
            }
            return '<?php \\' . Html::class . '::$includeCss[] = "' . $path . '"; ?>';
        });
        Blade::directive('includeJs', function ($path) {
            if (str_contains($path, 'elixir')) {
                return '<?php \\' . Html::class . '::$includeJs[] = ' . $path . '; ?>';
            }
            return '<?php \\' . Html::class . '::$includeJs[] = "' . $path . '"; ?>';
        });
        Blade::directive('js', function () {
            return '<?php ob_start(); ?>';
        });
        Blade::directive('endjs', function () {
            return '<?php \\' . Html::class . '::$js .= ob_get_clean(); ?>';
        });
        Blade::directive('jsData', function () {
            return '<?php ob_start(); ?>';
        });
        Blade::directive('endjsData', function () {
            return '<?php \\' . Html::class . '::$jsData .= ob_get_clean(); ?>';
        });
        Blade::directive('css', function () {
            return '<?php ob_start(); ?>';
        });
        Blade::directive('endcss', function () {
            return '<?php \\' . Html::class . '::$css .= ob_get_clean(); ?>';
        });
        /*
         * Describe a collection as a comma delimited list
         *
         * Usage: @describe(Collection, string, string)
         */
        Blade::directive('describe', function ($params) {
            $params = explode(', ', $params);
            $toDescribe = $params[0];
            $descriptor = $params[1] ?? 'and';
            $attribute = $params[2] ?? 'name';
            return <<<EOF
            <?php 
                \$collection = {$toDescribe};
                \$last = \$collection->pop();
                if (\$collection->count() > 0) {
                    echo \$collection->implode('{$attribute}', ', ').' {$descriptor} '.\$last->{$attribute};
                } else {
                    echo \$last->{$attribute};
                }
             ?>
EOF;
        });
    }