This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Before | |
class BeforeTest { | |
private string $name = 'Monish'; | |
public function getName() { | |
return $this->name; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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] | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const footballerStats = { | |
name: "Lionel Messi", | |
goals: 819, | |
assists: 344, | |
yellowCards: 96, | |
redCards: 2, | |
}; | |
// Freeze the footballer's stats to protect them from changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + '"]'); |