PHP code example of fatihirday / suffix
1. Go to this page and download the library: Download fatihirday/suffix 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/ */
fatihirday / suffix example snippets
return [
'suffixes' => [
'table' => \Fatihirday\Suffixed\Models\Suffix::class,
'column' => 'code',
'auto_create_suffixed_tables' => true,
],
'suffix_auto_check' => true,
'merge_operator' => '_',
'suffix_max_length' => 3,
];
class Suffix extends Model
{
use HasFactory, SuffixList;
}
$row = new \Fatihirday\Suffixed\Models\Suffix();
$row->name = 'Fatih';
$row->code = 'fth';
$row->save();
class CreateDenemeTable extends SuffixMigration implements SuffixSchame
{
protected $baseTableName = 'demo';
public function upSuffix(string $tableName, string $prefix)
{
Schema::create($tableName, function (Blueprint $table) use ($prefix) {
$table->id();
$table->string('name', 30);
$table->timestamps();
});
}
public function downSuffix(string $tableName, string $prefix)
{
Schema::dropIfExists($tableName);
}
}
class Demo extends Model
{
use HasFactory, Suffixed;
}
App\Models\Demo::checkSuffixCode('fth');
// Response : true || false
App\Models\Demo::setSuffixCode('fth')->toSql();
// Response : "select * from `demo_fth`"
App\Models\Demo::setSuffixCode('fth')->getTable();
// Response : "demo_fth"
App\Models\Demo::setSuffixCode('fth')->getSuffixCode();
// Response : "fth"
// insert row to demo_fth table
$newRow = App\Models\Demo::setSuffixCode('fth');
$newRow->name = 'deneme';
$newRow->save();
// get rows to demo_fth table
App\Models\Demo::setSuffixCode('fth')->whereNotNull('name')->get();
shell
php artisan vendor:publish --provider="Fatihirday\Suffixed\SuffixServiceProvier"
* config/suffixed.php
* migrations/*_create_suffixes_table.php
shell
php artisan migrate
shell
php artisan tinker
shell
php artisan make:migration-suffix CreateDemoTable
shell
php artisan migrate