sqlite3 file.db "VACUUM;"
if (!Schema::hasTable('table_name')) {
// Opt tables
}
if (Schema::hasColumn('table_name', 'column_name')) {
}
Schema::create('table_name', function (Blueprint $table) {
$table->increments('id');
$table->integer('foreign_id')->unsigned();
$table->foreign('foreign_id')->references('id')->on('foreign_table')->onDelete('cascade');
$table->string('key');
$table->text('value')->nullable(true);
$table->timestamps();
});
Schema::create('link_product_retailer', function (Blueprint $table) {
$table->increments('id');
$table->integer('product_id')->unsigned()->nullable();
$table->integer('retailer_id')->unsigned()->nullable();
$table->foreign('product_id')->references('id')->on('products');
$table->foreign('retailer_id')->references('id')->on('retailers');
});
Schema::table('table', function(Blueprint $table){
$table->dropForeign('foreign_name');
});
Schema::table('table', function(Blueprint $table) {
$table->index(['col1', 'col2']);
});
Schema::table('table', function(Blueprint $table) {
$table->dropIndex('index_name');
});
Schema::rename('table_name', 'new_table_name');
Schema::dropIfExists('table_name');
// DROP TABLE IF EXISTS `table_name`;
DB::statement("
CREATE
OR REPLACE
SQL SECURITY INVOKER
VIEW `view_name` AS
SELECT *
FROM `table`
")
DB::statement('DROP VIEW IF EXISTS `view_name`;');
\App\Models\Model::where( [
'key' => 'value'
])->first()->update([
'key' => 'value'
],
]);
graph LR
A[Master] -- one to many --> B[Slave]
$master->hasMany(Slave::class);
$slave->belongsTo(Master::class);
graph LR
E[Employer] --> L((employer_staff))
S[Staff] --> L((employer_staff))
$employer->belongsToMany(Staff::class)
$staff->belongsToManu(Employer::class)
graph LR
U[User] -- one to one --> N[Name]
$user->hasOne(Name::class)
$name->hasOne(User::class)
create
persists to the database while make
just creates a new instance of the model. Laravel create
method is created the model instance and save data in the database. make
function has created the instance of the class. 2