Laravel Searching multiple tables with one query

Today, We want to share with you Laravel Searching multiple tables with one query.In this post we will show you wordpress plugin require another plugin, hear for laravel eloquent join 3 tables we will give you demo and example for implement.In this post, we will learn about how to fetch data from multiple table in laravel with an example.

Laravel Searching multiple tables with one query

There are the Following The simple About Laravel Search in multiple tables Full Information With Example and source code.

READ :  Vuejs Form Input Bindings - vuejs form component-Vuejs-Form

As I will cover this Post with live Working example to develop Searching multiple tables with one query with Laravel, so the Searching through multiple table using laravel eloquent is used for this example is following below.

laravel 6 search engine Examples

Searching through multiple table using laravel eloquent
[php]
$products = Tamilrokers::whereHas(‘bollywood’, function($query) use($querystr) {
$query->where(‘bollywood_name’, ‘like’, ‘%’.$querystr.’%’);
})->orWhere(‘movie_name’,’LIKE’,’%’.$querystr.’%’)->orderBy($order, ‘asc’)->get();
[/php]

Search multiple tables for a search term in Laravel
[php]
Album::where(‘title’, ‘LIKE’, ‘%’ .$querystr. ‘%’)
->orWhereHas(‘students’, function($q) use ($querystr) {
return $q->where(‘name’, ‘LIKE’, ‘%’ . $querystr . ‘%’);
})
->orWhereHas(‘teachers’, function($q) use ($querystr) {
return $q->where(‘title’, ‘LIKE’, ‘%’. $querystr . ‘%’);
})->get();
[/php]

Using Joins in Laravel Eloquent Queries
[php]
$productCategory = Tamilrokers::where(‘id’, $moviId)
->leftJoin(‘bollywood’, ‘movies.bollywood’, ‘=’, ‘bollywood.id’)
->select(‘movies.id’,’bollywood.name’)->first();
[/php]

READ :  Laravel Eloquent Join Multiple Table

Laravel search from two tables

[php]
$licenses = Tamilrokers::where(‘pname’,’like’,’%’.$querystr.’%’)
->orWhere(‘licenseNumber’,’like’,’%’.$querystr.’%’)
->orWhereHas(‘client’, function ($query) use ($querystr) {
$query->where(‘name’, ‘like’, ‘%’.$querystr.’%’);
})
->orderBy(‘id’)
->paginate(20);
[/php]

Laravel search DB with multiple tables

[php]
// Get the teacher ID
$teacher = DB::table(‘students’)
->select(DB::raw(‘CONCAT_WS(” “,`firstname`,`lastname`) as `fullname`,id’))
->having(‘fullname’, ‘LIKE’, ‘%’.$querystr.’%’)
->first();

// $teacher output:
stdClass Object
(
[fullname] => Modi Narendra
[id] => 58
)

// Query the records using the gathered ID
$records->where(‘stud_id’, $teacher->id)
->orWhere(‘title’, ‘LIKE’, ‘%’.$querystr.’%’);
[/php]

Search in multiple tables by eloquent query
[php]
$results = DB::query(‘SELECT id, title FROM (
SELECT id, title,info_member FROM `members` where `info_member` LIKE “%’.$querystr.’%” OR `title_en` LIKE “%’.$querystr.’%”
UNION ALL
SELECT id, info_client FROM `clients` where `info_client` LIKE “%’.$querystr.’%” OR `content` LIKE “%’.$querystr.’%”
) temp_table
ORDER BY `id` desc
LIMIT 0, 10
‘)
[/php]

READ :  What Is the Distinction Between Fiat and Cryptocurrency?
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about laravel eloquent join 2 tables.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment