Closed youyi1314 closed 4 years ago
Transferred to the jetstream repo.
How do you login with a "non-team" user? All registered users receive teams on sign up.
How do you login with a "non-team" user? All registered users receive teams on sign up.
@taylorotwell Thanks for your reply, i think i got bug, cos i register but no team is added, or may i know how it create team? cos i tried both add user manually with terminal and from register form. no team is added.
How do you login with a "non-team" user? All registered users receive teams on sign up.
@taylorotwell Thanks for your reply, i think i got bug, cos i register but no team is added, or may i know how it create team? cos i tried both add user manually with terminal and from register form. no team is added.
Encountered the same problem when I manually create user using factory (UserFactory.php). You can bypass this by inserting a new row to teams table on your db. Then refresh the page.
As for register, It's working fine for me.
@sureyeahdie How can we create a user with team using factory ?? Currently I am using User::factory()->create() , but it seems it is not creating teams
@sureyeahdie How can we create a user with team using factory ?? Currently I am using User::factory()->create() , but it seems it is not creating teams
@iRajul the default factory doesn't handle other data creation, you need to create another factory that handles teams creation. Make sure you provide the factories with some static values, as the default UserFactory uses the Faker Library to populate data.
More about factories and db seeding: https://laravel.com/docs/8.x/database-testing#creating-factories
I can see 2 issues here:
Both of these can be handled in code by the developer, but should they happen/be available by default?
How do you login with a "non-team" user? All registered users receive teams on sign up.
@taylorotwell, I want to give an example when creating a user without a team can be useful. At the moment, when developing an application, I want to use teams as organizations, which will include users. Users, in turn, after filling out the registration form, must authorize on the site, but see only the most basic set of information, without having any more rights, until the super-administrator or special manager checks his registration application and assigns him a team and a role in this team. I would suggest taking into account similar situations in the package and allowing the user to register without creating a team for him automatically. And give the ability to authorize a user without a team assigned to him. It is also possible that commands are used as teams, for example, sports, and users without assigned teams will be observers. Maybe what I said above contradicts the principles for which you created teams, but I believe that the approach I described can be very useful for many developers. Thank you for your time.
Maybe someone will need a solution in the future:
You need to overwrite method switchTeam
in User
model:
/**
* Switch the user's context to the given team.
*
* @param $team
* @return bool
*/
public function switchTeam($team): bool
{
if (!$team || !$this->belongsToTeam($team)) {
return false;
}
$this->forceFill([
'current_team_id' => $team->id,
])->save();
$this->setRelation('currentTeam', $team);
return true;
}
In AppLayout.vue
to links route('teams.show', $page.props.user.current_team)
add the condition v-if="$page.props.user.current_team"
. You should get something like the following:
<!-- Team Settings -->
<jet-dropdown-link
v-if="$page.props.user.current_team"
:href="route('teams.show', $page.props.user.current_team)"
>
Team Settings
</jet-dropdown-link>
and
<!-- Team Settings -->
<jet-responsive-nav-link
v-if="$page.props.user.current_team"
:href="route('teams.show', $page.props.user.current_team)"
:active="route().current('teams.show')"
>
Team Settings
</jet-responsive-nav-link>
Perhaps I have not considered something else. I think the rest of the logic can be easily implemented.
I brought the teams into my laravel project but I am using this for agents and teams, not the users table. I updated the jetstream class file for the $userModel to reference 'App\Models\Agent" and changed the foreign_key to agent_id. The issue I have is when the HasTeams trait function pivots on the team_agent pivot table. It keeps looking for the team_user table. When I renamed the pivot table to team_user, it gets tripped up on my tenant_id in the where clause. That is a column in the pivot table for my multi-tenancy. Is there another way to configure the code to use the new pivot table name?
I brought the teams into my laravel project but I am using this for agents and teams, not the users table. I updated the jetstream class file for the $userModel to reference 'App\Models\Agent" and changed the foreign_key to agent_id. The issue I have is when the HasTeams trait function pivots on the team_agent pivot table. It keeps looking for the team_user table. When I renamed the pivot table to team_user, it gets tripped up on my tenant_id in the where clause. That is a column in the pivot table for my multi-tenancy. Is there another way to configure the code to use the new pivot table name?
You may try to add $table
variable with your new pivot table name in Membership
model class, like at:
/**
* The table associated with the pivot model.
*
* @var string
*/
protected $table = 'team_user';
If you not have Membership
model in your project, you may extend this class from Laravel\Jetstream\Membership
, like at:
<?php
namespace App\Models;
use Laravel\Jetstream\Membership as JetstreamMembership;
class Membership extends JetstreamMembership
{
/**
* The table associated with the pivot model.
*
* @var string
*/
protected $table = 'team_agent';
}
It's hard for me to understand without specific examples, but I hope I understood you correctly.
I brought the teams into my laravel project but I am using this for agents and teams, not the users table. I updated the jetstream class file for the $userModel to reference 'App\Models\Agent" and changed the foreign_key to agent_id. The issue I have is when the HasTeams trait function pivots on the team_agent pivot table. It keeps looking for the team_user table. When I renamed the pivot table to team_user, it gets tripped up on my tenant_id in the where clause. That is a column in the pivot table for my multi-tenancy. Is there another way to configure the code to use the new pivot table name?
You may try to add
$table
variable with your new pivot table name inMembership
model class, like at:/** * The table associated with the pivot model. * * @var string */ protected $table = 'team_user';
If you not have
Membership
model in your project, you may extend this class fromLaravel\Jetstream\Membership
, like at:<?php namespace App\Models; use Laravel\Jetstream\Membership as JetstreamMembership; class Membership extends JetstreamMembership { /** * The table associated with the pivot model. * * @var string */ protected $table = 'team_agent'; }
It's hard for me to understand without specific examples, but I hope I understood you correctly.
That resolved my issue. Thanks!
Description:
Added
use HasTeams;
to user modelsWhen login with a non-team user, it will show an error.
Steps To Reproduce:
I just start up and create 1 user using factory with data below:
and tried also register at register page. after login to dashboard page, it will show
Trying to get property 'id' of non-object
that error at:vendor/laravel/jetstream/src/HasTeams.php:28