Полное руководство по Laravel Search

Вы можете найти  метод поиска коллекции внутри  класса  Illuminate\Support\Collection  .

Ларавель поиск

Laravel search() — это встроенный метод коллекций , который используется для поиска в коллекции заданного значения. Если значение присутствует в коллекции, возвращается ключ значения. Если значение не соответствует ни одному элементу,  возвращается false . Поиск осуществляется с использованием «свободного» сравнения, то есть строка с целочисленным значением будет считаться равной целому числу того же значения.

Чтобы использовать «строгое» сравнение, мы должны передать true в качестве второго аргумента метода. 

public function search($value, $strict = false)
{
     if (! $this->useAsCallable($value)) {
         return array_search($value, $this->items, $strict);
     }

     foreach ($this->items as $key => $item) {
         if (call_user_func($value, $item, $key)) {
             return $key;
         }
     }

     return false;
}

Под капотом метод поиска коллекции() вызывает метод array_search()  .

См. следующий пример.

Напишите следующий код в  файле route >> web.php  .

<?php

// web.php

Route::get('/', function () {
    $collection = collect([21, 19, 46, 29]);

    echo $collection->search(19)."\n";

});

Теперь запустите проект laravel, и вы увидите следующий вывод 1. Это означает, что в массиве есть 19, и его ключ равен 1, который возвращается.

Теперь давайте искать со  строгим сравнением. См. следующий код.

<?php

// app.php

Route::get('/', function () {
    $collection = collect([21, 19, 46, 29]);
    echo $collection->search('19', true);
});

Вывод будет ложным, потому что мы ищем  19  как строку, а не целое число, и мы проверяем в строгом режиме, потому что мы передали второй параметр как  истину.

В качестве альтернативы вы можете передать свой обратный вызов для поиска первого элемента, который проходит ваш тест на истинность. Он вернет индекс первого элемента в качестве вывода. См. следующий код.

<?php

// app.php

Route::get('/', function () {
    $collection = collect([19, 21, 46, 29]);
    echo $collection->search(function($item, $key) {
        return $item > 19;
    });
});

В приведенном выше коде мы проверяем, чтобы каждый элемент коллекции был > 19. Теперь 21 — это первый элемент, который > 21, и его индекс равен 1. Таким образом, на выходе будет 1.

Ссылка: https://appdividend.com/2022/06/25/laravel-collections-search/

#laravel #php

What is GEEK

Buddha Community

Полное руководство по Laravel Search

I am Developer

1597475640

Laravel 7 Full Text Search MySQL

Here, I will show you how to create full text search in laravel app. You just follow the below easy steps and create full text search with mysql db in laravel.

Laravel 7 Full Text Search Mysql

Let’s start laravel full-text search implementation in laravel 7, 6 versions:

  1. Step 1: Install Laravel New App
  2. Step 2: Configuration DB .evn file
  3. Step 3: Run Migration
  4. Step 4: Install Full Text Search Package
  5. Step 5: Add Fake Records in DB
  6. Step 6: Add Routes,
  7. Step 7: Create Controller
  8. Step 8: Create Blade View
  9. Step 9: Start Development Server

https://www.tutsmake.com/laravel-full-text-search-tutorial/

#laravel full text search mysql #laravel full text search query #mysql full text search in laravel #full text search in laravel 6 #full text search in laravel 7 #using full text search in laravel

Seamus  Quitzon

Seamus Quitzon

1595201363

Php how to delete multiple rows through checkbox using ajax in laravel

First thing, we will need a table and i am creating products table for this example. So run the following query to create table.

CREATE TABLE `products` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 `description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

Next, we will need to insert some dummy records in this table that will be deleted.

INSERT INTO `products` (`name`, `description`) VALUES

('Test product 1', 'Product description example1'),

('Test product 2', 'Product description example2'),

('Test product 3', 'Product description example3'),

('Test product 4', 'Product description example4'),

('Test product 5', 'Product description example5');

Now we are redy to create a model corresponding to this products table. Here we will create Product model. So let’s create a model file Product.php file under app directory and put the code below.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $fillable = [
        'name','description'
    ];
}

Step 2: Create Route

Now, in this second step we will create some routes to handle the request for this example. So opeen routes/web.php file and copy the routes as given below.

routes/web.php

Route::get('product', 'ProductController@index');
Route::delete('product/{id}', ['as'=>'product.destroy','uses'=>'ProductController@destroy']);
Route::delete('delete-multiple-product', ['as'=>'product.multiple-delete','uses'=>'ProductController@deleteMultiple']);

#laravel #delete multiple rows in laravel using ajax #laravel ajax delete #laravel ajax multiple checkbox delete #laravel delete multiple rows #laravel delete records using ajax #laravel multiple checkbox delete rows #laravel multiple delete

Juned Ghanchi

1621508419

Laravel App Development Company in India, Hire Laravel Developers

Hire our expert team of Laravel app developers for flexible PHP applications across various cloud service providers.

With this easy build technology, we develop feature-rich apps that make your complex business process a lot easier. Our apps are,

  • More secure and scalable.
  • A good framework lets you manage and organize resources better.
  • And have a rich community base.

Get your business a best in classlaravel app. Hire laravel app developers in India. We have the best organizational set-up to provide you the most advanced app development services.

#laravel app development company india #hire laravel developers india #laravel app development company #hire laravel developers #laravel development agency #laravel app programmers

mehul bagada

mehul bagada

1592972324

Laravel Autocomplete Search With Jquery UI Example

Hi Guys,

In this Example,I will learn you how to use autocomplete search with jquery ui in laravel.you can easy and simply use autocomplete serach with jquery ui in laravel.

you can add to text search box then related text to get in your datatable.I show how you add jQuery UI autocomplete to the input field in the Laravel project.

Link :- https://www.nicesnippets.com/blog/laravel-autocomplete-search-with-jquery-ui-example

#laravel #laravel tutorial #laravel tutorial for beginner #learn laravel #learn laravel for free

Liz  Fernandes

Liz Fernandes

1670234150

Best Laravel Development Company

In the present world, PHP is a well-liked framework. Laravel is one of the most well-known frameworks out there. The popularity of Laravel is due to its expressiveness, flexibility, good controllers, strength, seamless caching, and time savings when handling tasks like routing, authentication, sessions, and many more.

Laravel is a PHP framework that everyone who knows PHP should be familiar with. The Laravel PHP framework is simple to learn and use, but it is packed with useful features. Despite rising market competition, many developers consider Laravel to be one of the best PHP frameworks available.

WPWeb Infotech is a top Laravel development company in India and the US since 2015. They develop reliable, scalable Laravel web and mobile apps using Ajax-enabled widgets, MVC patterns, and built-in tools. WPWeb Infotech has top-notch expertise in combining a variety of front- and back-end technologies like Laravel + VueJS, Laravel + Angular, and Laravel + ReactJS to create scalable and secure web architectures, so you don't have to worry about scalability and flexibility while developing your product. They understand business scale and recommend technology that fits. Agile experts reduce web and mobile app development time and risk.

When it comes to hiring Laravel developers from India, they are the best choice because their Laravel developers can work according to your time zone to provide you with hassle-free, innovative, and straightforward web development solutions. Being the most trusted Laravel development company in India, they can help you reach new heights of success, unleashing the power of the Laravel PHP framework.

Partner with one of India’s best Laravel Development Company and get the most expertise in Laravel development.

#laravel  #laravel-development #laravel-development-company #laravel-development-services #hire-laravel-developers