Преобразование типов данных массива в Laravel v5.4 Переполнение стека

Контроллер.

namespace App\Http\Controllers;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class TestDBController extends Controller
{
public function index()
{
$db_ext = \DB::connection('extdb');
$customer = $db_ext->table('customer')->get();
var_dump($customer);
// var_dump($customer);
return view('customers.index', ['customer' => $customer]);
}
}

Посмотреть

<table class="table table-responsive" id="kunder-table">
<thead>
<th>ID</th>
<th>name</th>
<th>Email</th>
<th>Mobil</th>
<th>Address</th>
<th>Address2</th>
<th>Address3</th>
</thead>
<tbody>
@foreach($customer as $customer)
<tr>
<td>{!! $customer->customerid !!}</td>
<td>{!! $customer->name !!}</td>
<td>{!! $customer->email !!}</td>
<td>{!! $customer->mobile !!}</td>
<td>{!! $customer->adress1 !!}</td>
<td>{!! $customer->adress2 !!}</td>
<td>{!! $customer->adress3 !!}</td>
</tr>
@endforeach
</tbody>
</table>

Это результат «var_dump».

    object(Illuminate\Support\Collection)[261]
protected 'items' =>
array (size=365)
0 =>
object(stdClass)[262]
public 'BANKACCOUNT' => string '' (length=0)
public 'CUSTOMERID' => int 10000
...

Я получил окончательный результат как «Неопределенное свойство: stdClass :: $ customerid.
но есть также обычай в каждой таблице полей.
Итак, как я могу получить правильное представление списка? Благодарю.

1

Решение

Пожалуйста, попробуйте следующие изменения:

В TestDBController

return view('customers.index', ['customers' => $customer]);

В представлении файла

@foreach($customers as $customer)
<tr>
<td>{!! $customer->customerid !!}</td>
<td>{!! $customer->navn !!}</td>
<td>{!! $customer->email !!}</td>
<td>{!! $customer->mobile !!}</td>
<td>{!! $customer->adress1 !!}</td>
<td>{!! $customer->adress2 !!}</td>
<td>{!! $customer->adress3 !!}</td>
</tr>
@endforeach

Здесь, в разделе вашего контроллера, вы передаете значения в customer переменная и ввиду foreach цикл вы используете то же имя.

Синтаксис по умолчанию foreach цикл это:

foreach($array as $values)

и согласно вашему коду, вы используете ту же переменную, что и ваш массив коллекций.

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector