简体   繁体   中英

htmlspecialchars() expects parameter 1 to be string, object given in laravel 9

public function viewData($id){

        $result = Property::find($id);
        $view = view('home.property_detail',compact('result'))->render();
     return response()->json(['body'=>$view]);
    }

controller function

function view(id) {
        var route = "{{route('home.page')}}";
        $.get(route+'/view/details/'+ id, function (product) {
            $('#single_view').html('');
            $('#single_view').append(product.body);
            $('#view_model').modal('toggle');
        });
    }

function call on onclick this function return "jquery.min.js:2 GET https://zehrii.com/view/details/24 500" error click on this error show that title

You have an error in resources/views/home/property_detail.blade.php

@foreach (json_decode($result->features) as $feature)
<div class="col-sm-4">
    {{ $feature }}
</div>
@endforeach

It seems that {{ $feature }} is an object and you're trying to access it as a string, You need to call the individual property inside of the object, example:

$feature->title

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM