2017-02-22 30 views
0

Я новичок в Laravel. И я сделал исследования, но я не могу найти правильный ответ для моего кода.htmlspecialchars() ожидает, что параметр 1 будет строкой, задан массив. (laravel)

Так у меня есть этот контроллер

namespace Modules\Inventory\Http\Controllers; 

use Modules\Setup\Init; 

use Illuminate\Http\Request; 
use Illuminate\Http\Response; 
use Illuminate\Routing\Controller; 
use Illuminate\Support\Facades\DB; 

use Modules\Inventory\Entities\mongodb_logs as mongodb_logs; 

use Modules\Template; 

class ActivityLogsController extends Controller 
{ 
    /** 
    * Display a listing of the resource. 
    * @return Response 
    */ 
    protected $data; 
    protected $page_title = 'Login'; 

    function setup($vars = null) 
    { 
     $Init = new Init; 
     $vars['page'] = $this->page_title; 
     $this->data['template'] = $Init->setup($vars); 
     return $this->data; 
    } 

    public function index() 
    { 
     $loglists = mongodb_logs::orderBy('date_added', 'desc')->get(); 
     $this->data['loglist'] = $loglists; 

     return view('inventory::_logs', $this->setup()); 
    } 
} 

и мой взгляд был как раз этот простой

<table id="tbl_logs" class="table table-striped table-bordered table-hover"> 
    <thead> 
     <tr> 
      <td>Type</td> 
      <td>User</td> 
      <td>Date</td> 
      <td>Message</td> 
      <td>Before</td> 
      <td>After</td> 
     </tr> 
    </thead> 
    <tbody> 
     @if($loglist != null) 
      @foreach($loglist as $logs) 
       <tr> 
        <td>{{$logs->type}}</td> 
        <td>{{$logs->logged_in_user}}</td> 
        <td>{{$logs->date_added}}</td> 
        <td>{{$logs->message}}</td> 
        <td>{{$logs->before}}</td> 
        <td>{{$logs->after}}</td> 
       </tr> 
      @endforeach 
     @endif 
    </tbody> 
</table> 

Я извлечь loglist из 'бревен' моей коллекции MongoDB. Я успешно извлечены данные, которые вы можете попробовать его с помощью «print_r», но когда я его просмотра на мой взгляд, это ошибка, которая показывает

htmlspecialchars() expects parameter 1 to be string, array given 

это print_r результат моего $ loglist который я successfulyl извлечена из MongoDB print_r result

вот несколько строк моего var_dump.

