Terms and conditions

Hello guys! I have a problem and not sure how to solve it. I have a page and livewire component Terms and Conditions. What i need is, when user registers for the first time, it should take him to the page where Terms and Conditions are declared, and there is a checkbox which looks like that :
public function submit(): \Illuminate\Http\RedirectResponse|\Illuminate\Contracts\Foundation\Application|\Illuminate\Routing\Redirector
{
$data = $this->form->getState();

// Check if the user is logged in and if terms_and_conditions is set.
if (auth()->check() && isset($data['terms_and_conditions']) && $data['terms_and_conditions']) {
// Update the terms_and_conditions field for the user.
auth()->user()->update(['terms_and_conditions' => $data['terms_and_conditions']]);

// Flash a session message to indicate terms were accepted.
session()->flash('accepted', true);

// Redirect to the /admin page.
return redirect('/admin');
} else {
// If the user does not accept the terms and conditions, send them to a 403 page.
abort(403, 'You must accept the terms and conditions to use this service.');
}
}
public function submit(): \Illuminate\Http\RedirectResponse|\Illuminate\Contracts\Foundation\Application|\Illuminate\Routing\Redirector
{
$data = $this->form->getState();

// Check if the user is logged in and if terms_and_conditions is set.
if (auth()->check() && isset($data['terms_and_conditions']) && $data['terms_and_conditions']) {
// Update the terms_and_conditions field for the user.
auth()->user()->update(['terms_and_conditions' => $data['terms_and_conditions']]);

// Flash a session message to indicate terms were accepted.
session()->flash('accepted', true);

// Redirect to the /admin page.
return redirect('/admin');
} else {
// If the user does not accept the terms and conditions, send them to a 403 page.
abort(403, 'You must accept the terms and conditions to use this service.');
}
}
So the idea is, when he gets there, he should be still able to see the look of filament, but absolutely nothing else that Terms and conditions and checkbox. The blade file :
<div>
<form wire:submit.prevent="submit">
{{ $this->form }}

<button type="submit">
Submit
</button>
</form>

{{ $this->modal }}
</div>
<div>
<form wire:submit.prevent="submit">
{{ $this->form }}

<button type="submit">
Submit
</button>
</form>

{{ $this->modal }}
</div>
I'm literally running out of ideas, so looking forward to your answers!
7 Replies
Patrick Boivin
Patrick Boivin17mo ago
What are you using for user registration?
dusan8061
dusan8061OP17mo ago
filament-breezy
Patrick Boivin
Patrick Boivin17mo ago
Maybe ask in #breezy to get more ideas... but I'm thinking you could probably do this with a Filament middleware. Add a column to your users table (e.g. has_agreed_to_terms) and then in your middleware, when a user logs in, check this to determine if they should be redirected to the Terms page or to the Dashboard.
Patrick Boivin
Patrick Boivin17mo ago
You can find an example of middleware here to get you started : https://filamentphp.com/tricks/redirect-in-case-canaccessfilament-fails
Filament
Redirect in case canAccessFilament fails by Quadrubo - Tricks - Fil...
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
dusan8061
dusan8061OP17mo ago
Hey, thanks a lot for an answer. I've already tried breezy, and from what I could see, there is no something like that there. The column is created, and the checkbox which is pointing it to 'users' table in DB. Ok, i will check this with the Middleware tomorrow and keep you updated. Thank you very much!!!!!
Dennis Koch
Dennis Koch17mo ago
I'd add a middleware similar to Laravel verified middleware that redirects to that page as long as a column is not set to true.
he should be still able to see the look of filament,
You might need to create your own layout without header and sidebar or use the layout that Filament uses for the auth route.
dusan8061
dusan8061OP17mo ago
This should be the solution. I will soon start implementing this and will keep you guys updated, but I am very optimistic!
Want results from more Discord servers?
Add your server