Skip to content

Instantly share code, notes, and snippets.

View jovialcore's full-sized avatar
👨‍🍳
cooking

Chidiebere Chukwudi jovialcore

👨‍🍳
cooking
View GitHub Profile
@jovialcore
jovialcore / countries_seeder.php
Created October 2, 2024 08:52
List of countries
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class CountriesTableSeeder extends Seeder
{
/**
@jovialcore
jovialcore / state_seeder.php
Created October 2, 2024 08:51
List of states, provinces or regions of countries
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class StateSeeder extends Seeder
{
@jovialcore
jovialcore / closest_date_to_a_date.php
Created September 13, 2024 16:25
get the closest dates to a specified date and generate a range
<?php
private function getTimeline(array $dates, int $maxDays = 20)
{
$weekHolder = [];
$startDate = null;
foreach ($dates as $index => $date) {
@jovialcore
jovialcore / array_of_arrays_validation.php
Created August 14, 2024 10:23
my template for Valdiating array of arrays properly in laravel
<?php
$validator = Validator::make(
$request->all(),
[
// you need to pass the question key so that it acts as a validator to make sure we have the array contents.
// if the question key is not added and the form requests doesn't come with the array contents, the validation will be skipped
'question' => 'required',
"question.*.id" => "required|integer", // This will validate each `question` array item
"question.*.applicant_answer" => "required|integer", // T
@jovialcore
jovialcore / fe_email_verification_link_generator.php
Last active June 20, 2024 03:44
Generating an email verification link with laravel that specific for your frontend, NUXT, VUE, REACT.....
@jovialcore
jovialcore / lengdary_way_laravel_authenticates_spa.php
Last active May 6, 2024 18:35
legendary way laravel authenticates SPAs expecially with sanctum
<?php
namespace Illuminate\Foundation\Http\Middleware;
//legendary way laravel authenticates SPAs expecially with sanctum
// compare the hash_equals of the server session token (session value generated by hashing the user's password) with the cookie sent to the frontend
class VerifyCsrfToken
{
/**
@jovialcore
jovialcore / number_props_tip.vue
Last active April 29, 2024 11:13
Number props tip in vuejs
<script setup>
//So in vuejs 3, to declare an integer prop, ideally, you should declare an object passing the prop as an object key and the expected dataype as value for that key
const props = defineProps({ totalPages : Number})
//another tip: when in the parent component, to pass the value for that integer prop, vuejs expects it to be a dynamic prop binding
</script>
<template>
<!--- inside parent component -->
@jovialcore
jovialcore / apiResponseTrait.php
Created March 25, 2024 20:41
A reusable trait I use for returning api response.
<?php
namespace App\Traits;
use Illuminate\Http\JsonResponse;
trait ApiResponse
{
protected function success(array|object $data = [], string $message = '', int $code = 200): JsonResponse
@jovialcore
jovialcore / upload_media_to_azure_and_retrieve_blob_url.php
Created March 23, 2024 14:14
Upload media to azure blob storage and generate a media url
<?php
public function uploadToAzureCloud($request)
{
try {
$storageAccountName = config('services.azure_storage.account_name');
$containerName = config('services.azure_storage.container');
$accessKey = config('services.azure_storage.key');
<?php
// Function to create a shared access signature (SAS) token
private function getSasToken($accountName, $accountKey, $containerName)
{
$sasExpiry = time() + 3600; // Token expires in 1 hour
$sasResource = "https://$accountName.blob.core.windows.net/$containerName";
$sasString = utf8_encode(urlencode($sasResource) . "\n$sasExpiry");
$sig = base64_encode(hash_hmac('sha256', $sasString, base64_decode($accountKey), true));