Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel search query

  // SEARCH QUERY
  if (request()->has('search')){
      $search = trim(request('search'));
      $resumess = $resumess->where(function($query) use ($search){
          $query->where('doc_name', 'LIKE', "%{$search}%");
          $searches = explode(" ",$search);
          foreach($searches as $s){
              $query->orWhere('first_name', 'LIKE', "%{$s}%");
              $query->orWhere('last_name', 'LIKE', "%{$s}%");
              $query->orWhere('position_type', 'LIKE', "%{$s}%");
              $query->orWhere('position_type', 'LIKE', "%{$s}%");
          }
      });
  }
Comment

search query in laravel

$searchTerm ='milad zamir Abc';
$reservedSymbols = ['-', '+', '<', '>', '@', '(', ')', '~'];
$searchTerm = str_replace($reservedSymbols, ' ', $searchTerm);

$searchValues = preg_split('/s+/', $searchTerm, -1, PREG_SPLIT_NO_EMPTY);

$res = User::where(function ($q) use ($searchValues) {
	foreach ($searchValues as $value) {
    $q->orWhere('name', 'like', "%{$value}%");
    $q->orWhere('family_name', 'like', "%{$value}%");
    }
})->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 search query

public function index()
{
  $q = Dog::query();

  if (Input::has('search'))
  {
     // simple where here or another scope, whatever you like
     $q->where('name','like',Input::get('search'));
  }

  if (Input::has('search-breed'))
  {
     $q->searchBreed(Input::get('search-breed'));
  }

  if (Input::has('sex'))
  {
     $q->where('sex', Input::get('sex'));
  }

  if (Input::has('radius'))
  {
     $q->withinRadius(Input::get('radius'));
  }

  $dogs = $q->orderBy(..)->paginate(5);

  // ...
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 "query()->find"

The find Method
If you are overriding the find method in your own models and calling parent::find() within your custom method, you should now change it to call the find method on the Eloquent query builder:

public static function find($id, $columns = ['*'])
{
    $model = static::query()->find($id, $columns);

    // ...

    return $model;
}
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

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 :: codeigniter apache remove index.php 
Php :: Expected response code 250 but got code "530", with message "530 Must issue a STARTTLS command first. " 
Php :: current date time in php for input 
Php :: heroku mysql 
Php :: laravel run controller from command line 
Php :: php string filter email 
Php :: ? in php 
Php :: php boolean 
Php :: wordpress programmatically change slug of media attachment site:wordpress.stackexchange.com 
Php :: php pretty json 
Php :: store a variable in session and echo that variable on a page wordpress 
Php :: laravel validation alphanumeric with spaces 
Php :: json decode php array 
Php :: Syntax error or access violation: 1055 
Php :: schema add column laravel 
Php :: convert string to int php 7 
Java :: java create window 
Java :: how to learn java in one day 
Java :: java main 
Java :: how to loop through code 3 times java 
Java :: java program to calculate age from date of birth 
Java :: flutter Uri toString and String to Uri 
Java :: java selenium new empty tab 
Java :: how to set checkbox size in android 
Java :: input double java 
Java :: java close jframe 
Java :: guess the number java 
Java :: icon button java 
Java :: set location of a label java 
Java :: fullscreen java jframe 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =