本文整理汇总了PHP中app\models\Item::pictures方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::pictures方法的具体用法?PHP Item::pictures怎么用?PHP Item::pictures使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Item
的用法示例。
在下文中一共展示了Item::pictures方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveImages
/**
* Save Images from temporary folder to Storage and store it in database
*
* @param Item $item
* @param Supplier $supplier
* @param array $images
*
* @return
*/
public static function saveImages($item, $supplier, $request)
{
// Get the short name of supplier
$supplier = $supplier->shortname;
$path = 'pictures/' . $supplier . '/';
foreach ($request->images['image'] as $image) {
$picture = Picture::where('path', '=', $path . $image)->first();
$first_choice = $request->picture == $image ? 1 : 0;
// If Picture exist in database, check if it's attached to this Item.
// If Picture don't exist in database, create it and attach it to this Item.
if ($picture === null) {
$picture = new Picture(['path' => $path, 'title' => $image]);
$picture->save();
$picture->moveImage();
$item->pictures()->attach($picture->id, ['first_choice' => $first_choice]);
} elseif ($picture) {
// If item don't have picture attached, attach it!
if (!$item->hasPicture($picture->id)) {
$item->pictures()->attach($picture->id);
}
}
}
}