Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Shelob9 / vite.config.js
Created July 22, 2022 16:18
Code for Laravel vite React fast refresh with tailwind https://twitter.com/Josh412/status/1547628986695446530
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: 'resources/js/app.jsx',
refresh: [
'resources/js/app.jsx',
'front-end-client/src/**',
'resources/components/react.blade.php',
<?php
trait HandlesContentType {
protected function getContentType(string $name) : string
{
return match($name){
Str::endsWith($name, '.css') => 'text/css',
Str::endsWith($name, '.js') => 'text/javascript',
Str::endsWith($name, '.html') => 'text/html',
default => 'text/plain',
@Shelob9
Shelob9 / click-test.js
Created July 14, 2022 15:57
Test clicks and if elment is or is not in the document after clicking with React @testing-library/react
import "@testing-library/jest-dom";
import { render, act, screen } from "@testing-library/react";
import Accordian from './Accordian';
describe("Accordion", () => {
it("opens", () => {
const { getByText } = render(
<Accordion question="Question" answer="Answer" />
);
act(() => {
import './bootstrap';
import '../css/app.css';
import React from 'react';
import { render } from 'react-dom';
import { createInertiaApp } from '@inertiajs/inertia-react';
import { InertiaProgress } from '@inertiajs/progress';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel';
const defaultTheme = require('tailwindcss/defaultTheme');
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
'./resources/js/**/*.jsx',
//NEW - Check tsx files for tailwind styles
<?php
class SomeCommand extends Command {
public function info($message){
logger()->info($message);
parent::info($message);
}
}
<?php
namespace App\Http\Controllers;
use App\Services\PmIdentityService;
use Aws\S3\S3Client;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Str;
use InvalidArgumentException;
@Shelob9
Shelob9 / database.php
Created May 27, 2022 18:06
Read-only WordPress database connection in a Laravel app.
<?php
return [
'default' => env('DB_CONNECTION', 'pgsql'),
//Other drivers removed for clarity
'mysql' => [
'readonly' => true,
'host' => env('WPDB_HOST', '127.0.0.1'),
'driver' => 'mysql',
'url' => env('WPDB_URL'),
{
"name": "vendor/site",
"type": "project",
"repositories": [
{
"type": "composer",
"url": "https://wpackagist.org",
"only": ["wpackagist-plugin/*", "wpackagist-theme/*"]
}
],
<?php
$script = wp_scripts()->query('react',true);