File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 14
14
use App \Events \TodoUpdated ;
15
15
use App \Exceptions \TodoException ;
16
16
use App \Models \AppLog ;
17
+ use App \Models \Category ;
17
18
use App \Models \Todo ;
18
19
use App \Services \ElasticsearchService ;
19
20
use App \Traits \RepositoryTraits ;
@@ -128,11 +129,17 @@ public function getTodosBySearch($params, $user)
128
129
public function createTodo ($ user , $ params )
129
130
{
130
131
try {
132
+ if (empty ($ category_id )) {
133
+ $ category_id = Category::where ('user_id ' , $ user ->id )->value ('id ' );
134
+ } else {
135
+ $ category_id = $ params ['category_id ' ];
136
+ }
137
+
131
138
$ todo = new Todo ;
132
139
$ todo ->uid = Uuid::uuid4 ()->toString ();
133
140
$ todo ->title = $ params ['title ' ];
134
- $ todo ->description = $ params ['description ' ];
135
- $ todo ->category_id = $ params [ ' category_id ' ] ;
141
+ $ todo ->description = ! empty ( $ params ['description ' ])? $ params [ ' description ' ] : '' ;
142
+ $ todo ->category_id = $ category_id ;
136
143
$ todo ->user_id = $ user ->id ;
137
144
$ todo ->save ();
138
145
You can’t perform that action at this time.
0 commit comments