for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Redirect extends Model
{
/**
* Allow these attributes to be filled.
*
* @var array
*/
protected $fillable = [
'hash',
'redirect_to',
];
* The url attribute of a particular.
protected $appends = [
'url'
* Hide unnecessary or private fields.
* @return array
protected $hidden = [
'created_at',
'updated_at'
* Get the url attribute.
* @return void
public function getUrlAttribute()
return config()['base_url'] . '/' . $this->hash;
return config()['base_url'] . '/' . $this->hash
string
void
hash
App\Models\Redirect
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.
}
* Creates an absolutely unique hash for a given url.
public static function createUnique($url)
do {
$hash = bin2hex(openssl_random_pseudo_bytes(4));
} while (static::where('hash', $hash)->first());
return static::create([
return static::create(ar...'redirect_to' => $url))
'hash' => $hash,
'redirect_to' => $url
]);