SalmanPatnee's avatar

Helper function to get values from database

I'm implementing theme options in Laravel so, of course i have a settings table in database which have different rows like logo, facebook_url, address, phone_number. What is the best practice to show them in a site ? Make a function in a model and use view composer or make a helper function like WordPress do with get_option function?

0 likes
5 replies
tisuchi's avatar

This how you need to write function in function.php file.

function getValuesFromFunctionFile()
{

    $getResult = App\Model::latest()->get();


    return $getResult;
}

Remember: Its a procedural file. You cannot write class. All just about function.

3 likes
SalmanPatnee's avatar

I have a settings model and a helper functions file in App/Helpers/helper.php.

tisuchi's avatar

I was thinking in a different way. I know its kinda wrong way, however, it will solve your purpose too.

Just write following in your blade code where you want to display your social icons.

<?php
    $socialIcons = App\Model::get();
?>

@foreach($socialIcons as $icon)
    do you html code
@endforeach

Disclaimer: Its not a ideal way, on the other hand, its not a serious offense to write.

4 likes
shez1983's avatar

you could just create a normal SETTINGS entity and have a static function..

Settings::getvalue('facebook_url');.. etc

1 like

Please or to participate in this conversation.