Reputation: 1
Laravel 5.6 , model name is not found in helper class (N:B: helper class is located in App\Helpers\Helper.php)
Upvotes: 0
Views: 756
Reputation: 299
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\Models
namespace :
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 :)
Upvotes: 1
Reputation: 1
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 :)
Upvotes: 0
Reputation: 9313
You need to add namespace.
<?php
namespace App\Helpers; // <--- Add this
class Helper{
...
Upvotes: 0