Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

you should look into Relationships if you want to learn Laravel http://laravel.com/docs/eloquent#relationships

if you set it up correctly you can use stuff like

$user = User::with('characters', 'clan')->where('username', '=', 'Zenry')->first();

$user->characters; // all characters belonging to the user
$user->clan; // dito
Last updated 1 year ago.
0

zenry said:

you should look into Relationships if you want to learn Laravel http://laravel.com/docs/eloquent#relationships

if you set it up correctly you can use stuff like

$user = User::with('characters', 'clan')->where('username', '=', 'Zenry')->first();

$user->characters; // all characters belonging to the user $user->clan; // dito

The problem is, the user doesnt always have a clan, and if none found laravel would throw an error. A character is created upon registration of the account. But a clan is not. The code above will search for a clan that is connected to the user. Therefor I will need a query with a WhereExists function in it if I am correct? Or will the code above NOT show an error once there is no clan connected to the user?

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.