Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View bayareawebpro's full-sized avatar
✔️
Available for Consulting

Dan Alvidrez bayareawebpro

✔️
Available for Consulting
View GitHub Profile
@bayareawebpro
bayareawebpro / AutoMorphMap.php
Last active January 23, 2021 11:44
Automatic MorphMap for Laravel Models within a Namespace
<?php
$namespace = 'App\Models';
$models = array_filter(get_declared_classes(), function($index) use ($namespace) {
return strpos($index, $namespace) === 0;
});
$morphMap = array();
foreach($models as $class){
$mapName = snake_case(str_plural(class_basename($class)));
$morphMap[$mapName] = $class;
}
<script>
import debounce from "./utilities/debounce"
export default {
name: "v-dropdown",
props: {
placeholder: {type: String, default: () => 'Type to search...'},
params: {type: Object, default: () => null},
route: {type: String, required: true},
autoload: {default: () => false},
tabindex: {default: () => 1},
@bayareawebpro
bayareawebpro / forge.sh
Created April 30, 2020 00:01
Laravel Forge Setup Script
#
# REQUIRES:
# - server (the forge server instance)
# - event (the forge event instance)
# - sudo_password (random password for sudo)
# - db_password (random password for database user)
# - callback (the callback URL)
#
@bayareawebpro
bayareawebpro / vue-bind-dom-mods.md
Last active April 29, 2020 04:49
VueJS Binding External DOM Modifications

Vue Directive | Listen to External Dom Value Changes

Vue doesn't recognize the input change because the script is directly setting the input value at random intervals using the DOM. So, here's my solution in the form of a directive that will hook into the Element Descriptor and emit an input event so Vue will bind the new value to the form's v-model.

It can use a custom event or other element type as well.

Example (3rd Party Script):

element.value = x //Does not trigger the v-model update
<?php
namespace App\Concerns;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
trait Resourceable
{
public function toResourceArray(?string $class = null, ?Request $request = null): array

Registering Providers (within application.js)

// Services/VueServiceProvider.js

this.load(require.context('./Services', true, /\.*ServiceProvider.js$/))
    .each((name, abstract) => this.register(abstract))

Binding Middleware

[program:provisioner-worker]
process_name=%(program_name)s
command=php /Users/builder/Sites/provisioner/artisan horizon
stdout_logfile=/Users/builder/Sites/provisioner/storage/logs/worker.log
redirect_stderr=true
autorestart=true
autostart=true
user=builder
[program:provisioner-websockets]
<script>
window.addEventListener('beforeunload', function (e) {
// Cancel the event
e.preventDefault();
// Chrome requires returnValue to be set
e.returnValue = '';
// This message may not be shown to the user / vendor specific message may be used...
window.confirm("Are you sure?");
});
</script>

Usage

<v-form-control
    type="text"
    name="name"
    label="Name"
    v-model="entity.name"
    @change="isInvalid = false"
    :invalid="isInvalid"
<?php declare(strict_types=1);
namespace App\Services;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\RequestOptions;
use GuzzleHttp\Exception\RequestException;
class ApiClient