0

Laravel 5.6 , model name is not found in helper class (N:B: helper class is located in App\Helpers\Helper.php)

enter image description here

1
  • 1
    namespace is missing in the code Commented Mar 4, 2018 at 9:58

3 Answers 3

1

The model name is not enough for Laravel to retrieve the right class, it needs the namespace too.

You can try this if all your models are in the App\Modelsnamespace :

public static function getAll($modelName)
{
    $modelName = '\App\Models\' . $modelName;
    return $modelName::all();
}

But if it is not the cas, you should send the whole name to your helper method like that :

Helper::getAll(\App\Models\User::class);
Helper::getAll(\App\Models\Subfolder\OtherModel::class);
// ...

Let me know if it helped you :)

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

Comments

0

You need to add namespace.

<?php

namespace App\Helpers; // <--- Add this

class Helper{
...

Comments

0

try this.
first import the Model namespace like this

use Illuminate\Database\Eloquent\Model;

then, add Model keyword before $model. like

public function getAll(Model $model){ // your code }

may it can help :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.