Call to undefined function, changes on helper.php file but still cant call presentPrice function
in my view file I try to add this code, but cant call the function name 'present price'
<table>
<tr>
<td>RM {{presentPrice(session()->get('coupon')['name'])}}</td>
</tr>
</table>
this function I add it into the app/helper path
<?php
class helpers{
function presentPrice($price)
{
return money_format('$%i', $price / 100);
}
}
of course I have to run composer dump-autoload. But it still show me undefined function
php laravel
add a comment |
in my view file I try to add this code, but cant call the function name 'present price'
<table>
<tr>
<td>RM {{presentPrice(session()->get('coupon')['name'])}}</td>
</tr>
</table>
this function I add it into the app/helper path
<?php
class helpers{
function presentPrice($price)
{
return money_format('$%i', $price / 100);
}
}
of course I have to run composer dump-autoload. But it still show me undefined function
php laravel
Have you defined Helper Class
– Gaurav Rai
Nov 13 '18 at 8:55
may I know where to defined it? Because I think view file can't defined 'use helper' ?
– lun7code
Nov 13 '18 at 8:56
answered please go through it.
– Gaurav Rai
Nov 13 '18 at 9:14
add a comment |
in my view file I try to add this code, but cant call the function name 'present price'
<table>
<tr>
<td>RM {{presentPrice(session()->get('coupon')['name'])}}</td>
</tr>
</table>
this function I add it into the app/helper path
<?php
class helpers{
function presentPrice($price)
{
return money_format('$%i', $price / 100);
}
}
of course I have to run composer dump-autoload. But it still show me undefined function
php laravel
in my view file I try to add this code, but cant call the function name 'present price'
<table>
<tr>
<td>RM {{presentPrice(session()->get('coupon')['name'])}}</td>
</tr>
</table>
this function I add it into the app/helper path
<?php
class helpers{
function presentPrice($price)
{
return money_format('$%i', $price / 100);
}
}
of course I have to run composer dump-autoload. But it still show me undefined function
php laravel
php laravel
asked Nov 13 '18 at 8:51
lun7codelun7code
548
548
Have you defined Helper Class
– Gaurav Rai
Nov 13 '18 at 8:55
may I know where to defined it? Because I think view file can't defined 'use helper' ?
– lun7code
Nov 13 '18 at 8:56
answered please go through it.
– Gaurav Rai
Nov 13 '18 at 9:14
add a comment |
Have you defined Helper Class
– Gaurav Rai
Nov 13 '18 at 8:55
may I know where to defined it? Because I think view file can't defined 'use helper' ?
– lun7code
Nov 13 '18 at 8:56
answered please go through it.
– Gaurav Rai
Nov 13 '18 at 9:14
Have you defined Helper Class
– Gaurav Rai
Nov 13 '18 at 8:55
Have you defined Helper Class
– Gaurav Rai
Nov 13 '18 at 8:55
may I know where to defined it? Because I think view file can't defined 'use helper' ?
– lun7code
Nov 13 '18 at 8:56
may I know where to defined it? Because I think view file can't defined 'use helper' ?
– lun7code
Nov 13 '18 at 8:56
answered please go through it.
– Gaurav Rai
Nov 13 '18 at 9:14
answered please go through it.
– Gaurav Rai
Nov 13 '18 at 9:14
add a comment |
2 Answers
2
active
oldest
votes
You have put it inside a class . If you want to define helper functions you should:
Change your helpers source to:
<?php
function presentPrice($price) {
return money_format('$%i', $price / 100);
}
Then add this to your composer.json
"autoload": {
"files": [
"app/helper.php"
],
keep the rest of the autoload parts as is
}
Then run composer dump-autoload
again. This should make the file app/helper.php
load automatically every time. (If the file is in a different path then update accordingly)
This will make presentPrice()
available everywhere.
add a comment |
Create your Helper file
/app/Helpers/Helper.php
<?php
namespace AppHelpers;
class Helper{
public static function MoneyFormat($number){}
}
/config/app.php
define alias
'Helper' => AppHelpersHelper::class,
/app/Http/Controllers/YourController.php
use Helper;
and use it where ever you want like
Helper::MoneyFormat($price)
it show the error undefined class error when i define alias.
– lun7code
Nov 13 '18 at 9:24
Have you created helper file /app/Helpers/Helper.php updated my answer
– Gaurav Rai
Nov 13 '18 at 9:26
my path is here ---> app/helpers.php
– lun7code
Nov 13 '18 at 9:30
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277094%2fcall-to-undefined-function-changes-on-helper-php-file-but-still-cant-call-prese%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have put it inside a class . If you want to define helper functions you should:
Change your helpers source to:
<?php
function presentPrice($price) {
return money_format('$%i', $price / 100);
}
Then add this to your composer.json
"autoload": {
"files": [
"app/helper.php"
],
keep the rest of the autoload parts as is
}
Then run composer dump-autoload
again. This should make the file app/helper.php
load automatically every time. (If the file is in a different path then update accordingly)
This will make presentPrice()
available everywhere.
add a comment |
You have put it inside a class . If you want to define helper functions you should:
Change your helpers source to:
<?php
function presentPrice($price) {
return money_format('$%i', $price / 100);
}
Then add this to your composer.json
"autoload": {
"files": [
"app/helper.php"
],
keep the rest of the autoload parts as is
}
Then run composer dump-autoload
again. This should make the file app/helper.php
load automatically every time. (If the file is in a different path then update accordingly)
This will make presentPrice()
available everywhere.
add a comment |
You have put it inside a class . If you want to define helper functions you should:
Change your helpers source to:
<?php
function presentPrice($price) {
return money_format('$%i', $price / 100);
}
Then add this to your composer.json
"autoload": {
"files": [
"app/helper.php"
],
keep the rest of the autoload parts as is
}
Then run composer dump-autoload
again. This should make the file app/helper.php
load automatically every time. (If the file is in a different path then update accordingly)
This will make presentPrice()
available everywhere.
You have put it inside a class . If you want to define helper functions you should:
Change your helpers source to:
<?php
function presentPrice($price) {
return money_format('$%i', $price / 100);
}
Then add this to your composer.json
"autoload": {
"files": [
"app/helper.php"
],
keep the rest of the autoload parts as is
}
Then run composer dump-autoload
again. This should make the file app/helper.php
load automatically every time. (If the file is in a different path then update accordingly)
This will make presentPrice()
available everywhere.
answered Nov 13 '18 at 8:57
apokryfosapokryfos
18.3k42956
18.3k42956
add a comment |
add a comment |
Create your Helper file
/app/Helpers/Helper.php
<?php
namespace AppHelpers;
class Helper{
public static function MoneyFormat($number){}
}
/config/app.php
define alias
'Helper' => AppHelpersHelper::class,
/app/Http/Controllers/YourController.php
use Helper;
and use it where ever you want like
Helper::MoneyFormat($price)
it show the error undefined class error when i define alias.
– lun7code
Nov 13 '18 at 9:24
Have you created helper file /app/Helpers/Helper.php updated my answer
– Gaurav Rai
Nov 13 '18 at 9:26
my path is here ---> app/helpers.php
– lun7code
Nov 13 '18 at 9:30
add a comment |
Create your Helper file
/app/Helpers/Helper.php
<?php
namespace AppHelpers;
class Helper{
public static function MoneyFormat($number){}
}
/config/app.php
define alias
'Helper' => AppHelpersHelper::class,
/app/Http/Controllers/YourController.php
use Helper;
and use it where ever you want like
Helper::MoneyFormat($price)
it show the error undefined class error when i define alias.
– lun7code
Nov 13 '18 at 9:24
Have you created helper file /app/Helpers/Helper.php updated my answer
– Gaurav Rai
Nov 13 '18 at 9:26
my path is here ---> app/helpers.php
– lun7code
Nov 13 '18 at 9:30
add a comment |
Create your Helper file
/app/Helpers/Helper.php
<?php
namespace AppHelpers;
class Helper{
public static function MoneyFormat($number){}
}
/config/app.php
define alias
'Helper' => AppHelpersHelper::class,
/app/Http/Controllers/YourController.php
use Helper;
and use it where ever you want like
Helper::MoneyFormat($price)
Create your Helper file
/app/Helpers/Helper.php
<?php
namespace AppHelpers;
class Helper{
public static function MoneyFormat($number){}
}
/config/app.php
define alias
'Helper' => AppHelpersHelper::class,
/app/Http/Controllers/YourController.php
use Helper;
and use it where ever you want like
Helper::MoneyFormat($price)
edited Nov 13 '18 at 9:28
answered Nov 13 '18 at 9:04
Gaurav RaiGaurav Rai
753619
753619
it show the error undefined class error when i define alias.
– lun7code
Nov 13 '18 at 9:24
Have you created helper file /app/Helpers/Helper.php updated my answer
– Gaurav Rai
Nov 13 '18 at 9:26
my path is here ---> app/helpers.php
– lun7code
Nov 13 '18 at 9:30
add a comment |
it show the error undefined class error when i define alias.
– lun7code
Nov 13 '18 at 9:24
Have you created helper file /app/Helpers/Helper.php updated my answer
– Gaurav Rai
Nov 13 '18 at 9:26
my path is here ---> app/helpers.php
– lun7code
Nov 13 '18 at 9:30
it show the error undefined class error when i define alias.
– lun7code
Nov 13 '18 at 9:24
it show the error undefined class error when i define alias.
– lun7code
Nov 13 '18 at 9:24
Have you created helper file /app/Helpers/Helper.php updated my answer
– Gaurav Rai
Nov 13 '18 at 9:26
Have you created helper file /app/Helpers/Helper.php updated my answer
– Gaurav Rai
Nov 13 '18 at 9:26
my path is here ---> app/helpers.php
– lun7code
Nov 13 '18 at 9:30
my path is here ---> app/helpers.php
– lun7code
Nov 13 '18 at 9:30
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277094%2fcall-to-undefined-function-changes-on-helper-php-file-but-still-cant-call-prese%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you defined Helper Class
– Gaurav Rai
Nov 13 '18 at 8:55
may I know where to defined it? Because I think view file can't defined 'use helper' ?
– lun7code
Nov 13 '18 at 8:56
answered please go through it.
– Gaurav Rai
Nov 13 '18 at 9:14