-
app/Models/Url.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; class Url extends Model { // protected $casts = [ 'user_id' => 'int', 'is_custom' => 'boolean', ]; // }
-
app/Services/UrlService.php
Open in GitHubuse App\Models\Url; class UrlService { protected $url; protected $keySrvc; public function __construct() { $this->url = new Url; $this->keySrvc = new KeyService; } // public function shortenUrl($request, $authId) { $key = $request['custom_key'] ?? $this->keySrvc->urlKey($request['long_url']); return Url::create([ 'user_id' => $authId, 'long_url' => $request['long_url'], 'meta_title' => $request['long_url'], 'keyword' => $key, 'is_custom' => $request['custom_key'] ? 1 : 0, 'ip' => request()->ip(), ]); } // }