Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
JavaScript concat()
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)
by გიორგი ბაკაშვილი
4 years ago
1
JavaScript
concat
0
recommended
getBoundingClientRect
method
let element = document.getElementById("some-id"); // for jQuery $("#some-id")[0];

let elementRect = element.getBoundingClientRect();
returns
DOMRect
Object
tooltipRect: 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: (...)
by გიორგი უზნაძე
4 years ago
0
JavaScript
DOM
3
upload multiple files at once and validate file mimes on front / back
In order to upload several files at once we need to specify
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> &nbsp;
    <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 types
public 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
.*
by Valeri Tandilashvili
4 years ago
0
Laravel
validation
3
copy text to clipboard with break lines
If we need to copy text to clipboard with break lines, than we need to use
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;
}
by Valeri Tandilashvili
4 years ago
0
JavaScript
3
In eloquent ORM, $fillable attribute is an array containing all those fields of table which can be filled using mass-assignment. Mass assignment refers to sending an array to the model to directly create a new record in Database.

class User extends Model {  

     protected $fillable = ['name', 'email', 'mobile'];   

     // All fields inside $fillable array can be mass-assigned  

}  
by Luka Tatarishvili
4 years ago
0
Laravel
model
0
user and role relationship caused problem with Spatie package
The relationship caused problems We should not write this many to many relationship inside User's model if we use Spatie permissions package
public function roles()
{
    return $this->belongsToMany(Role::class, 'model_has_roles', 'model_id', 'role_id');
}
by Valeri Tandilashvili
4 years ago
0
Laravel
2
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');
by Luka Tatarishvili
4 years ago
0
Laravel
database
0
@if (Auth::check())
  //show logged in content
@else
  //show logged out content
@endif
by Luka Tatarishvili
4 years ago
0
Laravel
blade
1
Laravel relationship: one function to the different tables
Instead of this:
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();
    }
by Luka Tatarishvili
4 years ago
0
Laravel
relationships
0
ajax request with callback function using native JavaScript
The function sends ajax request with
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 method
ajax(url, 'GET', function(resp) {
    console.log(resp);
})
by Valeri Tandilashvili
4 years ago
0
JavaScript
ajax
2
Results: 1578