MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Query Builder for Beginner In Laravel

1.Find Unique column and avoid duplicate column

3 method using distinct, groupby, pluck command

Laravel query builder selecting TripTitle from rvsps with distinct()->get() for unique values

OR

Laravel query builder selecting TripTitle from rvsps with groupby to remove duplicates

OR

Eloquent code Rvsp::distinct('TripTitle')->pluck('TripTitle') to get unique trip titles
JSON output with two unique TripTitle values: Land of the Rising Sun and Windy City
PhpMyAdmin rvsps table with four rows, three for Land of the Rising Sun and one for Windy City

In above table triptitle field land of rising sun and windy city r unique land of rising 3 times repeated

2 Find unique record

$categories = Rvsp::distinct()->get();

3.count total no of rows

here total 4 rows are there

Browser at localhost rvsplist route showing the count result 4
PhpMyAdmin rvsps table with four rows used for counting total records by TripTitle

$Trips = DB::table(‘rvsps’)
->select(‘TripTitle’)
->distinct()->count();
return $Trips;

count{{$Trips}} in blade file

4.display unique field and their total no of entries

here trip title Land of the Rising Sun 3 times entry in table triptitle Windy City one times see in below table mentioned in screenshot image

$touroperator = Rvsp::where(‘TripTitle’,$TripTitle)->latest()->paginate(20);
->select(‘TripTitle’, DB::raw(‘COUNT(TripTitle) as total_member’))
->groupBy(‘TripTitle’)
->havingRaw(‘COUNT(TripTitle) > 0’)
->get();

Table of trip titles and total counts: Land of the Rising Sun 3, Windy City 1
PhpMyAdmin rows of the Rvsp table with emails, names, phones and TripTitle values like Land of the Rising Sun

5.display particular colunm that is requested in blade file

first check requested value in blade file

Blade code with a List button linking to the touroperator.list route with $tour->TripTitle

$tour->TripTitle is requested

Laravel controller list($TripTitle) method that simply returns the requested TripTitle
Browser at localhost touroperator/list URL showing the returned value Land of the Rising Sun

requested value is land of rising sun

now find total record of requested value using this query
$touroperator = Rvsp::where(‘TripTitle’,$TripTitle)->latest()->paginate(20);

Laravel list method querying Rvsp where TripTitle matches, paginating 20 and returning the touroperator.Rvsp view
Bookings table showing three Land of the Rising Sun records, each with a Confirm button

6.display particular colunm that is present in another table based on condition

display all city of india

here three table city,state,country is present

Firstly retrive all state from state table that is under india where india id is 101 using pluck command

  $states = State::where(‘states.country_id’,’101′)->get();

then pass this variable to where condition to match all cities that is under india state

 $city = DB::table(‘cities’)->whereIn(‘cities.state_id’, $states)->get();

JSON output of the whereIn query listing city_id, city_name and state_id for Indian cities

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals

Related Posts

Laravel: oauth_access_tokens clean up process

using Laravel Passport—the oauth_access_tokens table balloons when tokens aren’t expiring, not being revoked on logout, or not being purged. Here’s a practical, safe cleanup + prevention plan…

Read More

Laravel: Complete Guide of Laravel Passport

Here’s a comprehensive, up-to-date step-by-step tutorial for setting up and using Laravel Passport (OAuth2 API authentication) with clear explanations, working code samples, and troubleshooting tips—suitable for local…

Read More

Laravel: What is APP_KEY in Laravel?

Let’s break down both what APP_KEY is in a Laravel .env file, why it matters, and its use cases. I’ll also explain how it’s generated and what…

Read More

artisan Tutorials: php artisan passport

When you run php artisan passport:install, Laravel attempts to do the following: Running php artisan passport:install is a crucial setup step when using Laravel Passport for API…

Read More

An introduction of Laravel Boilerplate

Laravel Boilerplate is a comprehensive starter kit designed to accelerate the development of Laravel applications by providing a robust foundation with pre-integrated features. Developed by Rappasoft, it…

Read More

Why You Should Avoid Laravel Spark and Stripe/Paddle for Certain Use Cases

✅ Explains why Laravel Spark is not suitable in certain use cases✅ Clarifies the limitations of Stripe and Paddle✅ Lists unsupported countries✅ Guides developers toward the right…

Read More