
On delete set foreign id column value null using migration in laravel 8
Sometimes we have to create a column with foreign id in the table which we have to set null on delete the parent table row (related table row). Like if you have a column discount_id (foreign ID) in a table which is related to discount table id. On delete discount table records the column value of discount_id will be set null.
Answers 1
-
On delete set null foreign id column in migration in laravel 8
$table->foreignId('discount_id')->nullable()->constrained()->onDelete('set null');
0It will set the null value to the foreignId column in the table on delete the parent table records. Like on delete discount table records which is the parent table it will set value of foreign id column (discount_id) to null.
Random Code Snippet Queries: Laravel
- How to create static page in Laravel
- How to check query string exists or not in laravel blade
- Laravel API response format
- How to display user profile after login in laravel
- How to use or operator in laravel
- Laravel route parameter
- Get ids in array from users table
- How to check records exist in loaded relationship in Laravel blade view
- How to get route name on visit URL in laravel
- Recursive function example code PHP Laravel
- Get Array of IDs from Eloquent Collection
- How to get file extension from input type file in laravel
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- How to add active class to menu item in laravel
- Post model with title and body in laravel 8
- Call to a member function getRelationExistenceQuery() on array in Laravel
- Update last created record in Laravel
- Attempt to read property "avatar" on null in Laravel
- Rendering HTML from database table to view in Laravel
- How to get count of all records created at yesterday
- How to check if user has created any post or not in laravel
- How to get only time from created_at in laravel
- Insert current date time in a column using Laravel
- Insert dummy data in users table Laravel
- How to get all posts which contains comments in laravel