1

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

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

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

Careful because that documentation is for v4.2. At the moment of this comment Laravel is at v5.4.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.