Вызов delete вызовет деструктор, а затем освободит память.
Вызвать деструктор явно вызовет только деструктор, а не освободит память.
Поэтому вы должны почти всегда вызов delete: за исключением случаев, когда вы хотите вызвать деструктор без освобождения памяти, например потому что вы построили объект с помощью размещения new .
Вам нужно с нетерпением загружать ваши отношения с фильтрацией:
Предполагая, что вы получите связь с информацией о вашем продукте
$typeName = 'Video';
$product = App\Product::with([
'asset' => function($query) use($typeName) {
//Filter asset by type
//See: https://laravel.com/docs/5.6/eloquent-relationships#constraining-eager-loads
return $query->whereHas('asset_type',function($query) use($typeName) {
//Filter where the type's name equals..
//Each query is relative to its scope, in this case the 'type' relationship which refers to your 'type' Model
return $query->where('name','=',$typeName);
});
},
//Nested relationship loading: https://laravel.com/docs/5.6/eloquent-relationships#querying-relations
'assets.asset_type'
])
->find(1);
$assets = $product->assets;
Предполагая, что вы извлекаете только активы
$productId = 1;
$typeName = 'Video';
//Returns a collection of eloquent models
$assets = Asset::whereHas('product',function($query) use ($productId) {
//Filter product by its id
return $query->where('id','=',$productId);
})
->whereHas('asset_type',function($query) use ($typeName) {
//Filter type by its name
return $query->where('name','=',$typeName);
})
->get();