SlideShare a Scribd company logo
MySQL triggers in Laravel
(continuare la proceduri stocate)
Vom adauga trigger-ul before insert: BITrigger care va converti la
majuscule toate inregistrarile, inainte de a fi inserate:
php artisan make:migration create_BITrigger_trigger
class CreateBITrigger extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::unprepared('CREATE TRIGGER BITrigger BEFORE INSERT ON flowers FOR EACH ROW
BEGIN
SET NEW.nume=UPPER(NEW.nume);
END');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::unprepared('DROP TRIGGER IF EXISTS BITrigger');
}
}
Daca dorim sa executam fisierele de migrare separat vom crea care un
director pt fiecare procedura(sau trigger). De ex, cream directorul
BITrigger in /database/migrations si mutam in acesta fisierul de migrari
generat pt procedura insert.
Apoi dam comanda:
php artisan migrate –path=/database/migrations/BITrigger
Astfel se va executa numai un fisier de migrare !!!
Pt a executa toate migrarile vom scrie:
php artisan migrate:refresh
php artisan make:migration create_AUTrigger_trigger
class CreateAUTrigger extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::unprepared('CREATE TRIGGER AUTrigger AFTER UPDATE ON flowers FOR EACH ROW
BEGIN
INSERT INTO flowers_updated(nume, status) VALUES(NEW.nume,"UPDATED");
END');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::unprepared('DROP TRIGGER IF EXISTS AUTrigger');
}
}
• Creati directorul AUTrigger in /database/migrations si mutati in
acesta fisierul de migrari care genereaza trigger-ul AUTrigger.
• Pentru a executa migrarea screti:
php artisan migrate --path=/database/migrations/AUTrigger
Al treilea trigger-- AfterDelete
php artisan make:migration create_AfterDelete_trigger
class CreateAUTrigger extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::unprepared(‘CREATE TRIGGER after_Delete AFTER DELETE ON flowers FOR EACH ROW
BEGIN
INSERT INTO flower_update(nume, status, EDTIME) VALUES(OLD.nume,'DELETED', NOW());
END;');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::unprepared('DROP TRIGGER IF EXISTS after_Delete ');
}
}
• Creati directorul ADelete in /database/migrations si mutati in acesta
fisierul de migrari care genereaza trigger-ul AfterDelete.
• Pentru a executa migrarea screti:
php artisan migrate --path=/database/migrations/ADelete
php artisan make:migration create_flower_update_table --create=flower_update
Schema::create('flower_update', function(Blueprint $table)
{
$table->increments('id');
$table->string('nume');
$table->string(‘status');
$table->timestamp(‘EDTIME');
$table->timestamps();
});
• Trigger-ul AuTrigger va fi declansat UpdateFlowers, pe care o vom genera astfel:
php artisan make:migration create_UpdateFlowers_procedure
class CreateUpdateFlowersProcedure extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::unprepared("CREATE PROCEDURE UpdateFlowers(IN var_nume varchar(255))
BEGIN
UPDATE flowers SET pret='10' where nume=var_nume;
END");
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::unprepared('DROP PROCEDURE IF EXISTS UpdateFlowers');
}
}
• Vom afisa datele din flowers_updated cu procedura GetUpdated().
php artisan make:migration create_GetUpdated_procedure
class CreateGetUpdatedProcedure extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::unprepared('CREATE PROCEDURE GetUpdated()
BEGIN
SELECT * FROM flowers_updated;
END');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::unprepared('DROP PROCEDURE IF EXISTS GetUpdated');
}
}
In controller, vom apela procedura astfel:
DB::select('CALL UpdateFlowers("toporasi")');
$flowers3=DB::select('CALL GetUpdated()');
• Trigger-ul AfterDelete va fi declansat de procedura DeleteFlowers(), pe care o vom genera astfel:
php artisan make:migration create_DeleteFlowers_procedure
class CreateDeleteFlowersProcedure extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::unprepared("CREATE PROCEDURE DeleteFlowers(IN var_nume varchar(255))
BEGIN
DELETE FROM flowers where nume=var_nume;
END");
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::unprepared('DROP PROCEDURE IF EXISTS DeleteFlowers');
}
}
php artisan migrate:refresh
Astfel s-au creat toate procedurile si toti triggerii!!!
• In controller, adaugati apelul procedurii:
DB::select('CALL DeleteFlowers("ghiocei")');
FlowersController::index
<?php namespace AppHttpControllers;
use AppFlower;
use DB;
class FlowersController extends Controller {
public function index(){
DB::insert("CALL InsertFlowers('lalele', 'mici','rosii','100')");
DB::insert("CALL InsertFlowers('trandafiri', 'mari','rosii','200')");
DB::insert("CALL InsertFlowers('toporasi', 'mici','albi','150')");
DB::insert("CALL InsertFlowers('ghiocei', 'mici','albi','10')");
$flowers1=DB::select('CALL GetFlowers()');
DB::select('CALL UpdateFlowers("toporasi")');
DB::select('CALL DeleteFlowers("ghiocei")');
$flowers2=DB::select('CALL GetFlower("trandafiri")');
$flowers3=DB::select('CALL GetUpdated()');
return view('pages.flowers')->with([
'title'=>'Flowers data',
'flowers1'=> $flowers1,
'flowers2'=>$flowers2,
'flowers3'=>$flowers3]);
}
}
?>
Modelul app/Flower.php
<?php namespace App;
use IlluminateDatabaseEloquentModel;
use DB;
class Flower extends Model {
protected $table = 'flowers';
//public $timestamps=false;
}
?>
Routes
<?php
Route::get('/', 'FlowersController@index');
?>
/pages/flowers.blade.php
@extends('pages.master')
@section('content')
<h1>Flowers data</h1>
<table>
<tr>
<th>Nume</th>
<th>Culoare</th>
<th>Marime</th>
<th>Pret</th>
</tr>
@foreach($flowers1 as $flower)
<tr>
<td><?php echo $flower->nume;?></td>
<td><?php echo $flower->culoare;?></td>
<td><?php echo $flower->marime;?></td>
<td><?php echo $flower->pret;?></td> </tr>
@endforeach
</table><br/><br/>
<h1>BEGIN SELECT * FROM flowers WHERE nume="trandafiri"</h1>
<table>
<tr>
<th>Nume</th>
<th>Culoare</th>
<th>Marime</th>
<th>Pret</th>
</tr>
@foreach($flowers2 as $flower)
<tr>
<td><?php echo $flower->nume;?></td>
<td><?php echo $flower->culoare;?></td>
<td><?php echo $flower->marime;?></td>
<td><?php echo $flower->pret;?></td> </tr>
@endforeach
</table>
<br/><br/>
<h1>Updated/Deleted data</h1>
<table>
<tr>
<th>Nume</th>
<th>Status</th>
</tr>
@foreach($flowers3 as $flower)
<tr>
<td><?php echo $flower->nume;?></td>
<td><?php echo $flower->status;?></td>
</tr>
@endforeach
</table>
@endsection
/pages/master.blade.php
<!DOCTYPE html>
<html>
<head><title> <?php echo $title;?> </title></head>
<body bgcolor='lightblue'>
@yield('content')
@yield('footer')
</body>
</html>
17.my sql triggers in laravel

More Related Content

What's hot

JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
Designveloper
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
Sunil OS
 
1.ebook 5 hr mahir web company.pdf
1.ebook 5 hr mahir web company.pdf1.ebook 5 hr mahir web company.pdf
1.ebook 5 hr mahir web company.pdf
LeisiSach
 
JQuery UI
JQuery UIJQuery UI
JQuery UI
Gary Yeh
 
Dts x dicoding #1 memulai pemrograman kotlin
Dts x dicoding #1 memulai pemrograman kotlinDts x dicoding #1 memulai pemrograman kotlin
Dts x dicoding #1 memulai pemrograman kotlin
Ahmad Arif Faizin
 
1 z0 047
1 z0 0471 z0 047
Angular
AngularAngular
Angular
LearningTech
 
JEE Course - JEE Overview
JEE Course - JEE  OverviewJEE Course - JEE  Overview
JEE Course - JEE Overview
odedns
 
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Dinesh Neupane
 
KOIN for dependency Injection
KOIN for dependency InjectionKOIN for dependency Injection
KOIN for dependency Injection
Kirill Rozov
 
Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017
Roman Elizarov
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
oracle content
 
Angular Pipes Workshop
Angular Pipes WorkshopAngular Pipes Workshop
Angular Pipes Workshop
Nir Kaufman
 
Exception Handling
Exception HandlingException Handling
Exception Handling
Sunil OS
 
Backup and-recovery2
Backup and-recovery2Backup and-recovery2
Backup and-recovery2
Command Prompt., Inc
 
Architecture java j2 ee a partager
Architecture java j2 ee a partagerArchitecture java j2 ee a partager
Architecture java j2 ee a partager
aliagadir
 
Spring Boot Actuator
Spring Boot ActuatorSpring Boot Actuator
Spring Boot Actuator
Rowell Belen
 
Meta Programming in Groovy
Meta Programming in GroovyMeta Programming in Groovy
Meta Programming in Groovy
NexThoughts Technologies
 
JDBC
JDBCJDBC
JDBC
Sunil OS
 
OpenSIPS Workshop
OpenSIPS WorkshopOpenSIPS Workshop
OpenSIPS Workshop
Saúl Ibarra Corretgé
 

What's hot (20)

JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
 
1.ebook 5 hr mahir web company.pdf
1.ebook 5 hr mahir web company.pdf1.ebook 5 hr mahir web company.pdf
1.ebook 5 hr mahir web company.pdf
 
JQuery UI
JQuery UIJQuery UI
JQuery UI
 
Dts x dicoding #1 memulai pemrograman kotlin
Dts x dicoding #1 memulai pemrograman kotlinDts x dicoding #1 memulai pemrograman kotlin
Dts x dicoding #1 memulai pemrograman kotlin
 
1 z0 047
1 z0 0471 z0 047
1 z0 047
 
Angular
AngularAngular
Angular
 
JEE Course - JEE Overview
JEE Course - JEE  OverviewJEE Course - JEE  Overview
JEE Course - JEE Overview
 
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
 
KOIN for dependency Injection
KOIN for dependency InjectionKOIN for dependency Injection
KOIN for dependency Injection
 
Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Angular Pipes Workshop
Angular Pipes WorkshopAngular Pipes Workshop
Angular Pipes Workshop
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Backup and-recovery2
Backup and-recovery2Backup and-recovery2
Backup and-recovery2
 
Architecture java j2 ee a partager
Architecture java j2 ee a partagerArchitecture java j2 ee a partager
Architecture java j2 ee a partager
 
Spring Boot Actuator
Spring Boot ActuatorSpring Boot Actuator
Spring Boot Actuator
 
Meta Programming in Groovy
Meta Programming in GroovyMeta Programming in Groovy
Meta Programming in Groovy
 
JDBC
JDBCJDBC
JDBC
 
OpenSIPS Workshop
OpenSIPS WorkshopOpenSIPS Workshop
OpenSIPS Workshop
 

Similar to 17.my sql triggers in laravel

«Работа с базами данных с использованием Sequel»
«Работа с базами данных с использованием Sequel»«Работа с базами данных с использованием Sequel»
«Работа с базами данных с использованием Sequel»
Olga Lavrentieva
 
Advanced redux
Advanced reduxAdvanced redux
Advanced redux
Boris Dinkevich
 
To-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step GuideTo-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step Guide
Biztech Consulting & Solutions
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
Siarzh Miadzvedzeu
 
Build your own_map_by_yourself
Build your own_map_by_yourselfBuild your own_map_by_yourself
Build your own_map_by_yourself
Marc Huang
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
Marcus Ramberg
 
Django quickstart
Django quickstartDjango quickstart
Django quickstart
Marconi Moreto
 
Introduction to backbone presentation
Introduction to backbone presentationIntroduction to backbone presentation
Introduction to backbone presentation
Brian Hogg
 
Vitta Minicurso Laravel - Hackathon League of Legends
Vitta Minicurso Laravel - Hackathon League of LegendsVitta Minicurso Laravel - Hackathon League of Legends
Vitta Minicurso Laravel - Hackathon League of Legends
Filipe Forattini
 
Angular and The Case for RxJS
Angular and The Case for RxJSAngular and The Case for RxJS
Angular and The Case for RxJS
Sandi Barr
 
Oracle trigger
Oracle triggerOracle trigger
Oracle trigger
nasrul28
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
Jonathan Wage
 
ABCD firebase
ABCD firebaseABCD firebase
ABCD firebase
옥현 도
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
Fernando Daciuk
 
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Sarp Erdag
 
Add loop shortcode
Add loop shortcodeAdd loop shortcode
Add loop shortcode
Peter Baylies
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gears
dion
 
Migrating data to drupal 8
Migrating data to drupal 8Migrating data to drupal 8
Migrating data to drupal 8
Ignacio Sánchez Holgueras
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
DroidConTLV
 
Talkaboutlithium
TalkaboutlithiumTalkaboutlithium
Talkaboutlithium
noppoman722
 

Similar to 17.my sql triggers in laravel (20)

«Работа с базами данных с использованием Sequel»
«Работа с базами данных с использованием Sequel»«Работа с базами данных с использованием Sequel»
«Работа с базами данных с использованием Sequel»
 
Advanced redux
Advanced reduxAdvanced redux
Advanced redux
 
To-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step GuideTo-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step Guide
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Build your own_map_by_yourself
Build your own_map_by_yourselfBuild your own_map_by_yourself
Build your own_map_by_yourself
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
Django quickstart
Django quickstartDjango quickstart
Django quickstart
 
Introduction to backbone presentation
Introduction to backbone presentationIntroduction to backbone presentation
Introduction to backbone presentation
 
Vitta Minicurso Laravel - Hackathon League of Legends
Vitta Minicurso Laravel - Hackathon League of LegendsVitta Minicurso Laravel - Hackathon League of Legends
Vitta Minicurso Laravel - Hackathon League of Legends
 
Angular and The Case for RxJS
Angular and The Case for RxJSAngular and The Case for RxJS
Angular and The Case for RxJS
 
Oracle trigger
Oracle triggerOracle trigger
Oracle trigger
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
ABCD firebase
ABCD firebaseABCD firebase
ABCD firebase
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
 
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
 
Add loop shortcode
Add loop shortcodeAdd loop shortcode
Add loop shortcode
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gears
 
Migrating data to drupal 8
Migrating data to drupal 8Migrating data to drupal 8
Migrating data to drupal 8
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
Talkaboutlithium
TalkaboutlithiumTalkaboutlithium
Talkaboutlithium
 

More from Razvan Raducanu, PhD

12. edit record
12. edit record12. edit record
12. edit record
Razvan Raducanu, PhD
 
11. delete record
11. delete record11. delete record
11. delete record
Razvan Raducanu, PhD
 
10. view one record
10. view one record10. view one record
10. view one record
Razvan Raducanu, PhD
 
9. add new record
9. add new record9. add new record
9. add new record
Razvan Raducanu, PhD
 
8. vederea inregistrarilor
8. vederea inregistrarilor8. vederea inregistrarilor
8. vederea inregistrarilor
Razvan Raducanu, PhD
 
7. copy1
7. copy17. copy1
6. hello popescu 2
6. hello popescu 26. hello popescu 2
6. hello popescu 2
Razvan Raducanu, PhD
 
5. hello popescu
5. hello popescu5. hello popescu
5. hello popescu
Razvan Raducanu, PhD
 
4. forme in zend framework 3
4. forme in zend framework 34. forme in zend framework 3
4. forme in zend framework 3
Razvan Raducanu, PhD
 
3. trimiterea datelor la vederi
3. trimiterea datelor la vederi3. trimiterea datelor la vederi
3. trimiterea datelor la vederi
Razvan Raducanu, PhD
 
2.routing in zend framework 3
2.routing in zend framework 32.routing in zend framework 3
2.routing in zend framework 3
Razvan Raducanu, PhD
 
1. zend framework intro
1. zend framework intro1. zend framework intro
1. zend framework intro
Razvan Raducanu, PhD
 
18. images in symfony 4
18. images in symfony 418. images in symfony 4
18. images in symfony 4
Razvan Raducanu, PhD
 
17. delete data
17. delete data17. delete data
17. delete data
Razvan Raducanu, PhD
 
16. edit data
16. edit data16. edit data
16. edit data
Razvan Raducanu, PhD
 
15. view single data
15. view single data15. view single data
15. view single data
Razvan Raducanu, PhD
 
14. add data in symfony4
14. add data in symfony4 14. add data in symfony4
14. add data in symfony4
Razvan Raducanu, PhD
 
13. view data
13. view data13. view data
13. view data
Razvan Raducanu, PhD
 
12.doctrine view data
12.doctrine view data12.doctrine view data
12.doctrine view data
Razvan Raducanu, PhD
 
11. move in Symfony 4
11. move in Symfony 411. move in Symfony 4
11. move in Symfony 4
Razvan Raducanu, PhD
 

More from Razvan Raducanu, PhD (20)

12. edit record
12. edit record12. edit record
12. edit record
 
11. delete record
11. delete record11. delete record
11. delete record
 
10. view one record
10. view one record10. view one record
10. view one record
 
9. add new record
9. add new record9. add new record
9. add new record
 
8. vederea inregistrarilor
8. vederea inregistrarilor8. vederea inregistrarilor
8. vederea inregistrarilor
 
7. copy1
7. copy17. copy1
7. copy1
 
6. hello popescu 2
6. hello popescu 26. hello popescu 2
6. hello popescu 2
 
5. hello popescu
5. hello popescu5. hello popescu
5. hello popescu
 
4. forme in zend framework 3
4. forme in zend framework 34. forme in zend framework 3
4. forme in zend framework 3
 
3. trimiterea datelor la vederi
3. trimiterea datelor la vederi3. trimiterea datelor la vederi
3. trimiterea datelor la vederi
 
2.routing in zend framework 3
2.routing in zend framework 32.routing in zend framework 3
2.routing in zend framework 3
 
1. zend framework intro
1. zend framework intro1. zend framework intro
1. zend framework intro
 
18. images in symfony 4
18. images in symfony 418. images in symfony 4
18. images in symfony 4
 
17. delete data
17. delete data17. delete data
17. delete data
 
16. edit data
16. edit data16. edit data
16. edit data
 
15. view single data
15. view single data15. view single data
15. view single data
 
14. add data in symfony4
14. add data in symfony4 14. add data in symfony4
14. add data in symfony4
 
13. view data
13. view data13. view data
13. view data
 
12.doctrine view data
12.doctrine view data12.doctrine view data
12.doctrine view data
 
11. move in Symfony 4
11. move in Symfony 411. move in Symfony 4
11. move in Symfony 4
 

Recently uploaded

RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 

Recently uploaded (20)

RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 

17.my sql triggers in laravel

  • 1. MySQL triggers in Laravel (continuare la proceduri stocate)
  • 2. Vom adauga trigger-ul before insert: BITrigger care va converti la majuscule toate inregistrarile, inainte de a fi inserate:
  • 3. php artisan make:migration create_BITrigger_trigger class CreateBITrigger extends Migration { /** * Run the migrations. * * @return void */ public function up() { DB::unprepared('CREATE TRIGGER BITrigger BEFORE INSERT ON flowers FOR EACH ROW BEGIN SET NEW.nume=UPPER(NEW.nume); END'); } /** * Reverse the migrations. * * @return void */ public function down() { DB::unprepared('DROP TRIGGER IF EXISTS BITrigger'); } }
  • 4. Daca dorim sa executam fisierele de migrare separat vom crea care un director pt fiecare procedura(sau trigger). De ex, cream directorul BITrigger in /database/migrations si mutam in acesta fisierul de migrari generat pt procedura insert. Apoi dam comanda: php artisan migrate –path=/database/migrations/BITrigger Astfel se va executa numai un fisier de migrare !!! Pt a executa toate migrarile vom scrie: php artisan migrate:refresh
  • 5. php artisan make:migration create_AUTrigger_trigger class CreateAUTrigger extends Migration { /** * Run the migrations. * * @return void */ public function up() { DB::unprepared('CREATE TRIGGER AUTrigger AFTER UPDATE ON flowers FOR EACH ROW BEGIN INSERT INTO flowers_updated(nume, status) VALUES(NEW.nume,"UPDATED"); END'); } /** * Reverse the migrations. * * @return void */ public function down() { DB::unprepared('DROP TRIGGER IF EXISTS AUTrigger'); } }
  • 6. • Creati directorul AUTrigger in /database/migrations si mutati in acesta fisierul de migrari care genereaza trigger-ul AUTrigger. • Pentru a executa migrarea screti: php artisan migrate --path=/database/migrations/AUTrigger
  • 7. Al treilea trigger-- AfterDelete
  • 8. php artisan make:migration create_AfterDelete_trigger class CreateAUTrigger extends Migration { /** * Run the migrations. * * @return void */ public function up() { DB::unprepared(‘CREATE TRIGGER after_Delete AFTER DELETE ON flowers FOR EACH ROW BEGIN INSERT INTO flower_update(nume, status, EDTIME) VALUES(OLD.nume,'DELETED', NOW()); END;'); } /** * Reverse the migrations. * * @return void */ public function down() { DB::unprepared('DROP TRIGGER IF EXISTS after_Delete '); } }
  • 9. • Creati directorul ADelete in /database/migrations si mutati in acesta fisierul de migrari care genereaza trigger-ul AfterDelete. • Pentru a executa migrarea screti: php artisan migrate --path=/database/migrations/ADelete
  • 10. php artisan make:migration create_flower_update_table --create=flower_update Schema::create('flower_update', function(Blueprint $table) { $table->increments('id'); $table->string('nume'); $table->string(‘status'); $table->timestamp(‘EDTIME'); $table->timestamps(); });
  • 11. • Trigger-ul AuTrigger va fi declansat UpdateFlowers, pe care o vom genera astfel: php artisan make:migration create_UpdateFlowers_procedure class CreateUpdateFlowersProcedure extends Migration { /** * Run the migrations. * * @return void */ public function up() { DB::unprepared("CREATE PROCEDURE UpdateFlowers(IN var_nume varchar(255)) BEGIN UPDATE flowers SET pret='10' where nume=var_nume; END"); } /** * Reverse the migrations. * * @return void */ public function down() { DB::unprepared('DROP PROCEDURE IF EXISTS UpdateFlowers'); } }
  • 12. • Vom afisa datele din flowers_updated cu procedura GetUpdated(). php artisan make:migration create_GetUpdated_procedure class CreateGetUpdatedProcedure extends Migration { /** * Run the migrations. * * @return void */ public function up() { DB::unprepared('CREATE PROCEDURE GetUpdated() BEGIN SELECT * FROM flowers_updated; END'); } /** * Reverse the migrations. * * @return void */ public function down() { DB::unprepared('DROP PROCEDURE IF EXISTS GetUpdated'); } }
  • 13. In controller, vom apela procedura astfel: DB::select('CALL UpdateFlowers("toporasi")'); $flowers3=DB::select('CALL GetUpdated()');
  • 14. • Trigger-ul AfterDelete va fi declansat de procedura DeleteFlowers(), pe care o vom genera astfel: php artisan make:migration create_DeleteFlowers_procedure class CreateDeleteFlowersProcedure extends Migration { /** * Run the migrations. * * @return void */ public function up() { DB::unprepared("CREATE PROCEDURE DeleteFlowers(IN var_nume varchar(255)) BEGIN DELETE FROM flowers where nume=var_nume; END"); } /** * Reverse the migrations. * * @return void */ public function down() { DB::unprepared('DROP PROCEDURE IF EXISTS DeleteFlowers'); } }
  • 15. php artisan migrate:refresh Astfel s-au creat toate procedurile si toti triggerii!!! • In controller, adaugati apelul procedurii: DB::select('CALL DeleteFlowers("ghiocei")');
  • 16. FlowersController::index <?php namespace AppHttpControllers; use AppFlower; use DB; class FlowersController extends Controller { public function index(){ DB::insert("CALL InsertFlowers('lalele', 'mici','rosii','100')"); DB::insert("CALL InsertFlowers('trandafiri', 'mari','rosii','200')"); DB::insert("CALL InsertFlowers('toporasi', 'mici','albi','150')"); DB::insert("CALL InsertFlowers('ghiocei', 'mici','albi','10')"); $flowers1=DB::select('CALL GetFlowers()'); DB::select('CALL UpdateFlowers("toporasi")'); DB::select('CALL DeleteFlowers("ghiocei")'); $flowers2=DB::select('CALL GetFlower("trandafiri")'); $flowers3=DB::select('CALL GetUpdated()'); return view('pages.flowers')->with([ 'title'=>'Flowers data', 'flowers1'=> $flowers1, 'flowers2'=>$flowers2, 'flowers3'=>$flowers3]); } } ?>
  • 17. Modelul app/Flower.php <?php namespace App; use IlluminateDatabaseEloquentModel; use DB; class Flower extends Model { protected $table = 'flowers'; //public $timestamps=false; } ?>
  • 19. /pages/flowers.blade.php @extends('pages.master') @section('content') <h1>Flowers data</h1> <table> <tr> <th>Nume</th> <th>Culoare</th> <th>Marime</th> <th>Pret</th> </tr> @foreach($flowers1 as $flower) <tr> <td><?php echo $flower->nume;?></td> <td><?php echo $flower->culoare;?></td> <td><?php echo $flower->marime;?></td> <td><?php echo $flower->pret;?></td> </tr> @endforeach </table><br/><br/>
  • 20. <h1>BEGIN SELECT * FROM flowers WHERE nume="trandafiri"</h1> <table> <tr> <th>Nume</th> <th>Culoare</th> <th>Marime</th> <th>Pret</th> </tr> @foreach($flowers2 as $flower) <tr> <td><?php echo $flower->nume;?></td> <td><?php echo $flower->culoare;?></td> <td><?php echo $flower->marime;?></td> <td><?php echo $flower->pret;?></td> </tr> @endforeach </table> <br/><br/> <h1>Updated/Deleted data</h1> <table> <tr> <th>Nume</th> <th>Status</th> </tr> @foreach($flowers3 as $flower) <tr> <td><?php echo $flower->nume;?></td> <td><?php echo $flower->status;?></td> </tr> @endforeach </table> @endsection
  • 21. /pages/master.blade.php <!DOCTYPE html> <html> <head><title> <?php echo $title;?> </title></head> <body bgcolor='lightblue'> @yield('content') @yield('footer') </body> </html>