Live Search Using Laravel - laravel

I can't find any good plugins for a live search using Laravel, does one exist? I've found a few jQuery autocomplete plugins but I'm looking for something like this: https://github.com/iranianpep/ajax-live-search
I tried implementing the above yesterday (for about 10 hours) and couldn't get it to work due to the MySQL queries they use vs Laravel's implementation
any thoughts or information is appreciated
I also tried using a large Laravel query to receive data (I want to search more than one column) but using the
User::where('name', 'like', $query)->orWhere('username', 'like', $query)->etc.
format didn't even match the name for me. Is there such a thing as a more advanced algorithm to search?
Thanks
Zach

Laravel Scout is your answer.
Laravel Scout provides a simple, driver based solution for adding full-text search to your Eloquent models. Using model observers, Scout will automatically keep your search indexes in sync with your Eloquent records.
Currently, Scout ships with an Algolia driver; however, writing custom drivers is simple and you are free to extend Scout with your own search implementations.
I would personally recommend Algolia as well, as it is very sophisticated, has a free entry level, and is better than any search you could come up with by yourself.
You can set the ranking yourself in their backend, it will regard typos made in your search, and so much more. Plus it is cloud powered!
With Laravel Scout any searching is made a breeze just like:
$users = App\User::search('Chris')->get();
What's really cool:
$users = App\User::search('Chrs')->get();
Both $users return the same results. Even with a typo.
For more information you can read up in the official Laravel Scout documentation.
If you are a member of Laracasts, check out these screencasts. And even if you are not, it's really cheap and you will learn a lot on Laravel Scout and live search!

Related

Use whereIn and with in the Eloquent Model of Laravel

I have a relationship as Restaurant has Many Jobs
I have properly set the methods in Restaurant and Jobs model.
I am creating a query where the job.status is in active or upcoming and with that I need restaurant data too.
Below is my code:
Job::whereIn("status", ['upcoming', 'active'])->with(['restaurant'])->get();
with this I am getting restaurant as null
As I am novice in Laravel, I tried the other way around also.
Job::with(['restaurant'])->whereIn("status", ['upcoming', 'active'])->get();
But it gave the same result.
However, if I use where it works properly.
Below is the code which is working and providing restaurant data.
Job::where("end_date_time", '>=', $currentDate->format('Y-m-d H:i:s'))->with(['restaurant'])->get();
I saw the documentation and I found that whereIn is Collections method, so is it something that it will not work if we have with?
I searched on google any example of whereIn and with, but I didn't found any.
May I am doing some conceptual mistake in understanding whereIn and with
Your help is much appreciated.
Thanks.

Missing understanding for pivot tables on Laravel

I know the relationship with table pivot, but i don't understand:
Is the pivot a table that I have to create on my database? Or is it a virtual table that laravel provides to us?!
Beyond that: is better use pivot relationship or use my own third table to relationship many to many?
You will likely only need a pivot table for a Many To Many Relationship, if it is a One to Many you would only need to include a foreign key. However, Laravel is flexible enough to allow you to do whatever you feel like doing as there is no right way to do anything in Laravel.
Personally, I would say it's better to stick to the best practices/conventions as you will find it easier to get help form the community than if you roll your own custom solution that no one else understands.
If you haven't already heard about Laracasts, it's a truly fantastic resource for building things with Laravel. I have been using Laravel for several years now and I still learn new things watching Jeffrey's videos.
If you can't afford the subscription, you can still watch each "What's new in Laravel" for free going back to Laravel 5.0 or further but I don't know how useful they would be. Which should give you a good overview of some of Laravel's best practices and conventions.
Jeffery also has a free series on Learning Vue.js 2 which you should also look into and he'll get to using Vue together with Laravel.

Laravel Search Model

Im new to laravel and have completed a project on the latest version laravel 5.6
However, the only thing that is pending to learn and implement is the search functionality which is the core of every application. The application i have coded is a huge project and i do not want to mess it up so would like to learn how search functionality works in order to implement in multiple sections of the project.
Let's say i have a the following models 1.Country 2.State 3.City 4.Professional_Categories 5.Professionals and i have added the relations in the models accordingly
I fetch the records normally using the following code
public function index()
{
$categories = ProfessionalCategory::all();
$topprofessionals = Professional::where('status', 1)->limit(12)->get()->sortByDesc('page_views');
$professionals = Professional::where('status', 1)->latest()->paginate(9);
return view('professionals.index',compact('professionals', 'categories', 'topprofessionals'));
}
I can pull up Countries, States and Cities as i pulled in categories and with foreach i can display them in the select box. Or i could use pluck('name', 'id') that works good too. But i have never tried search queries.
I want a search form on the professionals page where a user can select country, state, city, category and type keywords in locality and professional name to find the professionals. My next step would be to learn dependent dropdown for country, state and city.
And how the results can be displayed on the view file where im currently fetching records with foreach($professionals as $professional)
I do not need code, but just a basic example on how these kind of things work in laravel. Once i learn the basics i want to implement auto suggest from database and things like that. And a single form to search all the models.
It sounds like you'll need full text searching across a number of tables and associated columns. I'd recommend using Laravel Scout or a similar service (such as elastisearch) for this.
These will index your records in a way to allow for fast and efficient fuzzy searching. Using Scout as an example, you can directly query on your models like:
$orders = App\Order::search('Star Trek')->get();
Searching with Scout
This will save you from writing numerous queries using LIKE which becomes very slow and inefficient quite quickly.
Using Eloquent you might do something like this in your Controller:
public function search(Request $request)
{
$countries = Country::where('name', 'like', '%' . $request->search_value . '%')->get();
}
This will return the countries whose name contains the search_value provided by the user.

Fixed or "frozen" columns in table inside Eclipse Scout

I am interesting into how implement "frozen" columns inside Eclipse Scout table.
I see solution with two tables https://www.eclipse.org/forums/index.php/t/99484/, but I am looking if anyone has different solution, or this is the only one.
Marko
You are looking at what Excel describes as freeze panes?
I afraid there is no support in Scout for this at the moment. You can file a change request in Bugzilla, but without any sponsoring (money or code contribution), it will be hard to implement this.
You can have a look at the approach chosen by Karsten Thoms for the RAP-UI: Scout tables with fixed columns. He uses a custom field (he has extended the default RAP table).
In my opinion, if we include this feature in Scout, it should be a property on each column (frozen = true / false) and not on the table.

Find or create (upsert) functionality in Doctrine 2

Does Doctrine 2 have upsert functionality built in? It doesn't seem to, but I wasn't able to find a definitive yes-or-no answer.
If it does, I would of course be interested to see an example and/or some documentation.
I believe I found the answer. As of today (10/15/2012), there's an open "add upsert support" issue for Doctrine. I assume that this ticket wouldn't still be open if Doctrine 2 did have upsert support, so I guess there's my definitive answer.
Upsert is already present in Doctrine.
Using the query builder, you have to set findAndUpdate() and returnNew() if you want to return the document. Set upsert() and you're ready to go.
For example:
$documentMannager->createQueryBuilder('App\Domain')
->findAndUpdate()
->returnNew()
->field('_id')->equals($id)
->field('page')->equals($page)
->field('count')->inc(1)
->upsert()
->getQuery()
->execute();
This is the way i implement a bucket pattern.

Resources