Some Important Laravel Query Screenshot
use of selectraw
- get single value
- count
- sum
get all data using query
query is used for search
Booking.php
get_my_bookings
check_booking
get organizor booking
organiser_view_booking
Delete_booking
total_booking
total_revenue
update_payment_type
get_seat_availability_by_ticket
Category.php
get_categories
get_all_categories
city.php
get_countries_having_events()
Discount.php
get_discount()
Event.php
get_latest_events()
get_featured_events
get_top_selling_events
get_allevent_by_category
get_upcomming_events
get_cities_events
get_organizers||get_customers
search_customers
disable_event
get_all_events
total_event
iternary.php
get_days
mydiscount.php
insertselect_discount||insert_discount
get_discountweek||get_discountweek_second
rvsp.php
get_my_bookevents
Ticket.php
get_event_tickets
get_events_tickets
User.php
all_operator_user
group by two field
get all data using query
is used for filter see Event.php
using query
oR using get
$query = Event::get();
$query = DB::table('users');
$query->select('name', 'id', 'email')
->where('role_id', 3);
Booking.php
- use of left join
- use of selectRaw
- use of alias,orderby,paginate.
condition
- condition based on customer_id and publish
get_my_bookings
make_booking
- use of create
check_booking
- use of first
- use of multiple condition inside where having multiple param .
condition
replacement of multiple where and
get data using first using multiple condition
update data using multiple condition
get organizor booking || get_organiser_tripbookings(rvsp.php
- whereDate
greater or equal to
conditionin case of searching by between two dates
in case of searching by start_date
in case of searching by event_id
in case of searching by between two dates
in case of searching by start_date
in case of searching by event_id
Full Code
organiser_view_booking
- use of selcet,where,first
- how to use DB::table($this->tb).
Delete Example
- use of Delete
- how to use DB::table($this->tb).
condition
count Example
- use of count with where and without where just attach with model.
condition
- total_bookings
- count total no of booking created by that organizors id
sum Example
- use of sum with where and without where just attach with model
condition
total_revenue
total money collected by that oranizors id
update_payment_type
- how to use $key and $value pair inside foreach
- take model::get() inside one variable use it inside foreach
- apply if condition on $value on (key,value) pair
condition
update multiple row using get() and take key,value pair inside foreach and then if stmt
get_seat_availability_by_ticket
- select,
- selectRaw,
- where,
- groupBy two field,
- orderBy,
- get
condition
- to get seat_availability_by_ticket first find total booked using sum through selectRaw
to get seat_availability_by_ticket first find total booked using sum through selectRaw
selectRaw("SUM(quantity) as total_booked")
Category.php
get_categories
- offset,
- limit,
- take,
- skip,
condition
get_all_categories
- leftJoin
- select
- use count selectRaw
- groupBy.
condition
count total no of event belongs to categories using selectraw
city.php
get_countries_having_events()
- leftJoin
- select
- where and not equal
- use count selectRaw
- groupBy.
condition
Discount.php
get_discount()
- get dynamic dropdown data like week 1,week 2.. using condition on days greater than or equal to
- empty condition on first
- condition on take.
condition
** get dynamic dropdown data like week 1,week 2.. using condition on days greater than or equal to**
public function get_discount($dayss,$event_id)
{
log::info('yeh mera days hai naa');
log::info($dayss);
$tickets= Myticket::where('ticket_event_id',$event_id)->first();
$trip=Trip::where('id',$event_id)->first();
$publish=$trip->publish;
if(empty($tickets)|| $publish==0 ||$publish==1)
{
if($dayss>=126)
{
$result = Discount::take(17)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=119)
{
$result = Discount::take(16)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=112)
{
$result = Discount::take(15)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=105){
$result = Discount::take(14)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=98){
$result = Discount::take(13)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=91){
$result = Discount::take(12)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=84){
$result = Discount::take(11)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=77){
$result = Discount::take(10)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=63){
$result = Discount::take(9)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=56){
$result = Discount::take(8)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=49){
$result = Discount::take(7)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=42){
$result = Discount::take(6)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=35){
$result = Discount::take(5)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=28){
$result = Discount::take(4)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=21){
$result = Discount::take(3)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=14){
$result = Discount::take(2)->get();
log::info($result);
return to_array($result);
}
elseif($dayss>=7){
$result = Discount::take(1)->get();
log::info($result);
return to_array($result);
}
else{
log::info('else 1st $result');
$result = Discountmsg::take(1)->get();
log::info($result);
return to_array($result);
}
}
else{
if($dayss<7)
{
log::info('else 1st $result');
$result = Discountmsg::take(1)->get();
log::info($result);
return to_array($result);
}
}
}
- empty condition on first.
- condition on take.
Event.php
get_latest_events()
- leftJoin
- select
- orWhere
- selectRaw
- first.
save_event()
updateOrCreate
How to Store Array in Database Laravel?
event_tags
one event has many tag
- use of sync in laravel relationship.
events()
Search based on event name,state,city,category(dropdown),date ,price (dropdown),country (dropdown)
whereRaw
whereDate
!empty($params['search']
LIKE.
condition
- Incase of input type search
- Incase of dropdown country,state,city
Incase of price
public function events($params = [])
{
$query = Event::query();
log::info('yaha evenst fun');
log::info($params['search']);
$query
->leftJoin("categories", "categories.id", '=', "events.category_id")
->select(["events.*", "categories.name as category_name"]);
if(!empty($params['search']))
{
$query
->whereRaw("( title LIKE '%".$params['search']."%'
OR venue LIKE '%".$params['search']."%' OR state LIKE '%".$params['search']."%' OR city LIKE '%".$params['search']."%' OR slug3 LIKE '%".$params['search']."%')");
}
$query
->selectRaw("(SELECT CN.country_name FROM country CN WHERE CN.country_id = events.country_id) country_name")
->selectRaw("(SELECT SN.state_name FROM states SN WHERE SN.state_id = events.state_id) state_name")
->selectRaw("(SELECT CITYN.city_name FROM cities CITYN WHERE CITYN.city_id = events.city_id) city_name")
->selectRaw("(SELECT SD.repetitive_type FROM schedules SD WHERE SD.event_id = events.id limit 1 ) repetitive_type");
if(!empty($params['category_id']))
$query->where('category_id',$params['category_id']);
if(!empty($params['country_id']))
$query->where('country_id',$params['country_id']);
if(!empty($params['state_id']))
$query->where('state_id',$params['state_id']);
if(!empty($params['city_id']))
$query->where('city_id',$params['city_id']);
if(!empty($params['start_date']) && !empty($params['end_date']))
{
$query->whereDate('start_date', '>=' , $params['start_date']);
$query->whereDate('start_date', '<=' , $params['end_date']);
}
if(!empty($params['start_date']) && empty($params['end_date']))
$query->whereDate('start_date', $params['start_date']);
if(!empty($params['price']))
{
if($params['price'] == 'free')
$query->where('price_type', "0" );
if($params['price'] == 'paid')
$query->where('price_type', 1);
}
$query
->where(["events.status" => 1, "events.publish" => 1, "categories.status" => 1]);
// if hide expired events is on
if(!empty(setting('booking.hide_expire_events')))
{
$today = \Carbon\carbon::now(setting('regional.timezone_default'))->format('Y-m-d');
$query->whereRaw('(IF(events.repetitive = 1, events.end_date >= "'.$today.'", events.start_date >= "'.$today.'"))');
}
return $query->orderBy('events.updated_at', 'DESC')->paginate(9);
}
get_featured_events
whereDate and Carbon::today()->toDateString()
get_top_selling_events
orderBy(total_booking),
SUM(BK.quantity) as total_booking
whereDate and Carbon::today()->toDateString()
if user id in request parameter then use query methods
get_allevent_by_category
- double where
get_upcomming_events
- whereDate with Carbon::now() with respect to start and end date
get_cities_events
get_organizers||get_customers
$query->select('name', 'id', 'email')
LIKE condition with where and orwhere inside !empty($search)
search_customers
disable_event
get_all_events
get all my evenst for admin using
$query->where and $query->get()
total_event
model with count with or without where
iternary.php
mydiscount.php
insertselect_discount||insert_discount
discount_title.php
get_discountweek||get_discountweek_second
rvsp.php
get_my_bookevents
- use of select
Ticket.php
add_ticket
- at same time update from two model
- update
get_event_tickets
- use of with
- use of where and wherein
get_events_tickets
- whereIn
User.php
all_operator_user
- double where (both condition should be true)
total_customers||total_organizers
- count with where
Oldest comments (0)