Results: 1580
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
in order to have
Cache
class you need to import it
use Illuminate\Support\Facades\Cache;
$postCount = Cache::remember(
            'count.posts.' . $user->id,
            now()->addSeconds(30),
            function () use ($user) {
                return $user->posts->count();
            });
in this case the post count will be cached with different key on every user and will be retrieved by the authorized users id 2nd argument is expiration date, in this case 30 seconds in the future 3rd argument is a callback of what to do and store if cache is not found (is not set yet or 30 seconds has passed)
by გიორგი უზნაძე
4 years ago
0
Laravel
Cache
1
you can override parent static
boot
method, but you still need to call it inside
protected static function boot()
    {
        parent::boot();

        static::created(function ($user) {
            //do something with created model
        });
    }
by გიორგი უზნაძე
4 years ago
0
Laravel
Model
1
Available Column Types
Of course, the schema builder contains a variety of column types that you may use when building your tables:
	
$table->bigIncrements('id');	Incrementing ID (primary key) using a "UNSIGNED BIG INTEGER" equivalent.
$table->bigInteger('votes');	BIGINT equivalent for the database.
$table->binary('data');	BLOB equivalent for the database.
$table->boolean('confirmed');	BOOLEAN equivalent for the database.
$table->char('name', 4);	CHAR equivalent with a length.
$table->date('created_at');	DATE equivalent for the database.
$table->dateTime('created_at');	DATETIME equivalent for the database.
$table->decimal('amount', 5, 2);	DECIMAL equivalent with a precision and scale.
$table->double('column', 15, 8);	DOUBLE equivalent with precision, 15 digits in total and 8 after the decimal point.
$table->enum('choices', ['foo', 'bar']);	ENUM equivalent for the database.
$table->float('amount');	FLOAT equivalent for the database.
$table->increments('id');	Incrementing ID (primary key) using a "UNSIGNED INTEGER" equivalent.
$table->integer('votes');	INTEGER equivalent for the database.
$table->json('options');	JSON equivalent for the database.
$table->jsonb('options');	JSONB equivalent for the database.
$table->longText('description');	LONGTEXT equivalent for the database.
$table->mediumInteger('numbers');	MEDIUMINT equivalent for the database.
$table->mediumText('description');	MEDIUMTEXT equivalent for the database.
$table->morphs('taggable');	Adds INTEGER taggable_id and STRING taggable_type.
$table->nullableTimestamps();	Same as timestamps(), except allows NULLs.
$table->rememberToken();	Adds remember_token as VARCHAR(100) NULL.
$table->smallInteger('votes');	SMALLINT equivalent for the database.
$table->softDeletes();	Adds deleted_at column for soft deletes.
$table->string('email');	VARCHAR equivalent column.
$table->string('name', 100);	VARCHAR equivalent with a length.
$table->text('description');	TEXT equivalent for the database.
$table->time('sunrise');	TIME equivalent for the database.
$table->tinyInteger('numbers');	TINYINT equivalent for the database.
$table->timestamp('added_on');	TIMESTAMP equivalent for the database.
$table->timestamps();	Adds created_at and updated_at columns.
$table->uuid('id');	UUID equivalent for the database.
by გიორგი ბაკაშვილი
4 years ago
0
Laravel
laravel official doc
1
@if (Auth::check())
  //show logged in content
@else
  //show logged out content
@endif
by Luka Tatarishvili
4 years ago
0
Laravel
blade
1
issues when upgrading MySQL from 5.5 to 8.0
Row with datetime value '0000-00-00 00:00:00' is not allowed
INSERT INTO `t_cal_mention` VALUES 
(1, 4, 1426, '0000-00-00 00:00:00', 0)
The insert query will produce the following MySQL error
Error Code: 1292. Incorrect datetime value: '0000-00-00 00:00:00' for column inserted_at at row 14
Row with date value '0000-00-00' is not allowed
INSERT INTO `t_design` VALUES (5,0,'წმ. დიდმოწამე მარინე','წმ. დიდმოწამე მარინე','წმ. დიდმოწამე მარინე','oi8io_104355.jpg','0000-00-00','')
The insert query will produce the following MySQL error
Error Code: 1292. Incorrect date value: '0000-00-00' for column 'date' at row 14
by Valeri Tandilashvili
4 years ago
0
MySQL
1
INSERT statement
Inserts a single record into students table. In the
VALUES
clause we list the values in the same order as the columns are defined in the first clause
INSERT INTO `students` (
    `id`, 
    `first_name`, 
    `last_name`, 
    `points`, 
    `mail`, 
    `santa_id`
) 
VALUES (
    NULL, 
    'დავით', 
    'ბერიძე', 
    '54', 
    'david@gmail.com', 
    '10'
);
Inserts several rows with one INSERT statement
INSERT INTO `students` (
    `id`, 
    `first_name`, 
    `last_name`, 
    `points`, 
    `mail`, 
    `santa_id`
) 
VALUES 
	(NULL, 'დავით', 'ბერიძე', '54', 'david@gmail.com', '10'),
	(NULL, 'გელა', 'თავაძე', '54', 'david@gmail.com', '10'),
	(NULL, 'თამარ', 'დავითაშვილი', '54', 'david@gmail.com', '10')
