Search on eloquent with nullable relation. #2548
Unanswered
tcagkansokmen
asked this question in
Q&A
Replies: 3 comments 2 replies
-
+1 Have same issue |
Beta Was this translation helpful? Give feedback.
0 replies
-
Since it's nullable, you should add a class Post extends Model
{
public function address() {
return $this->belongsTo(Address::class)->withDefault();
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
-
You can set default using datatable too using example:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using server-side rendering, and trying to search between columns.
I got relation like below,
Post::with(['address']);
Post can have an address, but also It may not have any address too.
So that, my logic fails on there;
I'm using column like
{ data: 'address.name', name:'address.name' }
so that, if there's no data inside "address relation" datatable return error, because it says "requested unknown parameter 'address.name'" because name field is undefined.
What could be the solve?
Beta Was this translation helpful? Give feedback.
All reactions