Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
Both ID Name URL support
Both ID and Name of the record is supported with GET URL
public function showUpcomingProject($id){

    if (intval($id)) {
        $item = UpcomingProject::with('projectBlockchain')->findOrFail($id);
    } else {
        $item = UpcomingProject::with('projectBlockchain')->where('token_name', $id)->first();
    }
    if (!$item) {
        return abort(404);
    }
    $blockchains = Blockchain::all();

    return view(strtolower($this->title).'.home.upcoming_project', compact('item', 'blockchains'))->with('svg_renderer', SvgHelper::getBlockchainSvgs($blockchains));

}
If number is passed to the function as the record ID then
if statement
will run. If the
token_name
is passed then
else
will run. If the record is not found, then
404
error is thrown to the client Route Code for the feature:
    Route::get('/upcoming-projects/{id}', [ExternalController::class, 'showUpcomingProject']);
by Valeri Tandilashvili
3 years ago
0
Laravel
0
Laravel project settings by environment
Local environment settings:
APP_ENV=local
APP_DEBUG=true
Test environment settings:
APP_ENV=testing
APP_DEBUG=true
Production environment settings:
APP_ENV=production
APP_DEBUG=false
The main difference is that errors are not shown on production, also prevention mechanisms from deleting DB data using migration tools
by Valeri Tandilashvili
3 years ago
0
Laravel
0
Disable / enable foreign key checks
First we disable
FOREIGN_KEY_CHECKS
to be able to run queries, then we enable
FOREIGN_KEY_CHECKS
back
SET FOREIGN_KEY_CHECKS=0;
--- Runs some SQL query - for example deleting some rows from a table that has foreign keys
SET FOREIGN_KEY_CHECKS=1;
by Valeri Tandilashvili
3 years ago
0
MySQL
1
send auto messages fb
import pyautogui
import time

msg = input("message: ")
n = input("amount of msg : ")

count = 5

while(count != 0):
    print(count)
    time.sleep(1)
    count -= 1

print("Fire in the hole")

for i in range(0,int(n)):
    time.sleep(0.2)
    pyautogui.typewrite(msg + '\n')
by Luka Tatarishvili
3 years ago
0
0
Check if column exist in table
Import schema

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
if (Schema::hasColumn($table, 'deleted_at')){ 
   Query 1
}else{
   Query 2
}
This is useful if we use one query in multiple resources but there is some differences in table structure and we need to use this column in condition: for example:

 if (Schema::hasColumn($table, 'deleted_at')){
            $query = "SELECT
                $columns_str
                -- c1.order_priority,
                (
                    SELECT
                        Count(c2.id)
                    FROM
                        $table AS c2
                    WHERE
                        c2.parent_id = c1.id
                )
                AS children_count
            FROM
                $table AS c1
            WHERE deleted_at IS NULL
                ORDER BY ".($order_priority ? 'order_priority' : 'id')." DESC";
        }else{
            $query = "SELECT
                $columns_str
                -- c1.order_priority,
                (
                    SELECT
                        Count(c2.id)
                    FROM
                        $table AS c2
                    WHERE
                        c2.parent_id = c1.id
                )
                AS children_count
            FROM
                $table AS c1
                ORDER BY ".($order_priority ? 'order_priority' : 'id')." DESC";
        }
We use
   WHERE deleted_at IS NULL
where we have deleted_at column
by Luka Tatarishvili
3 years ago
0
Laravel
database
0
Install Certbot and it’s Nginx plugin with apt:
sudo apt install certbot python3-certbot-nginx
Verifies the syntax of your configuration edits:
sudo nginx -t
Reload Nginx to load the new configuration:
sudo systemctl reload nginx
To see the current setting of firewall:
sudo ufw status
Allows the Nginx Full profile and delete the redundant Nginx HTTP profile allowance:
sudo ufw allow 'Nginx Full'
sudo ufw delete allow 'Nginx HTTP'
Obtaining an SSL Certificate
sudo certbot --nginx -d example.com
Verifying Certbot Auto-Renewal:
sudo systemctl status certbot.timer
To test the renewal process, you can do a dry run with
certbot
:
sudo certbot renew --dry-run
by Valeri Tandilashvili
3 years ago
0
Linux
HTTPS
0
failed to open stream: Permission denied
fopen(/var/www/test.sdtokens.com/storage/app/public/images/mesk.webp): failed to open stream: Permission denied
Solution to the problem is running these commands to get the permissions
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

php artisan storage:link
by Valeri Tandilashvili
3 years ago
0
Linux
0
Select every Nth row
Selects every 5th row of
sdt_prices
table
SELECT *
FROM ( 
    SELECT @row := @row +1 AS rownum, sdt_prices.*
    FROM (
        SELECT @row :=0) r, sdt_prices where token_id = 1 order by id desc
    ) ranked
WHERE rownum %5 = 1
by Valeri Tandilashvili
3 years ago
0
MySQL
ROWNUM
0
1)
var data = {!!json_encode($collection, JSON_UNESCAPED_SLASHES|JSON_HEX_APOS)!!};
2)Or use
@json
directive
var data = @json($collection);
by გიორგი უზნაძე
3 years ago
0
0
number_format
The default
thousands_separator
is
,
which is 4th parameter. Without passing something else for the
thousands_separator
parameter, the
latency
was equal to
1,511.68525
The following PHP code caused problem in MySQL
$this->latency = number_format(microtime(1)-$_SESSION['startTime'], 5);
MySQL error:
SQLSTATE[01000]: Warning: 1265 Data truncated for column 'latency' at row 1
Solution to the problem is to specify the 4th parameter as an empty string
""
to get
latency
equal to
1511.68525
$this->latency = number_format(microtime(1)-$_SESSION['startTime'], 5, '.', '');
by Valeri Tandilashvili
3 years ago
0
PHP
functions
0
Results: 1578