ModelName::create([
'body' => if(isset($request->input('someText')) ? 1 : 0;
]);
Asked
Active
Viewed 72 times
0

Qirel
- 25,449
- 7
- 45
- 62
-
1Welcome to SO ... well you can use a ternary but they don't start with an `if` – lagbox Jul 30 '20 at 19:37
-
1You could probably just do `'body' => $request->has("someText")` instead, or if you're set on using `isset()`, then `'body' => isset($request->input('someText')`. I'd go with the first one. – Qirel Jul 30 '20 at 19:43
-
'body'=>$request->has("someText") ? 1 : 0; Like this? – user327534 Jul 30 '20 at 19:49
-
@user327534 that method returns a boolean so if you had to convert that into an integer you can `(int) $request->has('someText')` – lagbox Jul 30 '20 at 19:53
-
I don't really think you need to typecast it to integer, as it'll end up as `1` or `0` for a boolean `true` or `false` respectively. A simple `'body' => $request->has("someText")` should suffice. – Qirel Jul 30 '20 at 20:10
-
@Qirel to me that would depend if it is being converted to a string or not after the fact, that is my only worry – lagbox Jul 30 '20 at 20:30
-
I think this would be enough `'body' => $request->has('someText') ` – lewis4u Jul 30 '20 at 21:24