title: How to use triggers in laravel?
body: <p>My code, using PHP artisan make: migration create_trigger command</p>
  
  <pre><code>public function up()
  {
    DB::unprepared(' 
    CREATE TRIGGER roll_no BEFORE INSERT ON `students` FOR EACH ROW 
    BEGIN 
    SET @roll_num = IFNULL((substring((SELECT student_roll_no FROM students WHERE
      class_code = NEW.class_code ORDER BY created_at DESC LIMIT 1),-2) + 1), `1`),
      NEW.student_roll_no = CONCAT(
      YEAR(CURRENT_DATE),
      NEW.class_code,
      IF (@roll_num &lt; 10, CONCAT(`0`, @roll_num), @roll_num) 
    )
    END;
    ');
  }
  </code></pre>