0

New to Laravel php and trying to find out solution of this,

$periods = Period::where('timetable_id', $id);
echo $periods;

giving this error

Object of class Illuminate\Database\Eloquent\Builder could not be converted to string

i know why its giving this error but can not think of an alternate.

1
  • echo is used to print only string while in your case you are going to print object or an array so it's giving error. Try print_r() function to print array or object. Commented Dec 20, 2021 at 8:27

1 Answer 1

1

You'd need to ->get() your results first. Also, since you'll get a Collection returned you'd need to use dd() (or print_r/var_dump) to output the results:

$periods = Period::where('timetable_id', $id)->get();
dd($periods);

More on Building Queries

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

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.