How to add mysql trigger from migrations in Laravel 5?

By Hardik Savani | March 8, 2016 | Category : PHP Laravel MySql

Sometimes you require to add trigger in your mysql database of laravel 5. but you think how to create trigger using laravel migration because laravel not provide special function like insertTrigger and something so it problem to create direclty, But laravel DB::unprepared() through we can create trigger for database.

In Following example you can see how to create migration and create trigger code and how to write drop trigger code, so let's do it this way.

Create Migration:

php artisan make:migration add_trigger


use Illuminate\Database\Schema\Blueprint;

use Illuminate\Database\Migrations\Migration;

class AddTrigger extends Migration


public function up()


DB::unprepared('CREATE TRIGGER add_Item_city AFTER INSERT ON `items` FOR EACH ROW


INSERT INTO `items_city` (`item_id`) VALUES (;



public function down()


DB::unprepared('DROP TRIGGER `add_Item_city`');



Run Migration:

php artisan migrate

Try this....

Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.