Pol Carlo
Pol Carlo

Reputation: 61

Laravel - How to call model to class Helper then display the result in view

In Laravel how to call model to class helper then display the result to view.

i have an error

Non-static method App\Models\UserTypeHasModule::getModuleList() should not be called statically

Here's my code of that error

use \App\Models\UserTypeHasModule;

class UserRoleHelper
{
    public static function moduleList()
    {
        $generalSettings = UserTypeHasModule::getModuleList(1);

        return $generalSettings;
    }

Upvotes: 0

Views: 582

Answers (1)

nakov
nakov

Reputation: 14278

In your UserTypeHasModule class the getModuleList function is not static and you try to call it statically, instead of making an instance of the class first.

So you can either change your function to:

public static function getModuleList( $id ) { ... } 

Or make an instance of the module first and then call the method:

$generalSettings = (new UserTypeHasModule())->getModuleList(1);

Upvotes: 1

Related Questions