morganchorlton3's avatar

Appending a collection

Hi all i have been creating an eCommerce platform and I want to add colors to products, to do this I have a section with a selector which then creates a collection and added that colour (so I can display this to the user), I now want to update this collection and add another colour to the collection, is there a way to pass the collection back to the controller so i can do something like this:

$request->current_colours->push($colour);

or is there a better way to do this?

controller


public function save(Request $request, Collection $added_colours)
    {        
        $colour = Colour::find($request->id);

        $added_colours[] = $colour;

        return view('admin.product.create')->with([
            'colours' => $colours,
            'messages' => $messages,
            'categories' => $categories,
            'alerts' => $alerts,
            'added_colours' => $added_colours,
        ]);
    }
<form action="{{ route('admin.product.colour.add', "1") }}" method="POST">
                            @csrf
                            <div class="row">
                                <input hidden id="colour" name="id" type="text" value="">
                                <div class="col-lg-7">
                                    <select onchange="val()" id="colour_selector" class="mb-4 form-control @error('colour') is-invalid @enderror">
                                        <option></option>
                                        @foreach($colours as $colour)
                                            <option value="{{ $colour->id }}">{{ $colour->name }}</option>
                                        @endforeach
                                    </select>
                                    @error('colour')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                    @enderror
                                </div>
                                <div class="col-lg-5">
                                    <button type="submit" class="btn btn-primary" style="width:100%"><i class="fa fa-tint mr-2"></i>  Add Colour</button>
                                </div>
                            </div>
    </form>
0 likes
4 replies

Please or to participate in this conversation.