Reputation: 1523
I created an helper and I try to use it in one of my controllers,but I got an error, and I am not sure why.
//StringHelper.php
namespace App\Helpers;
class StringHelper
{
public function example($str1){
//CODE
}
}
//config/app.php
'aliases' => [
'StringHelper' => App\Helpers\StringHelper::class,
]
//In controller
use StringHelper;
$percentage = StringHelper::example($title);
Non-static method App\Helpers\StringHelper::example() should not be called statically
Upvotes: 1
Views: 782
Reputation: 13394
Because the method example($str1)
is not static, you need to call it by instance.
I think you are calling other instance's methods in example
, so the simple way is call the method by instance.
$helper = new StringHelper();
$percentage = $helper->example($title);
Or you need to defined all those methods to static.
Upvotes: 1