Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel eloquent search query 2020

$result = Marriage::where('name','LIKE','%'.$email_or_name.'%')
                ->orWhere('email','LIKE','%'.$email_or_name.'%')
                ->get();
Comment

laravel create search

public function index(){
      // // we need to show all data from "blog" table
      // $blogs = Blog::all();
      // // show data to our view
      // return view('blog.index',['blogs' => $blogs]);

      $search = Request::get('search');
      $blogs = Blog::where('title','like','%'.$search.'%')->orderBy('id')->paginate(6);
      return view('blog.index',['blogs' => $blogs]);
    }
Comment

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 Search

// Why do this ..
$users=User :: where(function($query)use($value){
    $query->orWhere('name','like',"{$value)")
          ->orWhere('email','like',"{$value}")
          ->orWhere('title','like',"{$value}")
          ->orWhere('role','like',"{$value}%")
          ->orWhere('status','like',"{$value}%")
})->get();
//...when you can do the same with this?
$users User :: search($value)->get();
Comment

search laravel

// Employee Model
public function searchResult($search)
{
  $query = DB::table("employee") ->where('employee_name', 'LIKE', '%'.$search.'%')->get();
  return $query;
}
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 search function

$users = User::has('posts')->withCount('posts')->orderBy('posts_count')->take(50)->get();

$userIndex = $users->search(function($user) {
    return $user->id === Auth::id();
});
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 find query

$model = AppModelsFlight::where('legs', '>', 100)->firstOr(function () {
        // ...
});
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 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 :: laravel tree category 
Php :: Add ... if string is too long PHP 
Php :: php curl request 
Php :: laravel 6 tymon/jwt-auth 
Php :: array_push 
Php :: filter_var filter_validate_url 
Php :: get post by name wordpress 
Php :: php server function 
Php :: update laravel .env variables dynamically 
Php :: wordpress get order 
Php :: action after model is created laravel 
Php :: laravel drop foreign key 
Php :: htmlspecialchars (PHP 4, PHP 5, PHP 7, PHP 8) htmlspecialchars — Convert special characters to HTML entities 
Php :: how to run multiple seeder at a time in laravel 
Php :: foreach in laravel 
Php :: if condition in smarty 
Php :: php get part of string 
Php :: laravel 8 eloquent orderby 
Php :: php ternary shorthand 
Php :: how to add javascript in php 
Php :: laravel hasmany relationship 
Php :: php extend parent constructor 
Php :: laravel without global scopes 
Php :: <?php /* vim: set expandtab sw=4 ts=4 sts=4: */ /** * Main loader script * * @package PhpMyAdmin */ declare(strict_types=1); 
Php :: doctrine query builder order by multiple 
Php :: how to clear session in laravel 
Php :: Best debugging tools for php 
Php :: php is_int 
Php :: wp_get_attachment_url 
Php :: php check if associative array 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =