Home > other >  How to update array in laravel
How to update array in laravel

Time:11-07

I am struggling to find a suitable logic to update this array in Laravel. With this same logic, I can create however with I try to update It does only update all rows of the array.

I do not want to update anything right now. I only enter the edit page. I get this error

Thanks

filters table

FilterController.php

public function edit(Filter $filter)
{
    $colors = Color::all();
    $categories = Category::lists();
    $filters = Filter::with('category')->whereHas('category', function($query) use ($filter){
        $query->whereIn('category_id', [$filter->category_id]);
    })->get();
    return view('Admin.filters.edit', compact('categories', 'colors', 'filter', 'filters'));
}

public function update(Request $request, Filter $filter)
{
    dd('ok');
}

edit.blade.php

<form method="post" action="{{ route('filters.update', $filter->whereIn('category_id', [$filter->id])) }}">
    @method('PUT')
    @csrf

CodePudding user response:

public function edit(Filter $filter)
{
    $colors = Color::all();

    $categories = Category::lists();

    $filters = Filter::with('category')->whereHas('category', function($query) use ($filter){

        $query->whereIn('category_id', [$filter->category_id]);

    })->get(); // I'm not sure what do you want by this instead of $filter->load('category');

    return view('Admin.filters.edit', compact('categories', 'colors', 'filter', 'filters'));
}

public function update(Request $request, $id)
{
    dd('ok');
}

Blade File

<form method="post" action="{{ route('filters.update', $filter->id) }}">
    @method('PUT')
    @csrf

Isn't it you're looking for?

  • Related