How to dynamically pass the variable name into the model in the laravel provider’s model config.php file

  breeze, laravel, namespaces, php

For instance let’s say the


    $model_name = 'student_table';


'providers' => [

        'users' => [
                '$model_name' => [
                'driver' => 'eloquent',
                'model' => AppModels.$model_name.::class

The problem is that laravel fires an unexpected ‘.’ expecting identified (T_STRING)

And I need to insert the model name dynamically because there lot of database tables to connect with. Any other solution pls

Source: Laravel

Leave a Reply