Pass the value of navigationLabel to create page

So, I have a Students table and it has a field called gametype, which is basically hidden from the user, its in my SQL Table only. What I have is that multiple types of sports and I am saving their data in the same sql table, so whenever I want to show players in Badminton, I just run a condition and show student with gametype Badminton, so what I want to do is that when I create a record from Badminton resource, I want the create page to know that I am coming from the Badminton page so the value of gametype should be Badminton etc Even better if I can keep that hidden but if I need to put that value in the form builder to have it save in the database, I will just use a disabled input field for it
Solution:
as a closure?
->brandName(fn () => auth()->user()->name);
->brandName(fn () => auth()->user()->name);
...
Jump to solution
20 Replies
Billi 🌻
Billi πŸŒ»β€’6mo ago
Also is there a way I can pass the name of the logged in user as brandname in admin panel provider?
Jordy
Jordyβ€’6mo ago
we dont know your code mate, show it.. it tells us more than this whole paragraph xd
Shaung Bhone
Shaung Bhoneβ€’6mo ago
code please
Billi 🌻
Billi πŸŒ»β€’6mo ago
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
$id = Auth::user()->name;

return $panel
->default()
->id('admin')
->path('admin')
->login()
->brandName($id)

}
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
$id = Auth::user()->name;

return $panel
->default()
->id('admin')
->path('admin')
->login()
->brandName($id)

}
Sorry I'm kind of new to Laravel
Jordy
Jordyβ€’6mo ago
not an entire duuuump xD.. pinpoint what you want and what you tried.. read the #βœ…β”Šrules .. help us help you and what not
Billi 🌻
Billi πŸŒ»β€’6mo ago
Let me edit this xD Basically the $id needs to have the name of the current logged in user and I want to just dynamically change the name of the dashboard I tried using this too hoping it may just give the ID even but atleast this code doesnt give me an error $id = Auth::id();
Jordy
Jordyβ€’6mo ago
->brandName(auth()->user()->name ?? 'default name')
->brandName(auth()->user()->name ?? 'default name')
Otherwise it prob throws user is null on the login screen?
Billi 🌻
Billi πŸŒ»β€’6mo ago
for some reason the name property doesnt exist, is there a way I can console the auth()->user() to see if it returns anything?
Jordy
Jordyβ€’6mo ago
ps.. dont use variable when you are just using them directly and dont need them for anything else.. bad practice.. no need for $id or $name ^^ are you logged in? if you are not.. there is no name as there is no user what do you actually want the brandname to be? it beeing different for every user seems odd to me tbh haha
Billi 🌻
Billi πŸŒ»β€’6mo ago
I am logged in, is it possible its happening because I did the remember me? I can see my dashboard and everything and I see the 'default name' now
Jordy
Jordyβ€’6mo ago
nah, doesnt change anything about the authenticated user just sets the remember token
Billi 🌻
Billi πŸŒ»β€’6mo ago
I have a column in my table that has value of their sports club so I want to later on set it as that but keeping it simple to name for now Is it possible that AdminPanelProvider does the authentication later?
Solution
Jordy
Jordyβ€’6mo ago
as a closure?
->brandName(fn () => auth()->user()->name);
->brandName(fn () => auth()->user()->name);
Jordy
Jordyβ€’6mo ago
works for me
Billi 🌻
Billi πŸŒ»β€’6mo ago
let me check by writing exactly this Oh this worked! I guess I needed the fn call, THANK YOU SO MUCH!!!! the same can be done for the clubname column? ->brandName(fn () => auth()->user()->clubname);
Jordy
Jordyβ€’6mo ago
as long it is set, yeah.. just watch out for the login page.. it will throw attempt to read x on null cus there is no auth user on the login page so you would need
->brandName(fn () => auth()->user()->clubname ?? 'default name');
->brandName(fn () => auth()->user()->clubname ?? 'default name');
so its nullsafe
Billi 🌻
Billi πŸŒ»β€’6mo ago
Okay, I will do that, thanks alot, sorry for the trouble! Really appreciate it !
Jordy
Jordyβ€’6mo ago
all good
Billi 🌻
Billi πŸŒ»β€’6mo ago
Thank you
Want results from more Discord servers?
Add your server
More Posts