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

usamaahmed's avatar

Search Value on the basis of dropdown

I'm creating events in my site. I want to search events on the basis of a country select dropdown . This is my blade file:

 @include('/includes/header')

<div class="table-container">
    <div class="container mx-w-lg">
        <div class="users_data">

            <div class="field">
                <div class="label">{{ __('language.Country') }}</div>
                <select name="country" id="country" required>
                    <option value="Netherlands" {{ session()->get('locale') == 'du' ? 'selected' : '' }}>{{ __('Netherlands') }}</option>
                    <option value="Spain" {{ session()->get('locale') == 'es' ? 'selected' : '' }}>{{ __('Spain') }}</option>
                    <option value="England" {{ session()->get('locale') == 'en' ? 'selected' : '' }}>{{ __('England') }}</option>
                    <option value="France" {{ session()->get('locale') == 'fr' ? 'selected' : '' }}>{{ __('France') }}</option>
                    <option value="Germany" {{ session()->get('locale') == 'gr' ? 'selected' : '' }}>{{ __('Germany') }}</option>
                </select>
            </div>


            @foreach($Activities as $date => $Activity)
            @if($date >= date('Y-m-d'))
            @if($date === date('Y-m-d'))
            <h3>{{ __('language.Today') }} {{date("d F Y", strtotime($date))}}</h3>
            @elseif($date === $tomorrowDate)
            <h3>{{ __('language.Tomorrow') }} {{date("d F Y", strtotime($date))}}</h3>
            @else
            <h3>{{date("l, d F Y", strtotime($date))}}</h3>
            @endif
            @endif

            @foreach($Activity as $activity)
            @if($activity->date >= date('Y-m-d'))
            <div class="content">
                <div class="item info">
                    @if(date_diff($activity->created_at, \Carbon\Carbon::now())->d < 1) <span>{{ __('language.New') }}!</span>
                        @endif
                </div>
                <div class="item img">
                    @include('activity::icon-component')
                </div>
                <div class="item title">
                    <a href="{{route("activity-detail", ['id' => $activity->id])}}"><span>{{ $activity->event_name }}</span></a>
                </div>
                <div class="item location">
                    <span><i class="fas fa-map-marker"></i> {{ $activity->location ?? 'Online' }}</span>
                </div>
                <div class="item time">
                    <span><i class="fas fa-clock"></i> {{ $activity->start_time }}</span>
                </div>
                <div class="item users">
                    <span><i class="fas fa-user"></i> {{ $activity->min_participants }} / {{ $activity->max_participants }}</span>
                </div>
                <div class="item">
                    <span>{{ $activity->age_group }} jr</span>
                </div>
                <div class="item">
                    <span>{{ \App\Models\User::find($activity->user_id)->name }}</span>
                </div>
            </div>
            @endif

            @endforeach
            @endforeach
        </div>
    </div>
</div>
@include('/includes/footer')

and this is my function to search country:

       $country= DB::table('activities')
            ->where('country', '=', $newdate)
            ->orderBy('id','asc')
            ->pluck('country');  // "5"

}

can anyone guide me how can I show columns of db on the base of select dropdown

0 likes
2 replies
webrobert's avatar

@usamaahmed, please format your code.

Three backticks to open and three more to close...

```

// code block here

```

You may use Markdown with GitHub-flavored code blocks.

1 like
webrobert's avatar

@usamaahmed,

there is a very helpful series here on how to use Laravel... Laravel 8 from Scratch.

This...

       $country= DB::table('activities')
            ->where('country', '=', $newdate)
            ->orderBy('id','asc')
            ->pluck('country'); 

Using the model would give you some added benefits, why use laravel?

Also, you should be using country_id following naming conventions

$activities = Activity::query()
	->where('country_id',  $country_id) // get all activities for this country_id
	->get();

and, you can cast your datetime fields to Carbon

// on the model
protected $casts = [
    'start_date' => 'datetime' ,
  // and so on
];

then...

            @if($date >= date('Y-m-d'))
            @if($date === date('Y-m-d'))
            <h3>{{ __('language.Today') }} {{date("d F Y", strtotime($date))}}</h3>
            @elseif($date === $tomorrowDate)
            <h3>{{ __('language.Tomorrow') }} {{date("d F Y", strtotime($date))}}</h3>
            @else
            <h3>{{date("l, d F Y", strtotime($date))}}</h3>
            @endif
            @endif

becomes a whole lot cleaner ....

@if($start_date->isToday())
//
@elseif($start_date->isTomorrow())
// and more

for your selection you can list the countries id => name then pass the country_id to the query.

// assuming you have a table of countries ...
<select name="country_id" id="country" required>
    @foreach($countries as $country)
        <option value="{{ $country->id }}" 
// some assumptions here, depend on version there is a selected helper
				@selected({{ session()->get('locale') == $country->abr }})> 
            {{ __($country->name) }})
        </option>
    @endforeach
</select>

all that to say it seems like events search is the current session country or the one selected by the user.

Please or to participate in this conversation.