0

i want access file i upload from client side using an array in php.

this is my request

{
    "first_name": "name",
    "last_name": "test",
    "religion": "islam",
    "date_of_birth": "2022-12-01",
    "phone": "213123123",
    "gender": "male",
    "identity_cards": [
        {
            "document_category_id": "1",
            "number": "1283712",
            "exp_date": "2020-11-20",
            "image": {}
        }
    ]
}

how can i possible to access the images?

i try some method like

$request->file('identity_cards[0][image]');

but doesn't work

Zulfikar
  • 49
  • 6

2 Answers2

0

I hope it will work.

$request->file('identity_cards.0.image');
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
-1

Object and array use different operators. For your case, you can use this

$request->file('identity_cards[0]->image');

So if your data like this:

"identity_cards": [
  {
            "document_category_id": "1",
            "number": "1283712",
            "exp_date": "2020-11-20",
            "image": {
                url: "blablabla.com"
            }
  }

How to access url? just modify it.

$request->file('identity_cards[0]->image->url');

Explanation here

Localhousee
  • 887
  • 1
  • 5
  • 17