PHP code example of kilobyteno / laravel-user-guest-like
1. Go to this page and download the library: Download kilobyteno/laravel-user-guest-like library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kilobyteno / laravel-user-guest-like example snippets
return [
// Let guests like a model
'guest_like_enabled' => true,
// Save IP and user agent to database
'user_tracking_enabled' => false,
];
use Kilobyteno\LaravelUserGuestLike\Traits\HasUserGuestLike;
use Illuminate\Database\Eloquent\Model;
class EloquentModel extends Model
{
use HasUserGuestLike;
}
$user = auth()->check() ? auth()->user() : null;
// Passing the user as null will like as a guest (if enabled)
$model->like($user);
$user = auth()->check() ? auth()->user() : null;
// Passing the user as null will like as a guest (if enabled)
$model->dislike($user);
$user = auth()->check() ? auth()->user() : null;
// Passing the user as null will check if the guest (if enabled) has liked the model
if($model->hasLiked($user)) {
// User has liked the model
}