Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

show array item on blade laravel

Arrays:

[
    {"id":1,"group":"post","name":"Mi","value":"x3 poco"},
    {"id":2,"group":"post","name":"iPhone","value":"14 pro"},
    {"id":3,"group":"post","name":"Nokia","value":"C5"},
    {"id":4,"group":"post","name":"Dell","value":"15 insp"}
    .
    .
    .
]

IndexController.php file:

$post = Post::all();
return view('index', compact('post'));

index.blade.php file:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Post Name: "{{ $post->name['iPhone']->value }}"

I want to show the output as below:

Post Name: "14 pro"

But error is showing:

Error: Property [name] does not exist on this collection instance.

>Solution :

You can use where on the collection to search by name:

Post Name: "{{ $post->where('name', 'iPhone')->first()?->value }}"

The question mark is in case there is no item with the name you are looking for.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading