totothegreat
totothegreat

Reputation: 1643

define constants paths in laravel

I'm trying to this in laravel app folder:

define('PP_CONFIG_PATH', /paypal/sdk_config.ini);

The source of this is a file i created next to routes.php and filters.php and i named it constants.php.

in the laravel app folder i have a folder named paypal and inside it i have the sdk_config,

i recieve this all the time:

Use of undefined constant paypal - assumed 'paypal'
Open: C:\wamp\www\misterSurvey\app\constants.php
<?php
    define('PP_CONFIG_PATH',/paypal/sdk_config.ini);
?>

Upvotes: 0

Views: 2561

Answers (3)

Khang Doan
Khang Doan

Reputation: 436

<?php
//file : app/config/constants.php

return [
    'PP_CONFIG_PATH' => '/paypal/sdk_config.ini'
];

in anywhere:

echo Config::get('constants.PP_CONFIG_PATH');

Upvotes: 1

Matt Burrow
Matt Burrow

Reputation: 11097

Encapsulate the string within ' or " otherwise it will try looking for constants, and you will get a Use of undefined constant error. Like so;

define('PP_CONFIG_PATH','/paypal/sdk_config.ini');

Note: This is an error within the documentation.

Upvotes: 1

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111899

You need to always put strings into quotes (single or double depending on need) otherwise you will get errors Use of undefined constant.

For example:

$x = aaa;

you will also get this error because there are no quotes before and after aaa so the correct usage is:

$x = 'aaa';

The same is in your case. It should be:

define('PP_CONFIG_PATH', '/paypal/sdk_config.ini');

It seems there is error in documentation at https://github.com/paypal/rest-api-sdk-php - quotes should be there or it's rather some pseudo path so author didn't add quotes because it's obvious.

Upvotes: 1

Related Questions