Skip to content

Instantly share code, notes, and snippets.

@VaguelyOnline
VaguelyOnline / README.md
Last active August 2, 2025 09:03 — forked from mohitmamoria/README.md
Inertia.js Form Helper for Axios/API calls
<?php
function calculateSum(int $min, int $max) {
$tally = 0;
for ($i = $min; $i < $max; $i++) {
$tally += $i;
}
return $tally;
@VaguelyOnline
VaguelyOnline / User.php
Last active February 21, 2022 14:57
Easily serialise Laravel policy method permissions that a given user has, for a given model.
/**
* Automatically generates an array detailing the permissions that this User has over the given target model.
* Usage: $user->getPolicyPermissions($modelWithPolicy)
*
* @param $model
* @return array
* @throws \ReflectionException
*/
public function getPolicyPermissions($model): array
{
@VaguelyOnline
VaguelyOnline / etag.php
Created January 4, 2021 12:41
Illustrates how to retrieve an S3 hosted asset ETag (likely MD5 sum) from a Laravel application.
/**
* Retrieves the ETag for the given S3 key.
*
* @param $key The file key. This is the URL of the object relative to the bucket. It can be found through the S3 portal.
* @return string The ETag
* @throws S3Exception
*/
public function getEtag($key)
{
$adapter = Storage::disk('s3')->getAdapter();
// NB - Activity is a subclass of an Eloquent Model
class Exercise extends Activity
{
public function details()
{
return $this->morphTo('details', 'details_type', 'id');
}
}
// the following doesn't eager load either the images, or the shapes relation.
// note - the details relation is a polymorphic one - will that make a difference??
$ex = Exercise::find(1282);
$ex->load('details.images.shapes');
{
"webAppId": "webappid0123456789",
"urlSchemeDetails":
{
"secure": true,
"host": "rp.example.com",
"port": "8443"
},
"voice":
{
class User {
...
public function sites() {
return $this->hasManyThrough('Site', 'Account');
}
public function hasSite($site) {
return $this->sites()->whereId($site->id)->count() != 0;