Laravel Laravel 4 ElasticSearch PHP Search
Simple Search with Laravel and ElasticSearch
I was recently asked to make a search engine for a client's website. Normally I would go down the MySQL fulltext search route but I was feeling rather adventurous at the time. I had no experience with ElasticSearch, Apache Solr or any other search system prior to this so I decided to pick ElasticSearch and dive in head first. This tutorial is a result of some of the things I picked up while learning it. I aim to show you how to set up the Elasticquent Laravel package and some basic ways to fine tune your search engine.
Laravel 4 Laravel PHP Eloquent
Laravel 4.1 one-to-one polymorphic relationships
To use one-to-one polymorphic relationships in Laravel 4.1 use the "morphOne" method in your models. For example: I have two tables, pages and products. I want to be able to add one featured image to each of these. The Product model would look like this: <?php class Product extends Eloquent { public function image() { return $this->morphOne('FeaturedImage', 'imageable'); } } The Page model would be: <?php class Page extends Eloquent { public function image() { return $this->morphOne('FeaturedImage', 'imageable'); } }