Implementing Full-Text search in Laravel 4


/ Published in: PHP
Save to your folder(s)

In this tutorial I will go over implementing Full-Text search in Laravel 4 .
Those who have used Laravel 3 in the past may remember that there used to be support for FULLTEXT indexes. This functionality has been removed in Laravel 4 but can still easily be implemented.


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. use Illuminate\Database\Migrations\Migration;
  4. use Illuminate\Database\Schema\Blueprint;
  5.  
  6. class CreatePostsTable extends Migration {
  7.  
  8. /**
  9. * Run the migrations.
  10. *
  11. * @return void
  12. */
  13. public function up()
  14. {
  15. Schema::create('posts', function(Blueprint $table) {
  16. $table->engine = 'MyISAM'; // means you can't use foreign key constraints
  17. $table->increments('id');
  18. $table->string('title');
  19. $table->text('body');
  20. $table->timestamps();
  21. });
  22.  
  23. DB::statement('ALTER TABLE posts ADD FULLTEXT search(title, body)');
  24. }
  25.  
  26. /**
  27. * Reverse the migrations.
  28. *
  29. * @return void
  30. */
  31. public function down()
  32. {
  33. Schema::table('posts', function($table) {
  34. $table->dropIndex('search');
  35. });
  36. Schema::drop('posts');
  37. }
  38.  
  39. }

URL: http://creative-punch.net/implementing-laravel-4-full-text-search/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.