Search
 
SCRIPT & CODE EXAMPLE
 

PHP

raw query in laravel with parameters

$someVariable = Input::get("some_variable");
$results = DB::select( DB::raw("SELECT * FROM some_table WHERE some_col = :somevariable"), array(
   'somevariable' => $someVariable,
 ));

DB::statement( 'ALTER TABLE HS_Request AUTO_INCREMENT=:incrementStart', array('incrementStart' => 9999) );
Comment

laravel db raw query execute

//true
$cards = DB::select("SELECT * ");

// false
$cards = DB::raw("SELECT * ");
Comment

laravel select raw where

 User::query()
                ->where('users.ban', '!=', 1)
                ->where('users.rights', '=', 1)
                ->leftJoin('users as referal', 'users.id', '=', 'referal.ref_id')
                ->whereNotNull('referal.id')
                ->select([
                    'users.id',
                    'users.name',
                    'users.telegram_id',
                    DB::raw('count(referal.id) as total_referal'),
                    DB::raw("(SELECT COUNT(ac_r.id) FROM users as ac_r WHERE ac_r.ref_id=users.id AND ac_r.ref_bonus = 1) as active_referal"),
                    DB::raw("(SELECT COUNT(ac_r.id) FROM users as ac_r WHERE ac_r.ref_id=users.id AND ac_r.ref_bonus != 1) as no_active_referal"),
                    DB::raw("((SELECT COUNT(ac_r.id) FROM users as ac_r WHERE ac_r.ref_id=users.id AND ac_r.ref_bonus = 1) * ".User::REFERAL_BONUS.") as total_money_referal"),
                ])
                ->groupBy('users.id')
   ->orderByDesc('total_referal')->paginate(100);
Comment

laravel Raw query methods

// whereRaw
$orders = DB::table('orders')
    ->whereRaw('price > IF(state = "TX", ?, 100)', [200])
    ->get();
// havingRaw
Product::groupBy('category_id')->havingRaw('COUNT(*) > 1')->get();
// orderByRaw
User::where('created_at', '>', '2016-01-01')
  ->orderByRaw('(updated_at - created_at) desc')
  ->get();
Comment

raw php laravel

@php
    $counter = 1;
@endphp
Comment

PREVIOUS NEXT
Code Example
Php :: symfony migration down 
Php :: laravel routing techniques 
Php :: Create Model with Controller in Laravel 
Php :: php number format comma and decimal 
Php :: php array flip 
Php :: remove string after comma in php 
Php :: wordpress log errors 
Php :: php replace youtube embed url 
Php :: Display the image on the front end from category taxonomy 
Php :: how to fetch all column values php 
Php :: wordpress add new page programmatically 
Php :: redirect from http to https laravel 
Php :: php mongodb 
Php :: increase php memory 
Php :: laravel 5 use env variable in blade 
Php :: laravel datepicker date format 
Php :: Warning: sprintf(): Too few arguments in /opt/lampp/htdocs/wordpress/wp-admin/includes/class-bulk-upgrader-skin.php on line 152 
Php :: explode php all values to int 
Php :: form validation for file type in codeigniter 
Php :: explode with new line 
Php :: get post in php 
Php :: replace key in php 
Php :: Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1 
Php :: combine 2 columns search query laravel 
Php :: smarty foreach 
Php :: array_column in php 
Php :: php close unclosed HTML Tags 
Php :: in_array validation laravel 
Php :: where with and and or in a laravel 
Php :: wp_cache_get 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =