Hi,
I have a table like this:
+----+------------------+-----------+
| id | mail_domain | type |
+----+------------------+-----------+
| 1 | my_app.test | EQ |
| 2 | another_app.test | ENDS_WITH |
+----+------------------+-----------+
I want to query this table depending on field type like this
if 'type' == 'EQ'
Model::where('mail_domain' , $search)
if 'type' == 'ENDS_WITH'
Model::where('mail_domain', 'like', '%' . $search)
I know, I can use when() but the documentation only tells about some condition based on a variable:
$role = $request->input('role');
$users = DB::table('users')
->when($role, function ($query, $role) {
return $query->where('role_id', $role);
})
->get();
How can I relate the when() to a database-field instead of an separate variable?