Is there no possible way to add teams after you created the jetstream project?
Laravel Jetstream teams
Hi,
I am currently using Laravel Jetstream and now I have decided I would like to use the functionality of teams. How would I go by adding teams to my existing Laravel Jetstream project? Please note I am using the livewire stack.
Digging up this post, and hopefully you found your answer at the time.
Since I had this same question three years later and could not search up a clear answer. I will share what I did to add Teams to Jetstream late in the build of an application. You can opt into Teams later via the jetstream config settings. However, that does not bring all the default pieces along with it (such as the views, and models) its just a setting.
So, I ran php artisan jetstream:install inertia --teams again. This added the missing migrations, models, views, etc. for Teams. This was mildly destructive for my application. The install reset a small handful of foundational files, such as, routes/web.php and dashboard.vue you should absolutely do this in a branch so that you can audit the changes made by re-running the install. If you have made extensive changes to Jetsteam this might be a mess.
I also needed to delete the new add_two_factor_columns_to_users_table.php migration as it was a duplicate that had been run at the beginning of the project.
Directly after the setup and migrations I got a Ziggy error that teams.show required an ID parameter. This is due to there being no teams and no users related to teams. First step was to seed in a team
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
class EditorTeamSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
DB::table('teams')->insert([
'user_id' => 1,
'name' => 'Editors',
'personal_team' => false,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now()
]);
}
}
After seeding the team I then modified the current_team_id column for the user. Since I only have a single user I did this directly in the DB. After that I was back up and running... after reconciling some files of course.
Jetstream only has a single artisan command, install. An additional command like add or feature to add on the pieces later would be very helpful.
I'm gonna try and take a stab at making a "jetstream:add livewire --teams" command. Just looking at the source code it seems pretty doable. I'll post my results or even make a pull request if I get it done but for anyone else curious the install command is here. https://github.com/laravel/jetstream/blob/5.x/src/Console/InstallCommand.php
wow really helpful, exactly what i was looking for
Please or to participate in this conversation.