const firstName = 'Giorgi';
const job = 'Doctor';
const birthdayYear = 1991;
const currentDate = new Date();
const currentYear = currentDate.getFullYear()
//same results but different syntax
const giorgisInfo = "I'm " + firstName + ', a ' + (currentYear - birthdayYear) + ' year old ' + job + '!';
console.log(giorgisInfo)
//----------------
const giorgisInfoNew = `I'm ${firstName}, a ${currentYear - birthdayYear} year old ${job}!`
console.log(giorgisInfoNew)
getBoundingClientRect
method
let element = document.getElementById("some-id"); // for jQuery $("#some-id")[0];
let elementRect = element.getBoundingClientRect();
returns DOMRect
ObjecttooltipRect: DOMRect
bottom: -5
height: 20
left: 1093.5625
right: 1149.59375
top: -25
width: 56.03125
x: 1093.5625
y: -25
__proto__: DOMRect
bottom: -5 //invoked
height: 20 //invoked
left: 1093.5625 //invoked
right: (...)
top: (...)
width: (...)
x: (...)
y: (...)
multiple
attribute and append []
to input name<input type="file" multiple="multiple" name="files[]" placeholder="Attach file"/>
To validate show errors on client side we have to append input name with .*
Complete example of the form-group
<div class="form-group">
<label for="files">Attach File</label>
<i id="add_new_file" class="ki ki-plus text-success pointer" title="Add New File"></i>
<input type="file" class="form-control mb-2 {{ $errors->has('files.*') ? 'is-invalid' : '' }}" multiple="multiple" name="files[]" placeholder="Attach file"/>
@if($errors->has('files.*'))
<div class="invalid-feedback">
<strong>{{ $errors->first('files.*') }}</strong>
</div>
@endif
</div>
Server side validation of mime typespublic function rules()
{
return [
'comment' => 'sometimes|nullable|min:2|max:255',
'files.*' => 'sometimes|nullable|mimes:pdf,docx,xlsx,pptx,rar,zip,png,jpg',
];
}
It's necessary the validator key files
to be appended with the same symbols .*
textarea
instead of using input
element function copy(part1, part2) {
// Creates textarea element
var textarea = document.createElement('textarea');
// Puts the text into the textarea with breaklines
textarea.value = part1 + "\n\n" + part2
// Adds the element to the DOM
document.body.appendChild(textarea);
// Selects the text that we want to copy
textarea.select();
// Copies the selected text clipboard
var result = document.execCommand('copy');
// Removes the element from the DOM because we no longer need it
document.body.removeChild(textarea);
return result;
}
class User extends Model {
protected $fillable = ['name', 'email', 'mobile'];
// All fields inside $fillable array can be mass-assigned
}
public function roles()
{
return $this->belongsToMany(Role::class, 'model_has_roles', 'model_id', 'role_id');
}
user_id
column on the books_chapter
table references the id
column on a users
table:
$table->foreign('book_id')->references('id')->on('books');
$table->foreign('chapter_id')->references('id')->on('texts');
$table->foreign('user_id')->references('id')->on('users');
->onDelete('cascade')
helps us to automatically delete related rows in Laravel
$table->foreign('book_id')->references('id')->on('books')->onDelete('cascade');
$table->foreign('chapter_id')->references('id')->on('texts')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
@if (Auth::check())
//show logged in content
@else
//show logged out content
@endif
public function words()
{
return $this->belongsToMany('App\Word', definition_word)->withTimestamps();
}
Use this:
With a variable $table
we can use words()
function to the different tables.
public function words($table = null)
{
return $this->belongsToMany('App\Word', $table)->withTimestamps();
}
vanilla JavaScript
and calls the callback function
if the third parameter's type is function
function ajax(url, methodType, callback){
var xhr = new XMLHttpRequest();
xhr.open(methodType, url, true);
xhr.send();
xhr.onreadystatechange = function(){
if (xhr.readyState === 4 && xhr.status === 200){
if (typeof callback === "function") {
callback(xhr.responseText);
}
}
}
}
Example of calling the above methodajax(url, 'GET', function(resp) {
console.log(resp);
})