使用动态数组在laravel中传递模型类名称

时间:2018-04-23 09:58:13

标签: php laravel models

我有一个数组($ models),其中包含我的模态类的名称:

<?php

namespace App\Http\Controllers\systemActions;

use Storage;
use App\Accident;
use App\Company;
use App\Driver;
use App\Employee;
use App\Expert;
use App\InputTransaction;
use App\Notification;
use App\Receipt;
use App\Person;
use App\Transaction;
use App\Group;
use App\User;
use App\Permission;
use App\Witness;
use App\Companynote;
use App\RejectedReceipt;
use App\DataEntryNote;
use App\Task;
use App\Setting;
use App\RealEstate;
use App\Oldreportpayment;
use App\Freelancerdataentryaccident;
use App\UserFlow;
use App\Page;
use App\Log;
use App\Damagedetection;
use App\Datarequest;
use App\Eperson;
use App\Edriver;
use App\Eaccident;
use App\Erealestate;
use App\Subcompany;
use App\Subcompanyaccident;
use Faker\Provider\tr_TR\DateTime;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Auth;
use Hash;
use Validator;
ob_start();
session_start();
class readController extends Controller
{
 $modals=['Accident','Company','Companynote','Damagedetection','Dataentrynote','Datarequest',
             'Driver','Eaccident','Edriver','Eperson','Erealestate','Freelancerdataentryaccident','Garage'
              ,'Group','Kashef','Notification','Oldreportpayment','Person','Realestate','Receipt','Setting',
              'Rejectedreceipt','Subcompany','Subcompanyaccident','Task','Transaction','Userflow','Witness'];

我试图在以下代码语句中使用它们:

$modals[$x]::create($DB2_Data[$x]);

但是我收到了这个错误:

  

未发现“意外事故”

另一方面,如果我把这个或任何在模型数组中的东西,它可以正常工作

Accident::create($DB2_Data[$x]);

所以任何人都可以为我解决这个问题。

1 个答案:

答案 0 :(得分:0)

所以我们的朋友在那里建议我们需要在数组中添加它们如下:$modals=['App\Accident'] 谢谢