How to Create a User?
Created 7 years ago by mattcdavis1When i try the following:
$userModel = \Anomaly\UsersModule\User\UserModel::create([
'email' => 'test@test.com',
'display_name' => 'Some Name',
'password' => uniqid(),
]);
I get an "Undefined index: id" error from line 68 of:
\TeamTNT\TNTSearch\Support\Collection
#0 /Users/mattdavis/Code/web/afmlandsales.com/vendor/teamtnt/tntsearch/src/Support/Collection.php(68): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined index...', '/Users/mattdavi...', 68, Array)
#1 /Users/mattdavis/Code/web/afmlandsales.com/vendor/teamtnt/tntsearch/src/Indexer/TNTIndexer.php(279): TeamTNT\TNTSearch\Support\Collection->get('id')
#2 /Users/mattdavis/Code/web/afmlandsales.com/vendor/teamtnt/tntsearch/src/Indexer/TNTIndexer.php(284): TeamTNT\TNTSearch\Indexer\TNTIndexer->processDocument(Object(TeamTNT\TNTSearch\Support\Collection))
#3 /Users/mattdavis/Code/web/afmlandsales.com/vendor/teamtnt/laravel-scout-tntsearch-driver/src/Engines/TNTSearchEngine.php(46): TeamTNT\TNTSearch\Indexer\TNTIndexer->insert(Array)
#4 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/framework/src/Illuminate/Support/Collection.php(228): TeamTNT\Scout\Engines\TNTSearchEngine->TeamTNT\Scout\Engines\{closure}(Object(Anomaly\UsersModule\User\UserModel), 0)
#5 /Users/mattdavis/Code/web/afmlandsales.com/vendor/teamtnt/laravel-scout-tntsearch-driver/src/Engines/TNTSearchEngine.php(48): Illuminate\Support\Collection->each(Object(Closure))
#6 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/scout/src/Searchable.php(56): TeamTNT\Scout\Engines\TNTSearchEngine->update(Object(Illuminate\Database\Eloquent\Collection))
#7 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/scout/src/Searchable.php(35): Anomaly\Streams\Platform\Entry\EntryModel->queueMakeSearchable(Object(Illuminate\Database\Eloquent\Collection))
#8 [internal function]: Illuminate\Database\Eloquent\Collection->Laravel\Scout\{closure}()
#9 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php(78): call_user_func_array(Object(Closure), Array)
#10 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/scout/src/Searchable.php(112): Illuminate\Support\Collection->__call('searchable', Array)
#11 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2706): Anomaly\Streams\Platform\Entry\EntryModel->searchable()
#12 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2679): Illuminate\Database\Eloquent\Model->getRelationshipFromMethod('searchable')
#13 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2623): Illuminate\Database\Eloquent\Model->getRelationValue('searchable')
#14 /Users/mattdavis/Code/web/afmlandsales.com/vendor/anomaly/streams-platform/src/Model/EloquentModel.php(480): Illuminate\Database\Eloquent\Model->getAttribute('searchable')
#15 /Users/mattdavis/Code/web/afmlandsales.com/vendor/anomaly/streams-platform/src/Entry/EntryModel.php(413): Anomaly\Streams\Platform\Model\EloquentModel->getAttribute('searchable')
#16 /Users/mattdavis/Code/web/afmlandsales.com/vendor/anomaly/streams-platform/src/Entry/EntryModel.php(715): Anomaly\Streams\Platform\Entry\EntryModel->getRawAttribute('searchable')
#17 /Users/mattdavis/Code/web/afmlandsales.com/vendor/anomaly/streams-platform/src/Entry/EntryObserver.php(36): Anomaly\Streams\Platform\Entry\EntryModel->fireFieldTypeEvents('entry_creating')
#18 [internal function]: Anomaly\Streams\Platform\Entry\EntryObserver->creating(Object(Anomaly\UsersModule\User\UserModel))
#19 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(354): call_user_func_array(Array, Array)
#20 [internal function]: Illuminate\Events\Dispatcher->Illuminate\Events\{closure}(Object(Anomaly\UsersModule\User\UserModel))
#21 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(221): call_user_func_array(Object(Closure), Array)
#22 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(164): Illuminate\Events\Dispatcher->fire('eloquent.creati...', Array, true)
#23 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1667): Illuminate\Events\Dispatcher->until('eloquent.creati...', Object(Anomaly\UsersModule\User\UserModel))
#24 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1557): Illuminate\Database\Eloquent\Model->fireModelEvent('eloquent.creati...')
#25 /Users/mattdavis/Code/web/afmlandsales.com/vendor/anomaly/streams-platform/src/Model/EloquentModel.php(576): Illuminate\Database\Eloquent\Model->performInsert(Object(Anomaly\Streams\Platform\Entry\EntryQueryBuilder), Array)
#26 /Users/mattdavis/Code/web/afmlandsales.com/vendor/anomaly/streams-platform/src/Model/EloquentModel.php(514): Anomaly\Streams\Platform\Model\EloquentModel->saveModel(Array)
#27 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(561): Anomaly\Streams\Platform\Model\EloquentModel->save()
#28 /Users/mattdavis/Code/web/afmlandsales.com/addons/shared/union/union-module/src/Console/Import/AgentUsersDebugCommand.php(82): Illuminate\Database\Eloquent\Model::create(Array)
#29 [internal function]: Union\UnionModule\Console\Import\AgentUsersDebugCommand->fire()
#30 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(508): call_user_func_array(Array, Array)
#31 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array)
#32 /Users/mattdavis/Code/web/afmlandsales.com/vendor/symfony/console/Command/Command.php(261): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#33 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 /Users/mattdavis/Code/web/afmlandsales.com/vendor/symfony/console/Application.php(817): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 /Users/mattdavis/Code/web/afmlandsales.com/vendor/symfony/console/Application.php(185): Symfony\Component\Console\Application->doRunCommand(Object(Union\UnionModule\Console\Import\AgentUsersDebugCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 /Users/mattdavis/Code/web/afmlandsales.com/vendor/symfony/console/Application.php(116): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 /Users/mattdavis/Code/web/afmlandsales.com/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 /Users/mattdavis/Code/web/afmlandsales.com/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 {main}
I assume you don't get this with others like Role do you?
Can you copy / use the code as it is in the users module seeder? I assume that didn't break being that it installed. I am guessing there are required fields missing perhaps? Awfully weird behavior though.
No - i tried the users module approach also. Based on slack thread it sounds like this approach works for others. There must be something about the state of my DB or search index that is causing this. I did try deleting the search index file but that didn't help either.
Well - i guess it isn't confirmed that it works for others yet. Just noticed the example shown in slack was setting the id. it works if you set an id - but that shouldn't be needed.
It looks like the issue resulted from creating a custom user field called “Searchable” (with a slug of searchable
). This messes things up
Can you post the trace? Also need username in there though.