object(Illuminate\Database\Eloquent\Collection)#408 (1) { 
    ["items":protected]=> 
    array(40) { 
    [0]=> 
    object(Modules\Inventory\Entities\mongodb_logs)#409 (26) { 
     ["connection":protected]=> 
     string(7) "mongodb" 
     ["collection":protected]=> 
     string(4) "logs" 
     ["primaryKey":protected]=> 
     string(3) "_id" 
     ["parentRelation":protected]=> 
     NULL 
     ["table":protected]=> 
     NULL 
     ["keyType":protected]=> 
     string(3) "int" 
     ["incrementing"]=> 
     bool(true) 
     ["with":protected]=> 
     array(0) { 
     } 
     ["perPage":protected]=> 
     int(15) 
     ["exists"]=> 
     bool(true) 
     ["wasRecentlyCreated"]=> 
     bool(false) 
     ["attributes":protected]=> 
     array(11) { 
     ["_id"]=> 
     object(MongoDB\BSON\ObjectID)#288 (1) { 
      ["oid"]=> 
      string(24) "58acfb2b202f941b50002ddf" 
     } 
     ["user_id"]=> 
     int(2) 
     ["admin_id"]=> 
     int(2) 
     ["logged_in_user"]=> 
     string(5) "admin" 
     ["date_added"]=> 
     string(19) "2017-02-22 02:44:59" 
     ["type"]=> 
     string(6) "update" 
     ["message"]=> 
     string(69) "Deceased Documents ofAniyah Gottlieb ID number 4   successfully updated" 
     ["before"]=> 
     string(188) " {"id":2,"d_id":4,"death_cert_no":null,"trans_permit_no":null,"crem_permit_no":nu ll,"exhum_permit_no":null,"senior_card_no":null,"disabled_card_no":null,"created _at":null,"updated_at":null}" 
     ["after"]=> 
     string(211) "  {"id":2,"d_id":4,"death_cert_no":"20171542","trans_permit_no":null,"crem_permit_ no":null,"exhum_permit_no":null,"senior_card_no":null,"disabled_card_no":null,"c reated_at":null,"updated_at":"2017-02-22 02:44:59"}" 
     ["updated_at"]=> 
     object(MongoDB\BSON\UTCDateTime)#287 (1) { 
      ["milliseconds"]=> 
     string(10) "1672815231" 
    } 
    ["created_at"]=> 
    object(MongoDB\BSON\UTCDateTime)#286 (1) { 
     ["milliseconds"]=> 
     string(10) "1672815231" 
    } 
    } 
    ["original":protected]=> 
    array(11) { 
    ["_id"]=> 
    object(MongoDB\BSON\ObjectID)#288 (1) { 
     ["oid"]=> 
     string(24) "58acfb2b202f941b50002ddf" 
    } 
    ["user_id"]=> 
    int(2) 
    ["admin_id"]=> 
    int(2) 
    ["logged_in_user"]=> 
    string(5) "admin" 
    ["date_added"]=> 
    string(19) "2017-02-22 02:44:59" 
    ["type"]=> 
    string(6) "update" 
    ["message"]=> 
    string(69) "Deceased Documents ofAniyah Gottlieb ID number 4 successfully updated" 
    ["before"]=> 
    string(188) "{"id":2,"d_id":4,"death_cert_no":null,"trans_permit_no":null,"crem_permit_no":null,"exhum_permit_no":null,"senior_card_no":null,"disabled_card_no":null,"created_at":null,"updated_at":null}" 
    ["after"]=> 
    string(211) "{"id":2,"d_id":4,"death_cert_no":"20171542","trans_permit_no":null,"crem_permit_no":null,"exhum_permit_no":null,"senior_card_no":null,"disabled_card_no":null,"created_at":null,"updated_at":"2017-02-22 02:44:59"}" 
    ["updated_at"]=> 
    object(MongoDB\BSON\UTCDateTime)#287 (1) { 
     ["milliseconds"]=> 
     string(10) "1672815231" 
    } 
    ["created_at"]=> 
    object(MongoDB\BSON\UTCDateTime)#286 (1) { 
     ["milliseconds"]=> 
     string(10) "1672815231" 
    } 
    } 
+0

на какой линии? замените условие ifif @if (! empty ($ loglist)) – rahulsm

+0

Покажите нам свой печатный массив ... – Nawin

+0

Привет @rahul_m, указанной конкретной строки не указано. ошибка только что указана ОшибкаException в строке helpers.php 532: htmlspecialchars() ожидает, что параметр 1 будет строкой, заданный массив (вид: C: \ laragon \ www \ template \ Modules \ Inventory \ Resources \ views \ _logs.blade .php) Я попробовал ваше предложение, но я все еще получаю ошибку –

ответ

0

Ваши переменные до и после являются массивами, поэтому вы получаете эту ошибку. Попробуйте этот код:

+0

ой! мой до и после json_encoded. Но даже если я удалю их из представления таблицы, я все равно получаю ошибку –

+0

Хорошо кажется, что «до и после» не проблема. Давайте посмотрим иначе, чем это. Что такое '$ this-> data ['template'] = $ Init-> setup ($ vars)' –

+0

Я делаю все это в определенном модуле, где я использую шаблон для просмотра блейдов. Значения из контроллера распознаются в виде через $ this-> data ['name_in_view'] = name_in_controller ', а все данные $ this-> содержатся внутри' $ this-> setup() 'для проще переносить ставки ценностей.контроллер и представления. –

0

Одним или несколькими из свойств возвращаемого объекта является массив. попытаться var_dump($logs)


Я не могу комментировать еще

 Смежные вопросы

  • Нет связанных вопросов^_^