Код: Выделить всё
public function store(ProductRequest $request)
{
if($request->hasfile('filename'))
{
foreach($request->file('filename') as $image)
{
$name=$image->getClientOriginalName();
$year = Carbon::now()->year;
$month = Carbon::now()->month;
$day = Carbon::now()->day;
$imagePath = "/upload/images/{$year}/{$month}/{$day}";
$image->move(public_path($imagePath), $name);
$data[] = $imagePath . '/' . $name;
}
}
product::create(array_merge($request->all() , ['images' => json_encode($data)]));
$request->session()->flash('success', '!محصول با موفقیت ثبت شد');
return redirect(route('Products.index'));
}
Код: Выделить всё
#original: array:23 [▼
"id" => 16
"name" => "eqwsa"
"code" => "۱۰۲۶"
"price" => "۱۲۰۰۰۰"
"slug" => "eqwsa"
"description" => null
"images" => "["\/upload\/images\/2020\/6\/15\/index222.jpg","\/upload\/images\/2020\/6\/15\/carpet4-1.jpg"]"
"tags" => "eddsfew"
"viewCount" => 0
"commentCount" => 0
"stockCount" => 0
"sailedCount" => "0"
"specialSail" => 0
"specialPrice" => null
"size_id" => 7
"color_id" => 7
"discount_id" => 7
"yarn_id" => 1
"category_id" => 10
"density_id" => 4
"comb_id" => 5
"created_at" => "2020-06-15 12:04:55"
"updated_at" => "2020-06-15 12:04:55"
]
Код: Выделить всё
protected $casts = [
'images' => 'array',
];
Подробнее здесь: https://stackoverflow.com/questions/623 ... m-database
Мобильная версия