OrganizationsController.php
public function user_index()
{
if(!is_null(Organization::find(Auth::user()->player->organization)))
$organization = Organization::find(Auth::user()->player->organization->id);
else $organization=null;
return view('organizations.user_index', [ 'organization' => $organization ]);
}
To avoid "Trying to get property of non-object" when "player" have no "organization" I used this code. But it doesnt seem very nice. There is a better way to obtain this? Maybe im wrong but with this method there is a useless query, am I right?
Table Player: id, name
Table Organization: id, name, player_id