This would work.
$users = App\Book::with('author:id,name,email')->get();
This would not.
$users = App\Book::with('author:id, name, email')->get();
It gives this error.
Unknown column ' name' in 'field list'
I think the space is detected as part of the table's name.
So follow the documentation and don't use spaces? 馃槒
Yeah, but I like spaces between my columns.
That's how it works currently, sorry.
This is so strange, I don't have spaces, but Laravel adds a space for some reason and then complains about it!
@json(\App\Language::with('subjects:id,title')->get())
SQLSTATE[42S22]: Column not found: 1054 Unknown column ' title' in 'field list' (SQL: select `id`, ` title` from `subjects` where `subjects`.`language_id` in (1, 3, 4, 5) and `subjects`.`deleted_at` is null)
The same thing is happening to me as @mokhosh :
@json(\App\Models\TagSets::with('tags:id,name,color')->get());
I get this error: Unknown column ' name' in 'field list'
Anyone else experienced this and how to fix?
I realized that the similarity in both our cases is the @json directive. For anyone in the future who experiences this, the fix is simply to put it outside of the @json directive.
@php
$tagSets = \App\Models\TagSets::with('tags:id,name,color')->get();
@endphp
@json($tagSets);
So it seems the @json is putting it off. Could this be a bug worth looking into @themsaid ? Frankly the workaround is not that big of a pain though :)
Most helpful comment
So follow the documentation and don't use spaces? 馃槒