1

I keep getting this error when I pass a user(venue) object through a controller into my view, I've tried encoding it, and decoding it to no avail. I've also tried finding the user in the view instead of in the controller by just passing the id of the user through, but I get the same error? People in other questions seem to have no problem doing it with this syntax or similar, am I doing something wrong?

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

Controller:

public function index($venue)
    {
        $venue = \App\venue::findOrFail($venue);
        return view('index.venue')->with(['venue'=>$venue]);
    }

I'm trying to access it in views like this:

            <div class="venueName">
                <h4>{{ $venue->name }}</h4>
            </div>
<p>{{ $venue->addresse }}</p>
<p>{{ $venue->bio }}</p>
<img src="{{ url($venue->galleryOne) }}" alt="">
@foreach ($venue->item as $item)...

this is the dd($venue):

venue {#247 ▼
  #guard: "venue"
  #fillable: array:5 [▶]
  #hidden: array:2 [▶]
  #connection: "mysql"
  #table: "venues"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:11 [▶]
  #original: array:11 [▶]
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #visible: []
  #guarded: array:1 [▶]
  #rememberTokenName: "remember_token"
}

Any Help would be fantastic! Thankyou :)

8
  • try dd($venue); in the index function, at start Commented Aug 20, 2019 at 8:57
  • do you have somewhere else in your blade {{$venue}} ? Commented Aug 20, 2019 at 8:58
  • Are you accessing any other properties or variables? Can you post the entire view? Commented Aug 20, 2019 at 8:58
  • I've added the dd and all the ways I access $venue in the view, the view is quite large, so I couldn't post it all Commented Aug 20, 2019 at 9:03
  • @rargy what is your galleryOne property is it a string or an object? Commented Aug 20, 2019 at 9:04

3 Answers 3

1

One of the items in one of the objects is an object too and the {{ }} requires a string to be the variable inside there. Check all items returned by objects.

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

Comments

1

Thanks to everyone for figuring out it must be a result of a call to an object variable in the view. Solution: Some of the variables were "NULL" which is processed as an object, and causes the error. I changed the default values in the database from NULL to an empty string, and it worked fine :).

Comments

0

You will add get method after findOrFail method,if exist data .... if not exist data or null ,you must control if(empty($venue)) in view


        $venue = \App\venue::findOrFail($venue)->get();
        return view('index.venue')->with(['venue'=>$venue]);


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.