Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel db query

$users = DB::table('users')
            ->where('votes', '>', 100)
            ->orWhere(function($query) {
                $query->where('name', 'Abigail')
                      ->where('votes', '>', 50);
            })
            ->get();
Comment

laravel elequent query

Model::where(function ($query) {
    $query->where('a', '=', 1)
          ->orWhere('b', '=', 1);
})->where(function ($query) {
    $query->where('c', '=', 1)
          ->orWhere('d', '=', 1);
});
Comment

Laravel when query

$query = Author::query();

$query->when(request('filter_by') == 'likes', function ($q) {
    return $q->where('likes', '>', request('likes_amount', 0));
});
$query->when(request('filter_by') == 'date', function ($q) {
    return $q->orderBy('created_at', request('ordering_rule', 'desc'));
});

$authors = $query->get();
Comment

laravel find query

// Retrieve a model by its primary key...
$flight = AppModelsFlight::find(1);

// Retrieve the first model matching the query constraints...
$flight = AppModelsFlight::where('active', 1)->first();

// Shorthand for retrieving the first model matching the query constraints...
$flight = AppModelsFlight::firstWhere('active', 1);
Comment

laravel find query

php artisan make:model Flight --migration

php artisan make:model Flight -m
Comment

laravel find query

return Destination::orderByDesc(
    Flight::select('arrived_at')
        ->whereColumn('destination_id', 'destinations.id')
        ->orderBy('arrived_at', 'desc')
        ->limit(1)
)->get();
Comment

laravel find query

<?php

namespace AppModels;

use IlluminateDatabaseEloquentModel;

class Flight extends Model
{
    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'flight_id';
}
Comment

laravel find query

foreach (Flight::where('foo', 'bar')->cursor() as $flight) {
    //
}
Comment

laravel query when

$users = DB::table('users')
                ->when($role, function ($query, $role) {
                    $query->where('role_id', $role);
                })
                ->get();
Comment

query builder laravel

use IlluminateDatabaseEloquentBuilder;

public function scopeFakePersons(Builder $query): Builder
{
  return $query->where('is_fake', 1);
}
Comment

laravel where in query builder

public function index()
{
    $users = User::select("*")
                    ->whereIn('id', [4, 5, 6])
                    ->get();
  
    dd($users);                    
}
Comment

LARAVEL QUERY

<?php

Route::get('games', function () {
    
    $games = DB::table('games')->get();
    
    return view('games', ['games' => $games]);
});
Comment

laravel find query

$model = AppModelsFlight::where('legs', '>', 100)->firstOr(function () {
        // ...
});
Comment

How to write this query in Laravel Eloquent

Visitor::select('country')
     ->withCount('id')
     ->groupBy('country')
     ->latest()
     ->get()
  
  //or
  
  Visitor::query()->groupBy('country')->orderByDesc('count')->select('country' ,DB::raw('COUNT(1) as count'))->get()
Comment

laravel find query

<?php

$flights = AppModelsFlight::all();

foreach ($flights as $flight) {
    echo $flight->name;
}
Comment

laravel find query

<?php

namespace AppModels;

use IlluminateDatabaseEloquentModel;

class Flight extends Model
{
    /**
     * The connection name for the model.
     *
     * @var string
     */
    protected $connection = 'connection-name';
}
Comment

laravel find query

foreach ($flights as $flight) {
    echo $flight->name;
}
Comment

Laravel query

//select specified colomns from all users
Employee::get(['name','email','title']);
Comment

laravel find query

use AppModelsDestination;
use AppModelsFlight;

return Destination::addSelect(['last_flight' => Flight::select('name')
    ->whereColumn('destination_id', 'destinations.id')
    ->orderBy('arrived_at', 'desc')
    ->limit(1)
])->get();
Comment

PREVIOUS NEXT
Code Example
Php :: php check if type is mysqli_result 
Php :: Laravel htaccess for aws ec2 
Php :: str_contains php 5 
Php :: laravel check if model has relation 
Php :: laravel roles and permissions 
Php :: view blob phpmyadmin 
Php :: READIMAGE FUNCTION PHP 
Php :: mysql between all months days even null 
Php :: woocommerce_recently_viewed 
Php :: readable date in php 
Php :: Laravel unique Validation with multiple input value 
Php :: isset in php 
Php :: magento 2 add in static block 
Php :: symfony get api data 
Php :: php remove html tag wrap 
Php :: array_push php 
Php :: debugbar:clear in laravel 
Php :: workpress change page title from shortcode 
Php :: many to many relationship laravel 
Php :: Update Data Multiple Columns MySql Database Table PHP Function 
Php :: generate a unique id 
Php :: cakephp find_in_set 
Php :: CODEIGNITER codeigniter 4 auth 
Php :: create model for existing table in laravel 
Php :: laravel relationship retrieve data 
Php :: laravel env use other env variables 
Php :: laravel skip a loop if error 
Php :: compare key and one array 
Php :: public $baseURL codeigniter 4 
Php :: create services in laravel with command line 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =