0

I develope a website using laravel under repository pattren and considered a table for storing global data (such as footer notes, address, admin's contact number and etc.) used a table called 'settings' with 'key', 'value' structure but faced with a problem... problem is i confused

how to implement logic for access and update data in settings' table using SettingRepository methods (SettingRepository.php is a repository class for model Setting.php)

like how to retrieving in baldes, ...

source code is written by laravel framework using repository pattern.

hussain
  • 442
  • 4
  • 5
  • Please post the code you're currently working with, and point to the parts you have working, and the parts where you're stuck. This should hopefully provide enough detail for others to fully understand the problem you're dealing with, and try and help. – i336_ Oct 01 '21 at 17:48

1 Answers1

0

Is you want to use in views and controllers you must use this: global variable for all controller and views

Or you can just use Laravel's View Composer https://laravel.com/docs/8.x/views#sharing-data-with-all-views

I am using second method. I have a "frontend" view folder. I use this code:

View::composer('frontend.*', function ($view) {
        $settings = Settings::find(1);
        $header_menu = Menus::where('id', $settings->header_menu)->with('items')->first();
        $footer_menu = Menus::where('id', $settings->footer_menu)->with('items')->first();
        $footer_menu1 = Menus::where('id', $settings->footer_menu1)->with('items')->first();
        $footer_menu2 = Menus::where('id', $settings->footer_menu2)->with('items')->first();
        $footer_menu3 = Menus::where('id', $settings->footer_menu3)->with('items')->first();
        $blog_header_menu = Menus::where('id', $settings->blog_header_menu)->with('items')->first();
        $blog_footer_menu = Menus::where('id', $settings->blog_footer_menu)->with('items')->first();
        
        View::share('header_menu', $header_menu);
        View::share('footer_menu', $footer_menu);
        View::share('footer_menu1', $footer_menu1);
        View::share('footer_menu2', $footer_menu2);
        View::share('footer_menu3', $footer_menu3);
        View::share('blog_header_menu', $blog_header_menu);
        View::share('blog_footer_menu', $blog_footer_menu);
        View::share('header_logo', $settings->logo);
        View::share('footer_logo', $settings->footer_logo);

        View::share('settings', $settings);

    });