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

[1.x] Adds custom redirects after creating or deleting a team #383

Merged
merged 1 commit into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/Http/Controllers/Inertia/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
use Laravel\Jetstream\Contracts\DeletesTeams;
use Laravel\Jetstream\Contracts\UpdatesTeamNames;
use Laravel\Jetstream\Jetstream;
use Laravel\Jetstream\RedirectsActions;

class TeamController extends Controller
{
use RedirectsActions;

/**
* Show the team management screen.
*
Expand Down Expand Up @@ -62,9 +65,11 @@ public function create(Request $request)
*/
public function store(Request $request)
{
app(CreatesTeams::class)->create($request->user(), $request->all());
$creator = app(CreatesTeams::class);

$creator->create($request->user(), $request->all());

return redirect(config('fortify.home'));
return redirect($this->redirectPath($creator));
}

/**
Expand Down Expand Up @@ -96,8 +101,10 @@ public function destroy(Request $request, $teamId)

app(ValidateTeamDeletion::class)->validate($request->user(), $team);

app(DeletesTeams::class)->delete($team);
$deleter = app(DeletesTeams::class);

$deleter->delete($team);

return redirect(config('fortify.home'));
return redirect($this->redirectPath($deleter));
}
}
5 changes: 4 additions & 1 deletion src/Http/Livewire/CreateTeamForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

use Illuminate\Support\Facades\Auth;
use Laravel\Jetstream\Contracts\CreatesTeams;
use Laravel\Jetstream\RedirectsActions;
use Livewire\Component;

class CreateTeamForm extends Component
{
use RedirectsActions;

/**
* The component's state.
*
Expand All @@ -27,7 +30,7 @@ public function createTeam(CreatesTeams $creator)

$creator->create(Auth::user(), $this->state);

return redirect(config('fortify.home'));
return redirect($this->redirectPath($creator));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Livewire/DeleteTeamForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function deleteTeam(ValidateTeamDeletion $validator, DeletesTeams $delete

$deleter->delete($this->team);

return redirect(config('fortify.home'));
return redirect($this->redirectPath($deleter));
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/RedirectsActions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Laravel\Jetstream;

trait RedirectsActions
{
/**
* Get the redirect path for the action.
*
* @param $action
* @return string
*/
public function redirectPath($action)
{
if (method_exists($action, 'redirectTo')) {
return $action->redirectTo();
}

return property_exists($action, 'redirectTo') ? $action->redirectTo : config('fortify.home');
}
}