3

First step - create a new a Gallery (Name and Type). Click 'Next' button. Second step - upload multiple images to that gallery.

What can I do in order to achieve that in Laravel Nova admin panel? I can't follow documentation and just add HasMany::make('Images') to a Gallery resource, I need a two steps form.

MEF
  • 31
  • 4

1 Answers1

1

If I understand right first step you need to make from view input <input type="file" multiple> than send request and in your controller you need something like this:

$date = Carbon::now()->format('Y-m-d-hh-mm-ss');
    $files = request('images');

    $pluss = 1;
    foreach ($files as $file) {
        $imageName = $date . '.' . $pluss . $file->getClientOriginalExtension();
        $file->move(public_path('/images/products'), $imageName);
        $pluss++;
        $data = [
            'image' => $imageName,
            'product_id' => $product->id
        ];
        Image::create($data);
    }
  • 2
    Thanks! But I am struggling to figure out how to create custom forms in Laravel Nova. – MEF Nov 14 '19 at 19:57