简体   繁体   中英

How to update array in laravel

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

过滤器表

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
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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM