Skip to content

Instantly share code, notes, and snippets.

@aklimaruhina
Created October 23, 2022 11:04
Show Gist options
  • Save aklimaruhina/64905246a77238cf12c24399d3bab528 to your computer and use it in GitHub Desktop.
Save aklimaruhina/64905246a77238cf12c24399d3bab528 to your computer and use it in GitHub Desktop.
when you need to use map function while imploading
function implodeProduct($product){
$multiplied = $product->stocks->map(function ($item, $key) {
return $item->size .' = '.$item->qty ;
});
return $multiplied->implode(', <br>');
}
and model
// each product might have many product
public function stocks()
{
return $this->hasMany(Stock::class,'product_id');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment