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

eloquent where raw

$query->whereRaw("(
        LOWER(name)             like '%". strtolower($search) ."%' OR
        LOWER(sku)              like '%". strtolower($search) ."%' OR
        LOWER(codigo)           like '%". strtolower($search) ."%' OR
        LOWER(descricao_curta)  like '%". strtolower($search) ."%'
    )");
Comment

eloquent where raw

/*
whereRaw / orWhereRaw
The whereRaw and orWhereRaw methods can 
be used to inject a raw "where" clause into your query. 
These methods accept an optional array of bindings as their second argument:
*/
$orders = DB::table('orders')
                ->whereRaw('price > IF(state = "TX", ?, 100)', [200])
                ->get();
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 :: update column value laravel 
Php :: drupal 7 hook_node_update 
Php :: php new PDO timeout 
Php :: laravel migrations generator laravel 
Php :: php undefined function mysqli_fetch_all() 
Php :: php super 
Php :: php add array to array 
Php :: laravel switch 
Php :: Laravel 8 Pagination Ui Problem 
Php :: get category of current post wordpress 
Php :: foreign key in laravel 9 
Php :: https://www.60d48b1061adf.site123/wp-login.php 
Php :: laravel local scope 
Php :: curl error (code 3) url malformed laravel 
Php :: ternaire echo isset php 
Php :: class php 
Php :: setcookie in php 
Php :: luhn algorithm credit card checker php 
Php :: php stop loading page 
Php :: seprate day and year from laravel to timestamp 
Php :: laravel one session per user 
Php :: get file request in laravel 
Php :: remove more than one space in string php 
Php :: how hide empty category wordpress woocommerce 
Php :: rewrite url to exclude php extension 
Php :: laravel eloquent get fillable 
Php :: bagisto package generator 
Php :: laravel form validation based on another field value 
Php :: laravel scheduler on shared hosting 
Php :: php split array into chunks 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =