1. Go to this page and download the library: Download va/cutlet-migrate library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
## Write a function:
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CutletFunction extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
\Illuminate\Support\Facades\DB::unprepared("
DROP FUNCTION IF EXISTS function_name;
CREATE FUNCTION function_name(
param1 INT,
param2 INT,
..
)
RETURNS datatype
[NOT] DETERMINISTIC
BEGIN
-- statements
END
");
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
\Illuminate\Support\Facades\DB::unprepared("
DROP FUNCTION if EXISTS function_name;
");
}
}
## Write a procedure:
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CutletProcedure extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
\Illuminate\Support\Facades\DB::unprepared("
DROP PROCEDURE IF EXISTS procedure_name;
CREATE PROCEDURE procedure_name(
IN param1 INT,
IN param2 INT,
..
)
BEGIN
-- statements
END
");
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
\Illuminate\Support\Facades\DB::unprepared("
DROP PROCEDURE IF EXISTS procedure_name;
");
}
}
## Write a trigger:
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CutletTrigger extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
\Illuminate\Support\Facades\DB::unprepared("
DROP TRIGGER IF EXISTS trigger_name;
CREATE TRIGGER trigger_name
{BEFORE | AFTER} {INSERT | UPDATE| DELETE }
ON table_name FOR EACH ROW
-- trigger_body;
");
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
\Illuminate\Support\Facades\DB::unprepared("
DROP TRIGGER IF EXISTS trigger_name;
");
}
}
## Write a view:
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CutletView extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
\Illuminate\Support\Facades\DB::unprepared("
DROP VIEW IF EXISTS view_name;
CREATE [OR REPLACE] VIEW [db_name.]view_name [(column_list)]
AS
-- select-statement;
");
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
\Illuminate\Support\Facades\DB::unprepared("
DROP VIEW IF EXISTS view_name;
");
}
}
## Use functions:
$cutlet = DB::select('select cutletFunction(?,?) as cutletField', [$request->param1, $request->param2]);
// or ..
## Use procedures
$cutlets = DB::select('call cutletProcedure(?)', [$request->param1]);
or ..
## Use triggers:
// It's execute auto in mysql level
## Use views:
$cutlets = DB::table('cutletView');
php artisan vendor:publish --tag=cutlet-migrate
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.