Thursday, March 16, 2017

Output value from table in view

I've got a problem in Laravel. I have passed my whole table to my view like this from my controller:

$usersTable = DB::table('users')->get();
return view('users')->with('users', $usersTable);

In a foreach loop I can perfectly get each of the values like this in my view:

        @foreach($users as $user => $value) 
            <div class="projectBox">
                <br><span class="projectBoxName"></span>
                @php
                    echo Form::image('/images/edit.png', "",['class' => "editUserBtn", 'userId' => $value->id]);
                @endphp
                <br><span class="projectBoxSmallText projectBoxEmail"></span>
                <br><span class="projectBoxSmallText projectBoxId">ID: </span>
                <br><span class="projectBoxSmallText projectBoxProjects">Currently no projects</span>
            </div>
        @endforeach

But I also need to access these values outside my foreach loop, how can I do that?

   echo Form::text('email', "$users->$value->email", array('placeholder' => "Email"));

Ain't working...

This gives my the whole object in this form

[{"id":"1","name":"Administrator","email":"admin@mail.com","password":"$2y$10$Re3Ahf.SwU5vj4UvtU5Dy.jxaZMsUNC2WhuJMwsNy9gu6TST4PuRG","remember_token":null}]

How to get only the email? I also tried using indexes, but those weren't working. Thanks!



via O'Niel

Advertisement