1

In laravel there are files like app.php or auth.php which contains one array with specific settings. For my application i want to create a file that contains all my query's like the same way in one array and return it. How could i use the file for example app.php in my controller

Example

return [

    /*
    |--------------------------------------------------------------------------
    | Query 1
    |--------------------------------------------------------------------------
    |
    | This is an example of a query 
    |
    */

        'sql_user_by_name' => "SELECT * FROM user WHERE name = 'test'",
]

1 Answer 1

1

If you place it in the config directory you can use this:

Config::get('myfile.myproperty');

So in you're case:

Config::get('app.sql_user_by_name');

You can also use the build in function of Laravel. This works the same:

config('app.sql_user_by_name');

You can look at the docs. Please scroll down to "Accessing Configuration Values".

Sign up to request clarification or add additional context in comments.

8 Comments

Thx, and if i want to use it in another directory?? And where can i find how laravel reads thouse files, so i could learn about it.
You've to look at the source.
For information about different folders this will help you I guess.
Thx for all the information this was exactly what i need. But for my learning curve i would like to know how laraval reads the file. Is it includes somewhere??
It's always good to read the source. Do it yourself github.com/laravel/framework :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.