This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Laravel 5.2 - Eloquent - How to order database SELECT results by multiple columns | |
--------------------------------------------------------------------------------- | |
Chain together using orderBy with the columns being sorted in the order they are chained, as in the example line below: | |
$contents = ModelName::orderBy('columnA', 'asc')->orderBy('columnB', 'desc')->get(); | |
If $contents is returned to the view now, all rows of the table will be sorted first according to the ascending values of | |
columnA, followed by a second sort of the desc values of column B. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sabrina Notes - Laravel 5.2 - Validator: How to customize the error messages produced by the validator | |
------------------------------------------------------------------------------------------------------- | |
1) Edit /resources/lang/en/validation.php | |
2) In the first section, called 'Validation Language Lines', you can edit the default error messages for existing validation rules: | |
Example: | |
One default error message is: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sabrina Notes - Laravel 5.2 - Validator: Things to check when you know there should be an error returned, | |
but it is empty. For instance, if you use Bootstrap, your error bar might show, but the words won't show | |
in it. | |
---------------------------------------------------------------------------------------------------------- | |
1) My Mistake: | |
@if (count($errors) > 0) | |
<div class="alert alert-danger"> | |
<ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If an application allows users to edit images, for example, once the image file is saved and the user returned to the page | |
showing their images (such as in the banner maker app), the behavior by default is that a cached version of an image is shown until | |
the user manually refreshes the page. This results in confusion because the person just edited the image and therefore expects those | |
changes to show right away. | |
To solve this problem it is a simple matter of creating a random string, such as the date/time: | |
$today = date("YmdHis"); | |
Then in the HTML img tags, add ?$today to the end of the image src attribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#301 Redirects for .htaccess | |
#Redirect a single page: | |
Redirect 301 /pagename.php http://www.domain.com/pagename.html | |
#Redirect an entire site: | |
Redirect 301 / http://www.domain.com/ | |
#Redirect an entire site to a sub folder | |
Redirect 301 / http://www.domain.com/subfolder/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$handle = fopen ("php://stdin","r"); | |
fscanf($handle,"%d",$n); | |
function addToStack($x, &$stack) { | |
$remainder = $x % 2; | |
$nextx = ($x - $remainder)/2; | |
array_unshift($stack, $remainder); | |
if ($nextx >= 1) { | |
addToStack($nextx, $stack); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Seek and Destroy | |
---------------- | |
You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. | |
Remove all elements from the initial array that are of the same value as these arguments. | |
function destroyer(arr) { | |
// Remove all the values | |
// arr array is the first element in the destroyer function, while the other arguments | |
// are in the arguments array: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sabrina: Notice how sort() includes a compare function. Since sort sorts by alphabetical order, sorting numbers tends to be WRONG. | |
The string "25" for example is GREATER THAN the string "100". So we compare with function(a,b) { return a-b; } to sort NUMBERS in | |
ASCENDING ORDER. (for descending order use return b-a instead). | |
Return the lowest index at which a value (second argument) should be inserted into an array (first argument) once it has been sorted. | |
The returned value should be a number. | |
For example, getIndexToIns([1,2,3,4], 1.5) should return 1 because it is greater than 1 (index 0), but less than 2 (index 1). | |
Likewise, getIndexToIns([20,3,5], 19) should return 2 because once the array has been sorted it will look like [3,5,20] and |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
One of the simplest and most widely known ciphers is a Caesar cipher, also known as a shift cipher. | |
In a shift cipher the meanings of the letters are shifted by some set amount. | |
A common modern use is the ROT13 cipher, where the values of the letters are shifted by 13 places. | |
Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on. | |
Write a function which takes a ROT13 encoded string as input and returns a decoded string. | |
All letters will be uppercase. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use in your blade templates like: | |
{{ $your_variable_name }} | |
OR: | |
{{ $settings['your_variable_name'] }} |
OlderNewer