Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should one create the first user? #288

Open
jakubgs opened this issue Jan 19, 2022 · 3 comments
Open

How should one create the first user? #288

jakubgs opened this issue Jan 19, 2022 · 3 comments

Comments

@jakubgs
Copy link

jakubgs commented Jan 19, 2022

I understand from the docs that it is recommended to create the database schema by calling:

php artisan migrate --seed

https://github.com/Bottelet/DaybydayCRM/wiki/Install
https://github.com/Bottelet/DaybydayCRM/wiki/Install-using-Docker

But is the --seed part necessary? I tried using it without --seed and then creating an admin user with:

php artisan tinker --execute="
  DB::table('users')->insert([
    'name'=>'admin',
    'email'=>'[email protected]',
    'password'=>Hash::make('super-secret')
  ]);
"

But when I try to login using that user I get:

ErrorException
Trying to get property 'country' of non-object
at app/Repositories/Format/GetDateFormat.php:17

But if I try to create the same user after using migrate with --seed I get:

ErrorException
Trying to get property 'name' of non-object (View: /var/www/html/resources/views/navigation/topbar/user-profile.blade.php)
at resources/views/navigation/topbar/user-profile.blade.php:20

So how am I supposed to do this? Should this even work without --seed? And if not, how should I create the first user?

I was thinking of updating the seeded admin this way:

php artisan tinker --execute="
  User::where('id',1)->update(array(
    'name'=>'{{ daybyday_crm_admin_user_name | mandatory }}',
    'email'=>'{{ daybyday_crm_admin_user_email | mandatory }}',
    'password'=>Hash::make('{{ daybyday_crm_admin_user_pass | mandatory }}')
  ));
"

Does this make sense?

@designamx
Copy link

did you tried seeding the settings first? the missing country field comes from the settings model

@jakubgs
Copy link
Author

jakubgs commented Jan 26, 2022

Yes, I tried both, as you can see from my issue description.

It appears seeding the database is necessary, but it is not doable multiple times, so I have to do an SQL query first - in my case SELECT name FROM users; - in order to check if the database was already seeded, and then I call php artisan db:seed --force --no-interaction , because otherwise it would fail during multiple Ansible runs.

It would be much better if there was an php artisan user:add command.

@Bottelet
Copy link
Owner

Hi @jakubgs You are right for the production you have to set up by hand. a command to do it would be cool. And I'll gladly accept a PR for it. But for now, it's either by hand DB insert or tinker. Or use db:seed and create and change the user that is created by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants