Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
public function show(\App\Post $post)
    {
        $post->load('comments');
        return view('posts.show', compact('post'));
    }
also possible to load relation on every model instance with
protected $with = ['comments'];
by გიორგი უზნაძე
4 years ago
0
Laravel
Model
0
function getValue(data, path) {
    var i, len = path.length;
    for (i = 0; typeof data === 'object' && i < len; ++i) {
        data = data[path[i]];
    }
    return data;
}
Now if you want to access
a.b.c
var prop = getValue(a, ["b", "c"]);
by გიორგი უზნაძე
4 years ago
0
JavaScript
Object
3
by გიორგი უზნაძე
4 years ago
0
Git
3
method_exists() does not care about the existence of
__call()
, whereas
is_callable()
does:
<?php
class Test {
  public function explicit(  ) {
      // ...
  }
  
  public function __call( $meth, $args ) {
      // ...
  }
}

$Tester = new Test();

var_export(method_exists($Tester, 'anything')); // false
var_export(is_callable(array($Tester, 'anything'))); // true
?>
by გიორგი უზნაძე
4 years ago
3
PHP
Objects
1
disable google crawler bot using meta tag
if you don't want google to crawl in your website and add it in search engine database use this tag to avoid it
<meta name="robots" content="noindex, nofollow">
by გიორგი უზნაძე
4 years ago
0
HTML
SEO
1
MySQL provides you with the DELETE JOIN statement that allows you to remove duplicate rows quickly. The following statement deletes duplicate rows and keeps the highest id:
DELETE t1 FROM table_name t1
INNER JOIN table_name t2 
WHERE 
    t1.id < t2.id AND 
    t1.email = t2.email;
by გიორგი უზნაძე
4 years ago
0
MySQL
Duplicate
2
Remove "having" from query builder using custom helper function
$query = ...->orHaving('col1', 'like', %text%)->orHaving('col2', '=', 123);
$this->removeHaving('col1', $query); //removes it entirely
This code works for all
->having
,
orHaving
,
havingRaw
and
orHavingRaw
public function removeHaving(Builder $builder, $havingColumn)
{
  $bindings = $builder->getQuery()->bindings['having'];
  $havings = $builder->getQuery()->havings;

	if($havings){
		$havingKey = false;
    $isRaw = false;
		foreach ($havings as $key => $having) {

			if (isset($having['column']) && $having['column'] == $havingColumn) {
				$havingKey = $key;
				break;
			}elseif(isset($having['type']) && $having['type'] === "Raw" && stripos($having['sql'], $havingColumn) !== false){
        $isRaw = true;
        $pattern = '/(or|and|(?:(?P<case1namE>)\() ?|) ?\w*(\.)?'.$havingColumn.'( like| ?\=) ?\?(?:(?P=case1namE) OR)?( and)?/mi';

        $havings[$key]['sql'] = preg_replace($pattern, '', $having['sql']);
        unset($bindings[$key]);
      }
		}

		if ($havingKey !== false && !$isRaw) {
			unset($bindings[$havingKey]);
			unset($havings[$havingKey]);
		}

    $havings = empty($havings) ? null : $havings;

		$builder->getQuery()->havings = $havings;
		$builder->getQuery()->bindings['having'] = $bindings;

	}

  return $builder;
}
by გიორგი უზნაძე
4 years ago
0
Laravel
Eloquent
0
(or|and|(?:(?P<case1namE>)\() ?|) ?\w*(\.)?colz( like| ?\=) ?\?(?:(?P=case1namE) OR)?( and)?
in this case if
(
is found before the expression then
OR
will be captured at the end of the expression(if found) IMPORTANT: group name is case sensitive //see code for real example
by გიორგი უზნაძე
4 years ago
0
PHP
Regexp
1
moving from jQuery to native JS
Get element (
input[type=text]
,
select
) value jQuery
let value = $("#element_id").val();
JS
let value = document.getElementById('element_id').value;'
Set value
5
to the specified element (
input[type=text]
,
select
) value jQuery
$("#element_id").val(5);
JS
let value = document.getElementById('element_id').value = 5;'
Check if the specified checkbox is checked jQuery
let is_checked = $("#element_id").is(":checked");
JS
let is_checked = document.getElementById('element_id').checked
Get HTML content of the specified element by element id jQuery
let content = $("#element_id").html();
JS
let content = 
 document.getElementById('element_id').innerHTML
Set HTML content to the specified element by element id jQuery
$("#element_id").html('some html');
JS
document.getElementById('element_id').innerHTML = 'some html'
Get attribute
placeholder
value of the element jQuery
$('#element_id').attr('placeholder');
JS
document.getElementById('element_id').getAttribute('placeholder');
Set attribute
placeholder
value to the specified element jQuery
$('#element_id').attr('placeholder', 'new placeholder');
JS
document.getElementById('element_id').placeholder = 'new placeholder';
Toggle class for an element jQuery
$("#element_id").toggle();
JS
document.getElementById('element_id').classList.toggle("hide");
CSS class
.hide {
	display: none !important;
}
Get selected
radio
value jQuery
let result = jQuery('input:radio[name=vote]:checked').val();
JS
let result = document.querySelector('input[name=vote]:checked').value;
Find
i
element inside another element with id
element_id
jQuery
let icon = $("#element_id").find('i');
JS
document.getElementById('element_id').querySelector('i');
Get
data-value
attribute of
datalist
element using selected text (datalist option's
value
attribute) jQuery
$('#datalist_id [value="selected text"]').data('value');
JS
document.querySelector('#datalist_id option[value="selected text"]').getAttribute('data-value')
Toggle two class for an element jQuery
let el = $('#element')
if(el.hasClass('arrow-down')) {
    el.removeClass('arrow-down');
    el.addClass('arrow-up');
} else {
    el.addClass('arrow-down');
    el.removeClass('arrow-up');
}
JS
let el = document.getElementById('element')
if (el.classList.contains('arrow-up')) {
    el.classList.remove('arrow-up');
    el.classList.add('arrow-down');
} else {
    el.classList.add('arrow-up');
    el.classList.remove('arrow-down');
}
Ajax request jQuery
$.ajax({
    url:'demo_get.asp',
    success:function(sms){
        $('#demo').html(sms);                        
    }
});
JS
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        document.getElementById("demo").innerHTML = this.responseText;
    }
};
xhttp.open("GET", "demo_get.asp", true);
xhttp.send();
MouseOver event jQuery
$('#element').on('mouseover', function(){
    console.log('mouse over');
});
JS
document.getElementById('element').addEventListener('mouseover', function(){
    console.log('mouse over');
});
Scroll animation down to the specified element's position in 500 ms jQuery
$('html, body').animate({scrollTop:($('#element').position().top)}, 400);
JS
function scrollDownToElement(el) {

    // Milliseconds per move 
    let pm = 50;

    // Padding from top
    let mft = 150;

    // Total animation milliseconds
    let scroll_ms = 500;

    // Calculates target element top position
    let bd_pos = document.body.getBoundingClientRect();
    let el_pos = document.getElementById(el).getBoundingClientRect();
    let height = el_pos.top-bd_pos.top-mft;

    // Calculates per move px
    let spm = height / (scroll_ms / pm);

    // The animation counter to stop
    let spmc = 1;
    let scroll_timer = setInterval(function() {

        // Moves down by {spm} px
        window.scrollBy(0, spm);
        spmc++;

        // Stops the animation after enough iterations
        if (spmc > (scroll_ms / pm)) {
            clearInterval(scroll_timer);
        }
    }, pm);
}
scrollDownToElement('element');
by Valeri Tandilashvili
4 years ago
0
JavaScript
jQuery
2
several ways to put space between table rows CODE
fThe First way is to use
border-spacing
property
table {
    border-collapse:separate;
    border-spacing:0 15px;
}
Another way is to put additional separator TRs
<tr class="separator" />
between rows
.separator {
    height: 10px;
}
Third way is to use
margin-bottom
property
tr { 
    display: block;
    margin-bottom: 15px;
}
by Valeri Tandilashvili
4 years ago
2
CSS
table
4
Results: 1578