Skip to content

Instantly share code, notes, and snippets.

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})

Laravel Snippets

Join a table to itself

e.g. a category that can have a parent_id which is another category

public function parent()
{
    return Category::where('id', '=', $this->category_id)->first();
<!DOCTYPE html>
<html class="no-js fuelux">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>E-Learning</title>
<link rel="stylesheet" href="https://fuelcdn.com/fuelux/2.3/css/fuelux.min.css">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
// Basic Random Image Rotator
// jQuery required http://jquery.com
// Easy option
// img is an array of images
var img = ['img1.jpg','img2.jpg','img3.jpg','img4.jpg'];
// src="images/rotator/ is path to your files contained in above array
$('<img src="images/rotator/' + images[Math.floor(Math.random() * images.length)] + '">').appendTo('#imageContainer');
////////////////////////////