Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

orest's avatar
Level 13

hide buttons based on query string

I'm building a small forum app with Laravel and Vue and currently i'm adding filter buttons to fetch threads based on the filter button.

For example, in a Vue component, i have the following button, which essentially makes a get request to the back-end and fetches the threads created by the authenticated user

<a href="/threads?myThreads=1"> My Threads </a>

But in addition to the button above i have other filters as well

  1. Threads i have replied to
  2. Threads that were created 7 days ago

However, i want to hide the clicked buttons based on the query strings

window.location.href

For example if i click the button My Threads, then the href will be

/threads?=myThreads=1

In this case i want to hide the button My Threads, based on the href.

My question

Is this a bad approach ? To make decisions based on the href.

Should i try a different approach ? Such as, passing data from the backend to to front end

0 likes
5 replies
Snapey's avatar

I suppose my question is, what has this to do with vue?

Why not just send what is required in the view from the controller. If no button is required, don't render it in blade.

orest's avatar
Level 13

@snapey

Do you mean to send data from the controller ( true or false ) in order to show or hide a button ?

For example,

If one of the requests is

myThreads = 1

Then to keep track of the request data and create a variable

if($request->has('myThreads')){
	$filterMyThreads = true;
}
return view('threads', compact('filterMyThreads'));

and use that to decide whether to show or hide the button My Threads

< a href="/threads?myThreads=1" v-if="{{ $filterMyThreads }}">My Threads </a>
orest's avatar
Level 13

@nathalie

I didn't remember that even though i've seen the whole series.

That's good to know that Jeffrey has used this approach.

However, he uses it for something ''less important'' let's say and i'd like to know if this is acceptable in general or whether i should take a different approach.

1 like
Snapey's avatar

i'm confused what is in a blade file and what is inside a vue component.

If the button is inside the vue component and that is in its own file and not inline then you need to pass it props from the controller to tell it how to behave

1 like

Please or to participate in this conversation.