cascadeOnDelete()
The cascadeOnDelete()
method is a convenient way to define cascading behavior for foreign keys when a referenced record is deleted.
Behavior
- Automatically deletes the rows in the child table if the related row in the parent table is deleted.
Example
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->timestamps();
});
This ensures that if a user is deleted, all their related posts will also be deleted.
Status: #idea
Tags: web-programming > web-prog-mid-exam-materials Mid Exam MaterialsWeb Programming (Laravel)Mid Exam Materials
Final Exam Materials
Status: #MOC
Tags:, web-prog-mid-exam-materialsweb-prog-mid-exam-materialsWP-Mid-Exam-Materials
my-wp-uts-practice
Initialization
composer create-project laravel/laravel newProject
not necessary since no wifi and project might be already given
Database
Setup Database
1. Open .env file and look for DB_.. and make sure its the same as this
DB_CONNECTION=mysql // XAMPP runs mysql database engine
DB_HOST=127.0.0.1
DB_PORT=3306 // port for database
DB_DATABASE=laravelproject // make a new database name
DB_USERNAME=root // credentials for XAMPP
DB_PASSWORD= // empty