Skip to content

Instantly share code, notes, and snippets.

View nataliaconde's full-sized avatar
🏠
Working from home

Natália Condê nataliaconde

🏠
Working from home
  • SJC - SP, BR
View GitHub Profile
Parse.Cloud.run("totalRevenue").then(function(response) {
console.log(JSON.stringify(response));
}).catch(function(error) {
console.error("Error fetching total revenue: " + error.message);
});
Parse.Cloud.define('totalRevenue', async (request) => {
const Purchase = Parse.Object.extend('Purchase');
const query = new Parse.Query(Purchase);
query.include('product');
const purchases = await query.find({ useMasterKey: true });
let totalRevenue = 0;
for (let purchase of purchases) {
const product = purchase.get('product');
if (product && product.get('price')) {
const Purchase = Parse.Object.extend("Purchase");
const query = new Parse.Query(Purchase);
query.find().then(function(purchases) {
console.log("Successfully retrieved purchases:");
console.log(purchases);
}).catch(function(error) {
console.error("Error while fetching purchases:");
console.log(error);
});
<?php
namespace App\Policies;
use App\Models\Post;
use App\Models\User;
class PostPolicy
use Illuminate\Support\Facades\Gate;
Gate::guessPolicyNamesUsing(function (string $modelClass) {
// Provide the name of the model’s policy class…
});
<?php
namespace App\Providers;
use App\Models\Post;
use App\Policies\PostPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
if (Gate::any(['can-post', 'delete-post'], $post)) {
// The user is authorized to update and delete the post…
}
if (Gate::none(['can-post', 'delete-post'], $post)) {
// The user cannot update or delete the post…
if (Gate::forUser($user)->allows('can-post', $post)) {
// The user is authorized to update the post…
}
if (Gate::forUser($user)->denies('can-post', $post)) {
// The user cannot update the post…
use App\Policies\PostPolicy;
use Illuminate\Support\Facades\Gate;
/**
* Register all authorization and authentication services.
*/
use App\Models\Post;
use App\Models\User;
use Illuminate\Support\Facades\Gate;
/**
* Register all authorization and authentication services.