Skip to content

Instantly share code, notes, and snippets.

View JordanDalton's full-sized avatar

Jordan Dalton JordanDalton

View GitHub Profile
@JordanDalton
JordanDalton / CustomFunctionExample.php
Created July 13, 2023 10:10
Code sample on using custom function in the OpenAI PHP Laravel package.
<?php
$city_fact_result = OpenAI::chat()->create([
'model' => 'gpt-3.5-turbo',
'messages' => [
[
'role' => 'user',
'content' => "I'm in {$location}?",
],[
'role' => 'assistant',
@JordanDalton
JordanDalton / helpers.php
Created February 19, 2023 14:28
Pipeline Helper / Wrapper
<?php
if( ! function_exists('pipe')) {
function pipe($payload, $steps = [])
{
return app(\Illuminate\Pipeline\Pipeline::class)
->send($payload)
->through($steps)
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class Something extends JsonResource
{
/**
* Transform the resource into an array.
@JordanDalton
JordanDalton / Chat.vue
Last active July 14, 2018 22:05
A beauty of leveraging Eloquent to prepare your urls is that your Vue components no longer care about the urls, just that a url is provided.
<script>
export default {
props : [
'messages_url',
'store_message_url'
],
data(){
return {
@JordanDalton
JordanDalton / Employee.php
Created September 23, 2017 21:29
Here's an example of what do to if you desire to use Laravel's updateExistingPivot() while getting your attributes mutated through a pivot model.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Employee extends Model
{
/**
@JordanDalton
JordanDalton / Auditable.php
Created March 14, 2017 16:25
Here's how you could use a trait to update the fillable property on eloquent models.
<?php
namespace App\Traits;
trait Auditable
{
/**
* The fillable properties for this trait which will be applied to the model.
*
* @var array
@JordanDalton
JordanDalton / gist:b2488cc840021b017df9a68120323e7e
Created December 10, 2016 19:20
A working curl request for IBM speech to text
curl -X POST -u "{username}":"{password}" --header "Content-Type: audio/wav;codec=pcm;bit=16;rate=16000" --header "Accept: application/json" --header "Transfer-Encoding: chunked" --data-binary @file.wav "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?model=en-US_NarrowbandModel&speaker_labels=true"
@JordanDalton
JordanDalton / AppServiceProvider.php
Last active August 27, 2019 19:00
Here's a nice, common App Service Provider I created and use in 100% of my applications. It provides a simple way to define and bind contracts, define model observers as well as extend form validation extension.
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Validator;
class AppServiceProvider extends ServiceProvider
{
/**
@JordanDalton
JordanDalton / StoreUserFormRequest.php
Last active August 29, 2015 14:24
Flexible errors with support for error bags.
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
class StoreUserFormRequest extends Request
{
/**
* The key to be used for the view error bag.
@JordanDalton
JordanDalton / UpdateUserRequest.php
Last active August 29, 2015 14:05
Here is an example of how you can utilize Laravel 4.3 FormRequest to force a unique rule to ignore a given ID
<?php namespace App\Http\Requests;
use Auth;
use Illuminate\Foundation\Http\FormRequest;
class UpdateUserRequest extends FormRequest {
/**
* Get the validation rules that apply to the request.
*