Results: 1580
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
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
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
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
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
Makes the array member stay filled after backend validation is failed
Makes the array member stay filled if the form is not successfully validated on the backend:
$item_presale_tokens = old('values.0');
$item_liquidity_tokens = old('values.1');
Form html looks like this:
<div class="form-group d-flex border-bottom-0">
    <div class="form-equal-inputs">
        <input type="number" step="1" min="1" value="{{ $item_presale_tokens }}" class="form-control {{ $errors->has('values.0') ? 'is-invalid' : '' }}" name="values[]" placeholder="Value"/>
    </div>
    

</div>

<div class="form-group d-flex border-bottom-0">
    <div class="form-equal-inputs">
        <input type="number" step="1" min="1" value="{{ $item_liquidity_tokens }}" class="form-control {{ $errors->has('values.1') ? 'is-invalid' : '' }}" name="values[]" placeholder="Value"/>
    </div>
</div>
by Valeri Tandilashvili
3 years ago
0
Laravel
0
Include .blade.php file
Includes
.blade.php
file located at:
\resources\views\external\calculator
<div class="container">
    
    @include('external.calculator.panel')

</div>
by Valeri Tandilashvili
3 years ago
0
Laravel
0
set identifier name to foreign key
When we have an Identifier name on the foreign key is a too-long error we can set name ourselves. Note:
Max foreign char size is 64
Example: Before:
$table->foreign('risk_project_id',)->references('id')->on('business_risk_projects')->onDelete('restrict');
Solution:
$table->foreign('risk_project_id', 
'business_rp_has_responsible_persons_risk_project_id_foreign'
)->references('id')->on('business_risk_projects')->onDelete('restrict');
Just add a second parameter to the foreign() method with the name of the key 
by Luka Tatarishvili
3 years ago
0
Laravel
0
If we have a table with a seeder and we want to add a foreign key to a column it must contain the correct id value or it can't be empty.
You can't use a value that doesn't belong to any entity in the other table nor delete one entity who has its ID in some other foreign_key in some other entity
by Luka Tatarishvili
3 years ago
0
Laravel
database
0
UTF-8 Unicode problem while json_encode()
JSON_UNESCAPED_UNICODE Json:
"[{"name":"additional[text][9]","value":"\u10e1 \u10d3\u10d0\u10e1\u10d0\u10d1\u10e3\u10d7\u10d4\u10d1\u10d0 (Judgement process"},{"name":"additional[text][3]","value":"version"}]"
If our json contains something like this
\u10d3\u10d0\u10e1\u10d0\u10d1\u10e3\u10d7\u10d4\u10d1\u10d0
we have UTF-8 unicode problem.
JSON_UNESCAPED_UNICODE
fixes this problem, so we can encode json like this
json_encode($request->field_data, JSON_UNESCAPED_UNICODE)
by Luka Tatarishvili
3 years ago
0
JSON
Laravel
DBquery
0
Sort array of arrays by sub-array values
We need to sort the array by
price
value
$inventory = array(

   array("type"=>"fruit", "price"=>3.50),
   array("type"=>"milk", "price"=>2.90),
   array("type"=>"pork", "price"=>5.43),

);
The solution is to use
array_multisort
function
$price = array();
foreach ($inventory as $key => $row)
{
    $price[$key] = $row['price'];
}
array_multisort($price, SORT_DESC, $inventory);
In PHP 5.5 or later
array_column
function can be used
$price = array_column($inventory, 'price');

array_multisort($price, SORT_DESC, $inventory);
by Valeri Tandilashvili
3 years ago
0
PHP
0
Results: 1580