;
We can exclude nullable fields and pass only the necessary fields
INSERT INTO `students` (
    `first_name`, 
    `last_name`, 
    `points`
) 
VALUES (
    'დავით', 
    'ბერიძე', 
    '54'
)
INSERT & SELECT statement
INSERT INTO `students` (`first_name`, `last_name`, `points`) 
SELECT first_name, last_name, points * 1.2 FROM students WHERE id = 3
We can use
sub-query
in INSERT statement. Before inserting the record,
sub-query
gets
gender_id
based on the provided gender name
INSERT INTO students (
    first_name, 
    last_name, 
    points,
    gender_id
) 
VALUES (
    'ილია', 
    'დავითაშვილი', 
    '84',
    (SELECT id FROM genders WHERE name = 'Male')
)
```
by Valeri Tandilashvili
4 years ago
0
MySQL
INSERT
1
set url parameter(s) from javascript CODE
Usage: set 1 parameter
setUrlParameter({'param_name': 'value1'})
set multiple parameters
setUrlParameter({'param_name': 'value1', 'param_name2': 'value2'})
open the altered url in new tab:
setUrlParameter({'param_name': 'value1'}, true)
get string of updated url instead of redirecting:
let url = setUrlParameter({'param_name': 'value1'}, null, true)
update custom url string instead of using current page url:
setUrlParameter({'param_name': 'value1'}, null, null, 'https://youtube.com')
function setUrlParameter(NameValuePairs, newTab = false, get_string = false, custom_url = false)
{
    let url;
    if(custom_url){
      url = custom_url;
    }else{
      url = window.location.href;
    }
    let hash = location.hash;
    url = url.replace(hash, '');

    for(const ParamNameKey in NameValuePairs){
      if(NameValuePairs.hasOwnProperty(ParamNameKey)){

      
        let paramName = encodeURIComponent(ParamNameKey);
        if (url.indexOf(paramName + "=") >= 0)
        {
            let prefix = url.substring(0, url.indexOf(paramName + "=")); 
            let suffix = url.substring(url.indexOf(paramName + "="));
            suffix = suffix.substring(suffix.indexOf("=") + 1);
            suffix = (suffix.indexOf("&") >= 0) ? suffix.substring(suffix.indexOf("&")) : "";
            url = prefix + paramName + "=" + NameValuePairs[ParamNameKey] + suffix;
        }
        else
        {
        if (url.indexOf("?") < 0)
            url += "?" + paramName + "=" + NameValuePairs[ParamNameKey];
        else
            url += "&" + paramName + "=" + NameValuePairs[ParamNameKey];
        }
      }
    }
    if(newTab == true){
      window.open((url + hash), '_blank');
    }else if(get_string === true){
      return (url + hash);
    }else{
      window.location.href = url + hash;
    }
    
}
by გიორგი უზნაძე
4 years ago
0
JavaScript
URL
1
Find duplicate values in one column:
SELECT 
    email, 
    COUNT(email) AS cnt
FROM
    contacts
GROUP BY email
HAVING cnt > 1;
Find duplicate values in multiple columns:
SELECT 
    first_name, COUNT(first_name) as cnt_fn,
    last_name,  COUNT(last_name)  as cnt_ln,
    email,      COUNT(email)  as cnt_m
FROM
    users
GROUP BY 
    first_name , 
    last_name , 
    email
HAVING  cnt_fn > 1
    AND cnt_ln > 1
    AND cnt_m > 1;
by Luka Tatarishvili
4 years ago
3
MySQL
Select
1
disable safe update
# Disables safe update temporarily 
SET SQL_SAFE_UPDATES = 0;

# Updates multiple rows at once
UPDATE notes SET priority = 100 WHERE priority = 0;

# Enables safe update
SET SQL_SAFE_UPDATES = 1;
by Valeri Tandilashvili
4 years ago
0
MySQL
alter
1
Grant all privileges
Grants all privileges to
some_user
user on all
some_db
database tables
GRANT ALL PRIVILEGES ON some_db.* TO 'some_user'@'localhost';
by Valeri Tandilashvili
4 years ago
0
MySQL
GRANT
1
Results: 1580