How to check data inserted or deleted in pivot after toggle method
You can easily check if data is inserted or deleted in the pivot table after the toggle method. Basically, toggle method insert data in pivot table if record with same (provided) data do not exist in it else it deletes the record from the pivot table.
Return json response after toggle method on pivot table
$user = User::find($userId); $roleId = $request->id; $response = $user->roles()->toggle($roleId); return response()->json(['success'=>$response]);0
The toggle method returns an object if the new record is created in the pivot table, else it returns 1 as a response after the toggle method deletes the existing record. Basically, the toggle method deletes the record if the record already exists in it, else insert the new record.
JQuery check the object is empty or not in HTML page on ajax call
You can easily check that the object is empty or not in HTML using the jquery method $.isEmptyObject(). It will return true if the data is an empty object.
Random Code Snippet Queries: Laravel
- How to get only time from created_at in laravel
- How to pass data to multiple partial view files in laravel
- How to add script on specific view file in laravel while extending layout
- The openssl extension is required for SSL/TLS protection but is not available
- Get last week data in Laravel
- Get previous date data in laravel
- Laravel form request validation
- Syntax error or access violation: 1072 Key column 'role_id' doesn't exist in table (SQL: alter table `users` add constraint `users_role_id_foreign` foreign key (`role_id`) references `roles` (`id`))
- Remove public from url in laravel project
- How to get last month records in Laravel
- How to get the id of last record from collection object in laravel view
- How to insert ckeditor data into database in Laravel?
- Laravel onclick function not working
- Insert values in pivot table dynamically in laravel
- Validation for multiple forms on same page in laravel
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- How to get specific columns using Laravel eloquent methods
- Shorter syntax for whereHas with call back function in laravel
- How to upload multiple images after preview in laravel using cropper js
- JQuery each loop on json response after ajax in laravel
- External link not working in laravel blade
- How to create static page in Laravel
- Run artisan command to generate key in laravel
- Get today records in Laravel
- Get products with number of orders in Laravel