Skip to content

Instantly share code, notes, and snippets.

View monish-khatri's full-sized avatar
💻
May the code be with you

Monish Khatri monish-khatri

💻
May the code be with you
View GitHub Profile
let dbNames = 'database_1,database_2';
const dbNamesArray = dbNames.split(",");
// Using Set to remove duplicates and converting back to an array
const uniqueDbNamesArray = [...new Set(dbNamesArray)];
uniqueDbNamesArray.forEach(function(dbName) {
var label = $('label:contains("' + dbName.trim() + ' #")');
var labelFor = label.attr('for');
var inputElement = $('input[value="' + labelFor + '"]');
const footballerStats = {
name: "Lionel Messi",
goals: 819,
assists: 344,
yellowCards: 96,
redCards: 2,
};
// Freeze the footballer's stats to protect them from changes
<?php
// Facing `Warning: Attempt to read property "name" on null`?
$name = $user->name;
/**
* To overcome the above error there are 3 ways in laravel
* 1) if-else condition [Not recommended]
* 2) null safe operator [Available from php8.0]
* 3) optional helper [Best Way]
*/
<?php
// Before
class BeforeTest {
private string $name = 'Monish';
public function getName() {
return $this->name;
}
}
<?php
use App\Models\User;
$updatedUser = User::find(1)->update(['first_name' => 'Monish']); // Output: true/false
$updatedUser = tap(User::find(1), function ($user) {
$user->update(['first_name' => 'Monish']);
}); // Output: User Object with updated value
<?php
// hidden directive in blade file
@hidden('user_id', $user->id)
// Output
<input type="hidden" name="user_id" value="{{$user->id}}">