2.3 will be rounded to 2 and the second 2.5 becomes 3SELECT
ROUND(2.3),
ROUND(2.5)php artisan make:component ComponentName creates ComponentName.blade.php inside resources/view/components and controller ComponentName.php inside App\View\Component directory
you can render component by x- syntax <x-component-name />
pass variables to components
use var-name= for normal strings and use :var-name= for variables
<x-component-name var-name="normal string" :var-name2="$some_variable"/>
make sure to use kebab-case as html attribute names and camelCase inside constructor argument
and inside component controller file ComponentName.php
namespace App\View\Components;
use Illuminate\View\Component;
class ComponentName extends Component
{
public $varName1;
public $varName2;
public function __construct($varName1, $varName2)
{
$this->varName1 = $varName1;
$this->varName2 = $varName2;
}
public function customFunction($last)
{
return [1, 2, 3, 4, 5, 6, 7, $last]; // or data from db for example
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\View\View|\Closure|string
*/
public function render()
{
return view('components.component_name');
}
}
inside ComponentName.blade.php we can retrieve these variables like so
<div class="component-class">
<div>{{$varName1}}</div>
<div>{{$varName2}}</div>
@foreach($customFunction('last line') as $line)
<h1>{{$line}}</h1>
@endforeach
</div>quotation marks, then the parameter is going to be interpreted as a column value.
Converts a string or column value to UPPER-CASE SELECT
UPPER(first_name),
UPPER('Converts a string or column value to UPPER-CASE')
FROM students
Converts a string or column value to lower-case SELECT
LOWER(first_name),
LOWER('Converts a string or column value to lower-case')
FROM students
Joins strings and columns togetherSELECT
CONCAT(first_name, ' ', 'joins', ' ', 'strings', ' ', 'and', ' ', 'columns')
FROM students
The function LENGTH Returns the length (in bytes) SELECT
id,
first_name,
LENGTH(first_name) first_name_length
FROM studentsNote: Each Georgian letter takes three bytes
The function is similar to CONCAT where WS means - With Separator.
The first parameter is the separator between each one of the additional fields, that we pass as next parametersSELECT
CONCAT_WS(' - ', first_name, 'joins', 'strings', 'and', 'columns', 'with', 'separator')
FROM students
The function TRIM removes leading and trailing spacesSELECT
LENGTH(' text ') length,
LENGTH(TRIM(' text ')) length_with_trim
The function RTRIM removes trailing spaces (removes spaces from the end)SELECT
LENGTH(' text ') length,
LENGTH(RTRIM(' text ')) length_with_right_trim
The function LTRIM remove leading spaces (removes spaces from the beginning)SELECT
LENGTH(' text ') length,
LENGTH(LTRIM(' text ')) length_with_left_trim
The function LEFT returns leftmost characters. In this case 5 characters because we pass 5 as second parameterSELECT
LEFT(first_name, 5) AS 'five leftmost characters'
FROM students
The function RPAD appends string (third parameter) the specified number of times (second parameter) to the first parameter.
In this example each one of the student's last name that is less than 10 characters long, is filled with - SELECT
RPAD(first_name, 10, '-') AS 'student name'
FROM students
Complete list of string functions on the official documentation: https://dev.mysql.com/doc/refman/8.0/en/string-functions.htmlROUND rounds the passed value using standard Math rules.
The first argument 2.3 will be rounded to 2 and the second 2.5 becomes 3SELECT
ROUND(2.3),
ROUND(2.5)
Function FLOOR rounds the argument down to the greater integer less then the decimal argument.
Both of the arguments will be rounded down to 2 SELECT
FLOOR(2.3),
FLOOR(2.8)
Function CEIL rounds the number up to the lowest integer value greater than the passed decimal argument.
Both of the arguments will be rounded to 3 SELECT
CEIL(2.3),
CEIL(2.8)
Function RADIANS converts degrees to radians.
90 degrees converted to radians gives us half of PI: 1.5707963267948966.
180 degrees converted to radians gives us PI: 3.141592653589793.SELECT
RADIANS(90),
RADIANS(180)
Function DEGREES converts radians back to degrees.
Half of PI radians 1.5707963267948966 converted to degrees gives us 90 degrees.
PI: 3.141592653589793 radians converted to degrees gives us 180 degrees.SELECT
DEGREES(1.5707963267948966),
DEGREES(3.141592653589793)
These two functions RADIANS and DEGREES are opposite to each other.
180 degrees converted to radians gives us PI: 3.141592653589793
PI: 3.141592653589793 radians converted to degrees gives us 180 degrees.SELECT
RADIANS(180),
DEGREES(3.141592653589793)
Function POWER raises the first argument to the power of another argument.
The code below returns 16 because 2 to the power of 4 is 16
SELECT
POWER(2, 4) Note: POW and POWER are the aliases for the same command
The function CONV converts the first argument from one number system (the second argument) to another (the third argument)
Converts 5 from 10 base system to 2 SELECT
CONV(5, 10, 2)
Complete list of mathematical functions on the official documentation: https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.htmlREPLACE statement updates the listed columns if primary key (one of the listed columns) already exists. Otherwise inserts as a new recordREPLACE INTO students (id, first_name, points)
VALUES (41, 'ილიკო', 147)
Similar to the REPLACE INTO statement is ON DUPLICATE KEY.
The only difference is that on duplicate key it updates only the listed columns but omitted values stays the sameINSERT INTO students (id, first_name, points)
VALUES (41, 'გიორგი', 149)
ON DUPLICATE KEY
UPDATE first_name = 'გიორგი', points = 123
Note 1: If primary key is not listed, it will insert the record, but if the primary key is one of the listed columns, it will update the specified row that matches the primary key.
Note 2: If the primary key exists, all the other omitted columns will get the default values after updating the record.RPAD appends string (third parameter) the specified number of times (second parameter) to the first parameter.
In this example each one of the student's last name that is less than 10 characters long, is filled with - SELECT
RPAD(first_name, 10, '-') AS 'student name'
FROM studentsLEFT returns leftmost characters. In this case 5 characters because we pass 5 as second parameterSELECT
LEFT(first_name, 5) AS 'five leftmost characters'
FROM studentsLTRIM remove leading spaces (removes spaces from the beginning)SELECT
LENGTH(' text ') length,
LENGTH(LTRIM(' text ')) length_with_left_trimTRIM removes leading and trailing spacesSELECT
LENGTH(' text ') length,
LENGTH(TRIM(' text ')) length_with_trim