Snippets
Register
Login
Language
Any
css
htmlmixed
javascript
markdown
plaintext
sass
sql
php
vue
yaml
Theme
Any
nord
Tags
$title = new \Illuminate\Support\HtmlString('
Hello World
'); // Blade {{ $title }} // Renders the actual HTML instead of HTML entities
php
laravel
// 2021-10-12 21:48:07.0 DateTime::createFromFormat('Y-m-d', '2021-10-12') // 2021-10-12 00:00:00.0 DateTime::createFromFormat('!Y-m-d', '2021-10-12')
php
/** * Get the attributes that have been changed since last sync. * * @return array */ public function getClean(): array { $clean = []; foreach ($this->getAttributes() as $key => $original) { if (!$this->originalIsEquivalent($key, $original)) { $clean[$key] = $this->getOriginal()[$key] ?? null; } } return $clean; }
php
laravel
model
attributes
/** * The "booting" method of the model. * * @return void */ protected static function boot() { parent::boot(); Model::unguard(); Model::preventLazyLoading(); }
php
laravel
model
/** UI/UX Tip If you can't control images uploaded by users, sometimes they can look bad. The reason is - they might have bad contrast with your background. One of the possible solutions is adding transparent inset border to the images. */ img { outline: 5px solid rgba(0, 0, 0, 0.1); outline-offset: -5px; }
css
image
border
// There is a #PHP function to compare two strings by how phonetically similar they are if (metaphone("Phreaky") === metaphone("freaky")) { echo "Phreaky sounds like freaky!"; } else { echo "Nooo, Phreaky isn't freaky anough!"; } // Outputs: Phreaky sounds like freaky!
php
metaphone
// You can use arrow key -> while asserting json column in tests $this->assertDatabaseHas('users', [ 'id' => 1, 'options->enabled' => true, ]);
php
laravel
database
json
/** * Add a `whereHasModel` scope. * * @param Builder $query * @param string $relation * @param Model $model * @param string $table * @param string $column * @param string $attribute * @return void */ public function scopeWhereHasModel(Builder $query, string $relation, Model $model, string $table = null, string $column = null, string $attribute = null) { $attribute = $attribute ?? $model->getKeyName(); $column = $column ?? $model->getKeyName(); $table = $table ?? $model->getTable(); $query->whereHas($relation, function($q) use($attribute, $column, $model, $table) { $q->where($table.'.'.$column, '=', $model[$attribute]); }); }
php
laravel
model
scope