0

Hi i am trying to show all count for left sidebar menu but unfortunately i am getting error class not found Class 'app/Http/Helpers/Helpers.php' not found please help me how can id do that thanks.

app/Http/Helpers/Helpers.php

function NotificationCount()
{
    return Example::where('status', 1)->where( 'created_at', '>', Carbon::now()->subDays(3))->latest()->count();
}

leftsidebar

@php
  
$className = 'app/Http/Helpers/Helpers.php';

 $count  = new $className();
  
  return $count->NotificationCount();

@endphp
1
  • 1
    without .php, $className = 'app\Http\Helpers\Helpers'; Commented Mar 22, 2021 at 7:52

2 Answers 2

1

Best Practices for custom helpers in Laravel.

Create a helpers.php file in your app folder and load it up with composer:

"autoload": {
    "classmap": [
        ...
    ],
    "psr-4": {
        "App\\": "app/"
    },
    "files": [
        "app/helpers.php" // <---- ADD THIS
    ]
},

After adding that to your composer.json file, run the following command:

composer dump-autoload

add your function

function propertyNotificationCount()
{
    return Property::where('status', 1)->where( 'created_at', '>', Carbon::now()->subDays(3))->latest()->count();
}

in helper.php file

Now in any blade file you can call propertyNotificationCount() this function.

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

2 Comments

sir i have already done it this steps but unfortunately getting same error.
If you have already done it, you don't need to use that class. simply {{ NotificationCount() }} call in blade, that's it!
0

As far as I know, it's not really a good practice to use @php @endphp inside blade templates.

I would probably consider another approach and try to return the notification count from the controller somehow and inside php you could handle more easily the class not found error ( maybe just declare it with use at the begging of the controller and you can use it afterwards )

Comments

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.