MyServiceProvider.php 1.09 KB
<?php

namespace App\Providers;

use App\Models\Job_title;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;

class MyServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        $views = ['admin.job_titles.parent_id'];
        View::composer($views,
            function($view)
            {
                static $items = null;

                if (is_null($items)) {
                    $items = Job_title::query()->
                                        orderByDesc('sort')->
                                        orderBy('name')->
                                        active()->
                                        get();
                    $parent = 0;
                    $view->with(['items' => $items, 'parent' => $parent]);
                } else {
                    $view->with(['items' => $items]);
                }

            }
        );
    }
}