Reputation: 658
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
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
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
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