From 9d66bf2c8cda1f983ba7854018bdd1b7e2be5d11 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Thu, 24 Mar 2022 23:04:00 +0100 Subject: [PATCH 01/10] Installed kilobyteno/laravel-user-guest-like --- composer.json | 1 + composer.lock | 73 ++++++++++++++++++- config/user-guest-like.php | 11 +++ ...24_220316_create_user_guest_like_table.php | 25 +++++++ 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 config/user-guest-like.php create mode 100644 database/migrations/2022_03_24_220316_create_user_guest_like_table.php diff --git a/composer.json b/composer.json index 9132100..694332c 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "fideloper/proxy": "^4.4", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^7.0.1", + "kilobyteno/laravel-user-guest-like": "^0.0.1", "laravel/framework": "^8.40", "laravel/jetstream": "^2.3", "laravel/sanctum": "^2.6", diff --git a/composer.lock b/composer.lock index 342bd30..3b7cef5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4f941691576f0cb135e5a690b1ad0184", + "content-hash": "0db9df3832ab75da918b3f02aa60a340", "packages": [ { "name": "asm89/stack-cors", @@ -1809,6 +1809,77 @@ ], "time": "2020-06-13T08:05:20+00:00" }, + { + "name": "kilobyteno/laravel-user-guest-like", + "version": "0.0.1", + "source": { + "type": "git", + "url": "https://github.com/kilobyteno/laravel-user-guest-like.git", + "reference": "4a84ce1489097a8aad86d96aacf9108fe147e9a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/kilobyteno/laravel-user-guest-like/zipball/4a84ce1489097a8aad86d96aacf9108fe147e9a0", + "reference": "4a84ce1489097a8aad86d96aacf9108fe147e9a0", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^8.73", + "php": "^8.0", + "spatie/laravel-package-tools": "^1.9.2" + }, + "require-dev": { + "nunomaduro/collision": "^5.10", + "orchestra/testbench": "^6.22", + "pestphp/pest": "^1.21", + "pestphp/pest-plugin-laravel": "^1.1", + "phpunit/phpunit": "^9.5", + "spatie/laravel-ray": "^1.26" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Kilobyteno\\LaravelUserGuestLike\\LaravelUserGuestLikeServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Kilobyteno\\LaravelUserGuestLike\\": "src", + "Kilobyteno\\LaravelUserGuestLike\\Database\\Factories\\": "database/factories" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel S. Billing", + "email": "daniel@kilobyte.no", + "role": "Developer" + } + ], + "description": "A Laravel package to allow guests and users to like models", + "homepage": "https://github.com/kilobyteno/laravel-user-guest-like", + "keywords": [ + "kilobyteno", + "laravel", + "laravel-user-guest-like" + ], + "support": { + "issues": "https://github.com/kilobyteno/laravel-user-guest-like/issues", + "source": "https://github.com/kilobyteno/laravel-user-guest-like/tree/0.0.1" + }, + "funding": [ + { + "url": "https://github.com/danielrtrd", + "type": "github" + } + ], + "time": "2022-03-24T21:55:30+00:00" + }, { "name": "laravel/fortify", "version": "v1.11.2", diff --git a/config/user-guest-like.php b/config/user-guest-like.php new file mode 100644 index 0000000..69c9647 --- /dev/null +++ b/config/user-guest-like.php @@ -0,0 +1,11 @@ + true, + + // Save IP and user agent to database + 'user_tracking_enabled' => false, + +]; diff --git a/database/migrations/2022_03_24_220316_create_user_guest_like_table.php b/database/migrations/2022_03_24_220316_create_user_guest_like_table.php new file mode 100644 index 0000000..975abd8 --- /dev/null +++ b/database/migrations/2022_03_24_220316_create_user_guest_like_table.php @@ -0,0 +1,25 @@ +id(); + $table->morphs('model'); + $table->nullableMorphs('author'); + $table->ipAddress('ip')->nullable(); + $table->string('user_agent')->nullable(); + $table->timestamps(); + }); + } + + public function down() + { + Schema::dropIfExists('user_guest_likes'); + } +}; From 09bffc6611c8210d33653c5beccf7aa7642df300 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Thu, 24 Mar 2022 23:04:08 +0100 Subject: [PATCH 02/10] Update Post.php --- app/Models/Post.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Models/Post.php b/app/Models/Post.php index 61bf1d8..71465ad 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -9,6 +9,7 @@ use CyrildeWit\EloquentViewable\Contracts\Viewable; use CyrildeWit\EloquentViewable\InteractsWithViews; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Kilobyteno\LaravelUserGuestLike\Traits\HasUserGuestLike; use GoldSpecDigital\LaravelEloquentUUID\Database\Eloquent\Uuid; class Post extends Model implements Viewable @@ -17,6 +18,7 @@ class Post extends Model implements Viewable use InteractsWithViews; use SoftDeletes; use HasTags; + use HasUserGuestLike; protected $removeViewsOnDelete = true; @@ -70,7 +72,7 @@ public function user() return $this->belongsTo(User::class); } - public function likes() + /*public function likes() { return $this->hasMany(PostLike::class); } @@ -99,7 +101,7 @@ public function removeLike() } return false; - } + }*/ public function scopeIsPublished($query) { From 9fd4c05111b90130e43bf727dd14d88a78e8b0c6 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Thu, 24 Mar 2022 23:04:11 +0100 Subject: [PATCH 03/10] Update like.blade.php --- resources/views/livewire/like.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/livewire/like.blade.php b/resources/views/livewire/like.blade.php index 5676bfe..083ac46 100644 --- a/resources/views/livewire/like.blade.php +++ b/resources/views/livewire/like.blade.php @@ -1,6 +1,6 @@ -