Search code examples
phpdatabaseimagelaravelsliders

The best way to edit slider images and links


I have a slider in the index page, which has 3 pictures and this pictures has links. What is the best way to change pictures and links: make db table sliders:

id
pic
link

and work with it, or make in config->settings.php something like this:

<?php
return [
        'new_products_count' => 6,
        'popular_products_count' => 6,
        'paginate' => 20,
        'admin_paginate' => 10,
        'slider'=>[
                   1=>['img'=>'1.jpg','link'=>'www1'],
                   2=>['img'=>'2.jpg','link'=>'www2'],
                   3=>['img'=>'3.jpg','link'=>'www3']
                   ]
       ]; 

and work with it like this:

Config::set('settings.slider[1]['img']=>'newimg.jpg')
Config::set('settings.slider[1]['link']=>'newWWW')

?


Solution

  • Would be safer to keep in the database for a couple of reasons.

    1- If you cache your configuration, it may sometimes behave like a buggy application. I mean after changing an image and coming back, you may see the previous image displaying again. Because what you change at runtime is not persisted. Try to update a config option, e.g:

    config(['database.connections.sqlite.driver' => 'fake']);
    

    Then go check the file. tadaaa... the file didn't change.

    2- You database is unlimited. YOu can add an infinite number of images (links) with much more options. Of course, you can also pass options to config() but using Eloquent or Query builder is more flexible.