Skip to content

Instantly share code, notes, and snippets.

View amberlex78's full-sized avatar
🏠
Working from home

Oleksii Abrosymov amberlex78

🏠
Working from home
View GitHub Profile
@amberlex78
amberlex78 / many-to-many
Last active April 7, 2024 15:41
SQL many-to-many (users of task)
SELECT * FROM `tasks2users`
JOIN `users` ON (`tasks2users`.`user_id` = `users`.`id`)
JOIN `tasks` ON (`tasks2users`.`task_id` = `tasks`.`id`)
@amberlex78
amberlex78 / Tree.php
Last active August 29, 2015 14:26
Tree::flat2nested($arr);
<?php
/*
-----------------------------------
Reformat flat array to nested array
-----------------------------------
Array(
[2] => Array(
[id] => 2
[parent_id] => 0
<?php
// Поиск цены в строке
// Число типа: 27.30 или 33,56
preg_match('/[0-9]*[\.,]?[0-9]/', $text, $matches);
if (isset($matches[0])) {
$price = str_replace(',', '.', $matches[0]);
} else {
@amberlex78
amberlex78 / mail.php
Created October 3, 2015 07:12
Clean PHP code for mail
<?php
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=utf-8";
$headers[] = "From: Sender Name <[email protected]>";
$headers[] = "Bcc: JJ Chong <[email protected]>";
$headers[] = "Reply-To: Recipient Name <[email protected]>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
@amberlex78
amberlex78 / highlighting_multi_level_menu.md
Created August 9, 2020 07:04
Highlighting multi-level menu items

Highlighting multi-level menu items

In a multi-level menu, you usually have to highlight the selected menu item and its parent element. This can be done based on the parent route.

<ul>
  <li>
    <a href="{{ route('admin.posts.index') }}"
       class="{{ Str::is('admin.posts.*', Route::currentRouteName()) ? 'is-active' : '' }}">
 Manage Posts
@amberlex78
amberlex78 / display_query_or_log.md
Created August 9, 2020 07:36
Display or log query

Display or log query

Display query

Add code in a file:

\DB::enableQueryLog();

$user = App\User::get();
@amberlex78
amberlex78 / mysql_version.php
Last active December 15, 2021 07:52
Laravel: Get mysql version
<?php
$v = \DB::select("select version()")[0]->{"version()"};
$v = explode('-', $v)[0];
@amberlex78
amberlex78 / AjaxController.php
Last active December 15, 2021 08:02
Symfony 5.4, PHP 8: Change bool status with error handling
<?php
namespace App\Controller\Admin;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
@amberlex78
amberlex78 / PostFetcher.php
Last active December 15, 2021 07:55
Symfony 5.4: Get all posts ids by slug of tag
<?php
namespace App\ReadModel\Blog;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
class PostFetcher
{
public function __construct(
@amberlex78
amberlex78 / BladeServiceProvider.php
Last active January 21, 2022 18:39
Example BladeServiceProvider with Form::component-s for Laravel with laravelcollective
<?php
class BladeServiceProvider extends ServiceProvider
{
public function boot(): void
{
Form::component('bsText', 'collective.form.text', [
'label', 'name', 'value' => null, 'attributes' => []
]);