Skip to content

Instantly share code, notes, and snippets.

View MubinSayed's full-sized avatar
🎯
Focusing

Mubin Sayed MubinSayed

🎯
Focusing
View GitHub Profile
@MubinSayed
MubinSayed / helper.php
Created September 23, 2022 10:14
Laravel - Combines SQL and its bindings
/**
* Combines SQL and its bindings
*
* @param \Eloquent $query
* @return string
*/
public static function getEloquentSqlWithBindings($query)
{
return vsprintf(str_replace('?', '%s', $query->toSql()), collect($query->getBindings())->map(function ($binding) {
$binding = addslashes($binding);
@MubinSayed
MubinSayed / .htaccess
Last active December 16, 2021 19:45
.htaccess redirect http to https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Successfully redirect all pages of domain from http to https:
# Note this will redirect using the 301 'permanently moved' redirect, which will help transfer your SEO rankings.
# To redirect using the 302 'temporarily moved' change [R=302,L]
@MubinSayed
MubinSayed / mailhog.md
Created December 2, 2021 07:39
Laravel MailHog Configuration

Mailhog Configuration

MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
@MubinSayed
MubinSayed / save_to_csv.php
Created May 7, 2021 00:38 — forked from dertajora/save_to_csv.php
This script is used to generate CSV file and save it to specific folder, I implement it on Codeigniter. Please modify the location of APPPATH section if you want to save to another location
<?php
// this script would save csv file to this specified directory
// APPPATH is location of application folder in Codeigniter
$file = fopen(APPPATH . '/../upload/'.'tesaasasat.csv', 'wb');
// set the column headers
fputcsv($file, array('Column 1', 'Column 2', 'Column 3', 'Column 4', 'Column 5'));
// Sample data. This can be fetched from mysql too
$data = array(
@MubinSayed
MubinSayed / jquery-validate-invalidhandler.js
Last active April 5, 2021 18:56
Get Error List in jQuery .validate plugin Invalid Handler
// In the invalidHandler, you are passed two arguments, a jQuery.Event and the validator object.
// You don't need to call validate within your invalidHandler to get the validate object.
// Further, the validator object has a properties called errorList and errorMap, which contain the information you are looking for.
invalidHandler: function(e,validator) {
//validator.errorList contains an array of objects, where each object has properties "element" and "message". element is the actual HTML Input.
for (var i=0;i<validator.errorList.length;i++){
console.log(validator.errorList[i]);
}
@MubinSayed
MubinSayed / console.php
Created April 1, 2021 11:23 — forked from meigwilym/console.php
Laravel Create User Command
<?php
// routes/console.php
// quickly create an user via the command line
Artisan::command('user:create', function () {
$name = $this->ask('Name?');
$email = $this->ask('Email?');
$pwd = $this->ask('Password?');
// $pwd = $this->secret('Password?'); // or use secret() to hide the password being inputted
\DB::table('users')->insert([
@MubinSayed
MubinSayed / IndianStatesDistricts.json
Created March 28, 2021 08:52 — forked from Dhaneshmonds/IndianStatesDistricts.json
Indian states, capitals and districts
{
"states": [
{
"id": "1",
"type": "Union Territory",
"capital": "Mayabunder",
"code": "AN",
"name": "Andaman and Nicobar Islands",
"districts": [
{
@MubinSayed
MubinSayed / covertToHierarchy.php
Created April 12, 2019 12:32 — forked from ubermaniac/covertToHierarchy.php
Convert a DB result of parent/child items into a hierarchical array
<?php
// -- Only one caveat : The results must be ordered so that an item's parent will be processed first.
// -- Simulate a DB result
$results = array();
$results[] = array('id' => 'a', 'parent' => '', 'name' => 'Johnny');
$results[] = array('id' => 'b', 'parent' => 'a', 'name' => 'Bobby');
$results[] = array('id' => 'c', 'parent' => 'b', 'name' => 'Marky');
$results[] = array('id' => 'd', 'parent' => 'a', 'name' => 'Ricky');
@MubinSayed
MubinSayed / CourseController.php
Last active April 25, 2021 05:11
Laravel Datatable Dynamic Filter (Advance Filter) (phpMyAdmin Style)
<?php
namespace App\Http\Controllers;
use DB;
use Config;
use App\Models\Course;
use Illuminate\Http\Request;
use Yajra\Datatables\Datatables;
use Illuminate\Support\Facades\Validator;
<?php
//Indexed two-dimensional array
$cars = array(
array("Honda Accord", "V6", 30000),
array("Toyota Camry", "LE", 24000),
array("Nissan Altima", "V1", 10000),
);
foreach($cars as $car){