Reputation: 11
use App\Abc\Model1;
use App\Abc\Model2;
use App\Abc\Model3;
use App\Abc\Model4;
// This My Models
$modelArr = ['Model1','Model2','Model3','Model4'];
foreach ($modelArr as $key => $value) {
$model = new $value;
$model->where('abc','=',$abc)->get();
$model->delete();
}
// But not working fatal error : Model1 Class Not Found
Upvotes: 0
Views: 202
Reputation: 725
Try with this
$modelArr = [Model1::class,Model2::class,Model3::class,Model4::class];
Or if you need to assign with string you need to include full namespace to the strings. Example:
$modelArr = ['App\Model1','App\Model2','App\Model3','App\Model4'];
Upvotes: 2