Melaku Minas Kasaye
Melaku Minas Kasaye

Reputation: 658

Laravel displaying array data

I have the following printed array data in laravel. how can I display it in a view.

Array ( [email] => minasmelaku@gmail.com [first_name] => Melaku [last_name ] => Minas [grade_id] => 9 [phone_number ] => minasmelaku@gmail.com [username] => minasmelaku@gmail.com [password ] => Melaku Minas [balance] => 0 [activation_code] => 123123 [penalty_counter] => 10 [account_status] => ACT ) 1

Upvotes: 1

Views: 77

Answers (3)

AddWeb Solution Pvt Ltd
AddWeb Solution Pvt Ltd

Reputation: 21681

You just pass $array variable with your view like

return view('yourview', compact('array'));

OR

use View;

return View::make('yourview')->with('array', $array);

AND use like this :

<p>{{$array['first_name']}}</p>
<p>{{$array['last_name']}}</p>

Hope this help for you

Upvotes: 0

peacemaker
peacemaker

Reputation: 2591

From your controller you can just pass the array to the view like so:

return view('view', $array);

Then in your view just access like:

<p>{{ $email }}</p>
<p>{{ $first_name }}</p>

And so on.

See the official Laravel docs on passing data to views: https://laravel.com/docs/master/views#passing-data-to-views

Upvotes: 1

Willie Mwewa
Willie Mwewa

Reputation: 361

This should work in your view..

@foreach($arrayname as $array)
   <p>{{ $array->first_name }}</p>
   <p>{{ $array->last_name }}</p>
   <p>{{ $array->firstname }}</p>
   <p>{{ $array->firstname }}</p>
   <p>{{ $array->grade_id }}</p>
   <p>{{ $array->phone_number }}</p>
   <p>{{ $array->username }}</p>
   <p>{{ $array->password }}</p>
   <p>{{ $array->balance }}</p>
   <p>{{ $array->activation_code }}</p>
   <p>{{ $array-> penalty_counter }}</p>
   <p>{{ $array->account_status }}</p>

@endforeach

Using the if statement with Blade templating will help you with printing out each element of an array called $arrayname. You should read more about this from the official laravel documentation concerning blade templates.

Read more about Blade templating with laravel from: https://laravel.com/docs/5.4/blade

Upvotes: 1

Related Questions