vendredi 3 avril 2020

finding array index from view in laravel

how can I fetch one particular index from the array to delete? e.g. if I have array[a, b, c] in the array list and want to delete b which is index array[1] from it? Any help would be great.

I need to pass index to the controller so I can delete it

View

@foreach (json_decode($p->filename) as $picture)
   <ul>
      li align="left"><a href="/delete-product-image-name/"><small><u><i>Delete</u></i></small></a></li>
   </ul>
@endforeach

Controller

public function deleteProductImageName($id) {
        if(Auth::check()) {

            $products = Product::where('id', $id)->first();

            foreach($products as $p) {
                if(($products->user_id == Auth::user()->id) && ($products->id == $id)) {
                    $product = Product::where('user_id', Auth::user()->id)
                                            ->where('id', $id)->first();

                    foreach ($product as $key => $value) {
                        echo $value . " in (" . $key . "), ";
                    }
                }
            }
        } else {
            Session::flash("message", "OOPS! You dont have permission to delete the items. Please login first.");
            return redirect("/register-user");

        }
    }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire