Closed wouterdorgelo closed 3 years ago
@wouterdorgelo
Where do you create your user? Only creating a User within your seeder is not enough. You also need a Team. Can you follow the registration process on the app and then log in?
Cheers Sebastian
Hi there,
Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:
However, this issue will not be locked and everyone is still free to discuss solutions to your problem!
Thanks.
Also need to seed a test team like so:
Team::create([ 'user_id' => 1, 'name' => 'admin-team', 'personal_team' => '1', ]);
Check if user has team in the blade view.
resources/views/navigation-dropdown.blade.php
In line 61:
- @if (Laravel\Jetstream\Jetstream::hasTeamFeatures())
+ @if (Laravel\Jetstream\Jetstream::hasTeamFeatures() && Auth::user()->current_team_id)
In line 162:
- @if (Laravel\Jetstream\Jetstream::hasTeamFeatures())
+ @if (Laravel\Jetstream\Jetstream::hasTeamFeatures() && Auth::user()->current_team_id)
i seem to be having this same problem.. i it was all working when i pushed to my github and later i downloaded a new copy it kept showing me these errors in my navigation-dropdown.blade.php i added in some checks for new menus and stuff like this
@if (Auth::user()->hasTeams()) @if($user->hasTeamPermission($team, 'admin'))
i mananged to get "hasTeams" to work again some how but hasTeamPermissions seems to always come back true when its not true.
its like the hole thing has bug somehwere from the pull form git..
Um.
Same problem. It's only on production for me. Which, and other clues in here, leads me to believe it's a database issue. production had 0 entries in Teams table. local had one. So I created the same entry on production now it works.
Maybe I missed a php artisan migrate or something.
Hope this helps someone.
@JonahKlimack for me it was because i have disabled having teams by default as i have extra code on signup to only make teams for one kind of signup... but my fix was the following..
In the AppServiceProvide.php (App/Providers) i added the following.. i could make it smaller but it works so i left it..
view()->composer(['navigation-dropdown'], function ($view) {
// Check if user owns a team...
if (Auth::user()->hasTeams()) {
$team = Team::where('user_id', auth()->user()->id)->first();
// if they dont own a team are they apart of one..
if ($team == NULL) {
$team = Team::where('id', auth()->user()->currentTeam->id)->first();
}
} else {
$team = '';
}
$view->with('team', $team);
});
Hello @driesvints,
I came here because I was following this tutorial: https://laracasts.com/series/laravel-authentication-options/episodes/2 And to make it clear, I was doing a clean installation of everything, Laravel, Breeze and then Jetstream. Did follow the installation instructions exactly, but it's not working.
So this is a bug with the library because it's not working out of the box, but needs to be fixed immediately, even before first run.
Please reconsider your position and push a fix for it.
Hi @DePalmo you need to run migrations first, this is because the first page "/" and "dashboard" view are already using data related to user and teams, so that is why you are required to run migrations first, it is pretty much the same as trying to register a user with "Breeze" or "Laravel UI" without running the migrations, it would throw an exception, just in this case on the first page.
For the sake of argument, I just tried again. Another clean installation but this time only Laravel and Jetstream. Steps:
laravel new test
.env
with DB credentials and database namecomposer require laravel/jetstream
php artisan jetstream:install livewire --teams
.htaccess
that redirects /
to /public
npm install
npm run dev
php artisan migrate
Please note that in first attempt, I was installing Laravel first, then Breeze and last Jetstream. I did run php artisan migrate:fresh
afterwards, but same issue.
@DePalmo for me i have it setup so i have 2 types of users, one being normal users with no teams and based on option clicked in signup i have "networks" this user type makes a team on the signup, so i guess as long as there is a team made then it should show in the dropdown.. here is an example of my App/Fortify/CreateNewUser.php
This also has a few edits for extra fields and such linking networks table to to teams and also to users ect..
class CreateNewUser implements CreatesNewUsers { use PasswordValidationRules;
public function create(array $input)
{
//check if its a user account
if($input['type'] == "user"){
Validator::make($input, [
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => $this->passwordRules(),
'username' => ['required', 'unique:users', 'string', 'max:255'],
])->validate();
$ip = $_SERVER['REMOTE_ADDR'];
$user = User::create([
'username' => $input['username'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
'ip' => $ip,
]);
return $user;
}
//check if its a Network account
if($input['type'] == "networkname"){
Validator::make($input, [
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => $this->passwordRules(),
'networkname' => ['required', 'string', 'max:255'],
'username' => ['required', 'unique:users', 'string', 'max:255'],
])->validate();
$ip = $_SERVER['REMOTE_ADDR'];
$user = User::create([
'username' => $input['username'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
'ip' => $ip,
]);
if (isset($user->id)){
//Add the Network
$name = $input['networkname'];
$userId = $user->id;
$slug = Str::slug($input['networkname']);
DB::table('networks')->insert(
['name' => $name, 'slug' => $slug, 'user_id' => $userId, 'created_at' => now(), 'updated_at' => now()]
);
$network = DB::table('networks')->where('user_id', $userId)->first();
//Make the Team for the Network
DB::table('teams')->insert(
['user_id' => $userId, 'name' => $name."'s Team", 'personal_team' => false, 'network_id' => $network->id, 'created_at' => now(), 'updated_at' => now()]
);
}
return $user;
}
} }
Read the docs carefully: https://jetstream.laravel.com/2.x/features/teams.html
Jetstream's team features allow each registered user to create and belong to multiple teams. By default, every registered user will belong to a "Personal" team. For example, if a user named "Sally Jones" creates a new account, they will be assigned to a team named "Sally's Team". After registration, the user may rename this team or create additional teams.
You cannot have a user without a team in the default --team scaffolding.
Just use withPersonalTeam()
from UserFactory.
Faced the same issue, check the routes. I had the '/'
route changed to point to a custom blade which requires authenticated user. Changed it back and it started to work.
I hope it helps someone.
Description: ErrorException on fresh Jetstream install: Trying to get property 'user_id' of non-object
Steps To Reproduce: