Try this?
DB::statement('ALTER TABLE products ADD FULLTEXT fulltext_index(name, description)');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
The last days I've been trying to figure out how to implement a full text search in my Laravel 4.1 application.
I found that full text search is available in InnoDB from mysql version 5.6 and above. I am currently running mysql 5.6.15 on my localhost configuration and having problems to get this working.
I have three tables declared (category, brand, product), all of them set to InnoDB engine. In my products migration table I have set:
DB::statement('ALTER TABLE `products` ADD FULLTEXT search(name, description)');
Initially I've tried to run a query on the products table which matches the search terms against the name and description fields on products table. I have a ProductsSearchService that has a search function like so to run that query:
public function search($data = array()) {
$exp = explode(' ', $data);
$s = '';
$c = 1;
foreach ($exp as $e)
{
$s .= "+$e*";
if ($c + 1 == count($exp))
$s .= ' ';
$c++;
}
$query = "MATCH (name, description) AGAINST ('$s' IN BOOLEAN MODE)";
$products = Product::whereRaw($query)->get();
return $products;
}
Although, this returns with an error if the table's engine is InnoDB:
SQLSTATE[HY000]: General error: 1191 Can't find FULLTEXT index matching the column list (SQL: select * from `products` where MATCH (name, description) AGAINST ('+product*' IN BOOLEAN MODE))
The above error is gone if I change my table's default engine to MYISAM. Additionally, the categories and brands table are connected to the products table with foreign keys.
1. Since MYISAM does not support foreign keys how can I get this to work?
2. Also, is there a way to adjust the search query so that it will match these two tables as well (categories and brands)?
Yeah I don't think it's possible to full text search across two tables but I haven't looked into it that much. Maybe use a dedicated search tool? (Sphinx etc)
Please or to participate in this conversation.