Skip to content

Commit

Permalink
📦 Laravel 6 ♻️ Simplified Hashid 📦 TNTSearch 💩 Feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
MarceauKa committed Sep 3, 2019
1 parent d43dc53 commit 15920cb
Show file tree
Hide file tree
Showing 22 changed files with 473 additions and 918 deletions.
11 changes: 0 additions & 11 deletions app/Chest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App;

use App\Concerns\Models\Postable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

class Chest extends Model
Expand All @@ -19,21 +18,11 @@ class Chest extends Model
'content' => 'json',
];

public function getHashIdAttribute(): string
{
return hashid_encode($this->id);
}

public function getPermalinkAttribute(): string
{
return route('chest.view', $this->hash_id);
}

public function scopeHashIdIs(Builder $query, string $hash): Builder
{
return $query->where('id', hashid_decode($hash));
}

public function toSearchableArray()
{
return [
Expand Down
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Kernel extends HttpKernel
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\Authenticate::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class,
\Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Illuminate\Auth\Middleware\Authorize::class,
Expand Down
26 changes: 3 additions & 23 deletions app/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Spatie\Feed\Feedable;
use Spatie\Feed\FeedItem;

class Link extends Model implements Feedable
class Link extends Model
{
use Postable;

Expand All @@ -28,7 +25,7 @@ class Link extends Model implements Feedable

public function getHashIdAttribute(): string
{
return hashid_encode($this->id);
return app('hashid')->encode($this->id);
}

public function getPermalinkAttribute(): string
Expand All @@ -47,7 +44,7 @@ public function getUrlAttribute(): string

public function scopeHashIdIs(Builder $query, string $hash): Builder
{
return $query->where('id', hashid_decode($hash));
return $query->where('id', app('hashid')->decode($hash));
}

public function updatePreview(): self
Expand Down Expand Up @@ -85,21 +82,4 @@ public function canDownloadArchive(): bool

return true;
}

public function toFeedItem()
{
return FeedItem::create([
'id' => $this->id,
'title' => $this->title,
'summary' => Str::limit($this->content, 130) ?? 'N.C',
'updated' => $this->updated_at,
'link' => $this->permalink,
'author' => config('app.name'),
]);
}

public static function getFeedItems()
{
return Link::latest()->withPrivate(false)->get();
}
}
7 changes: 7 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use App\Services\Hashid;
use App\Services\Shaarli\Shaarli;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
Expand All @@ -19,6 +20,12 @@ public function register()
});

$this->app->alias(Shaarli::class, 'shaarli');

$this->app->singleton(Hashid::class, function ($app) {
return new Hashid($app['config']->get('shaarli.hashids'));
});

$this->app->alias(Hashid::class, 'hashid');
}

public function boot()
Expand Down
28 changes: 28 additions & 0 deletions app/Services/Hashid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
namespace App\Services;

use Hashids\Hashids;

class Hashid
{
protected $hashids;

public function __construct(array $config = [])
{
$this->hashids = new Hashids(
$config['salt'],
$config['min'],
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
);
}

public function encode($data): string
{
return $this->hashids->encode($data);
}

public function decode($data)
{
return $this->hashids->decode($data);
}
}
2 changes: 1 addition & 1 deletion app/Services/Shaarli/Shaarli.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class Shaarli
{
/** @var string VERSION */
public const VERSION = '1.1.1';
public const VERSION = '1.2.0';
/** @var Application $app */
protected $app;
/** @var Valuestore $settings */
Expand Down
21 changes: 1 addition & 20 deletions app/Story.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Spatie\Feed\Feedable;
use Spatie\Feed\FeedItem;

class Story extends Model implements Feedable
class Story extends Model
{
use Postable;

Expand All @@ -34,21 +32,4 @@ public function scopeSlugIs(Builder $query, string $slug): Builder
{
return $query->where('slug', $slug);
}

public function toFeedItem()
{
return FeedItem::create([
'id' => $this->id,
'title' => $this->title,
'summary' => Str::limit($this->content, 130) ?? 'N.C',
'updated' => $this->updated_at,
'link' => $this->url,
'author' => config('app.name'),
]);
}

public static function getFeedItems()
{
return Story::latest()->withPrivate(false)->get();
}
}
11 changes: 10 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# Unreleased
# 1.2.0

## Added

- Loader on LinkForm, StoryForm and ChestForm
- Add original URL to card-link
- Ability to "Save and archive" a link

## Changed

- Laravel 6.0
- Simplified Hashid

## Deleted

- Feeds

# 1.1.1

## Fixed
Expand Down
14 changes: 6 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,27 @@
],
"license": "MIT",
"require": {
"php": "^7.1.3",
"php": "^7.2",
"doctrine/dbal": "^2.9",
"elfsundae/laravel-hashid": "^1.3",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.8.*",
"laravel/framework": "^6.0",
"laravel/scout": "^7.1",
"laravel/tinker": "^1.0",
"maatwebsite/excel": "^3.1",
"nesk/puphpeteer": "^1.6",
"norkunas/youtube-dl-php": "^1.3",
"predis/predis": "^1.1",
"spatie/laravel-feed": "^2.3",
"spatie/valuestore": "^1.2",
"teamtnt/laravel-scout-tntsearch-driver": "^7.1"
"hashids/hashids": "^2.0.4|~3.0",
"marceauka/laravel-scout-tntsearch-driver": "^7.2"
},
"require-dev": {
"beyondcode/laravel-dump-server": "^1.0",
"filp/whoops": "^2.0",
"facade/ignition": "^1.4",
"fzaninotto/faker": "^1.4",
"laravel/dusk": "^5.5",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0",
"phpunit/phpunit": "^7.5"
"phpunit/phpunit": "^8.0"
},
"config": {
"optimize-autoloader": true,
Expand Down
Loading

0 comments on commit 15920cb

Please sign in to comment.