PHP code example of miracuthbert / laravel-royalty
1. Go to this page and download the library: Download miracuthbert/laravel-royalty 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/ */
namespace App\Royalty\Actions;
use Miracuthbert\Royalty\Actions\ActionAbstract;
class CompletedLesson extends ActionAbstract
{
/**
* Set the action key.
*
* @return mixed
*/
public function key()
{
return 'completed-lesson';
}
}
use Miracuthbert\Royalty\Models\Point;
$point = Point::create([
'name' => 'Completed Lesson',
'key' => 'completed-lesson',
'description' => 'Reward for completing a lesson',
'points' => 100,
]);
// user instance
$user = User::find(1);
$user->givePoints(new CompletedLesson());
// using request user
$request->user()->givePoints(new CompletedLesson());
// using auth user
auth()->user()->givePoints(new CompletedLesson());
// user instance
$user = User::find(1);
$user->points()->number();
$user->points()->shorthand();
// using request user
$request->user()->points()->number();
$request->user()->points()->shorthand();
// using auth user
auth()->user()->points()->number();
auth()->user()->points()->shorthand();