mercredi 26 octobre 2022

I want to pull mysql export text from laravel

I want to pull mysql export text from laravel

INSERT INTO 'example' ('id', 'name') VALUES (1, 'example'), 
(2, 'example2'),
(3, 'example3'),
(4, 'example4');

Like this

Thank you.

I searched for sql query but couldn't find it



via Chebli Mohamed

dimanche 23 octobre 2022

Can't seem to find a way to use the route.php from 5.2 from laravel 5.2 to 8.83.25 web.php

I'm pretty new with Laravel, was able to work on finding a tutorial but it uses a 5.2 version.

I'm trying to convert the older version to 8.83.25

This is the route in the tutorial that I'm following. I have created the CategoryController.php manually

Route::group(['middleware' => ['web']], function(){
    Route::get('category', 'CategoryController');
});

enter image description here



via Chebli Mohamed

samedi 22 octobre 2022

Laravel Trying to get property of non-object $-> non Object

    public function handle()
    {
        $response = json_decode(file_get_contents(config('app.vatusa_api_base') . '/facility/zdv/roster?apikey=' . config('app.vatusa_api_key')));

        // Create Users

        foreach ($response as $user) {
            if(!User::where('vatsim_id', $user->cid)->whereNull('home_facility')->count()) {
                switch($user->rating) {
                    case 12:
                        $rating = 'ADM';
                        break;

Attempting to Pull from Our API For a Roster though it seems that I have messed something up somewhere.

Any and all help is appreciated.



via Chebli Mohamed

vendredi 21 octobre 2022

Laravel Update from 4.2 to 5.6

I'm getting the following error when running composer install:

PHP Fatal error: Uncaught ReflectionException: Class App\Console\Kernel does not exist in /home/ubuntu/fusion/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:788 Stack trace: #0 /home/ubuntu/fusion/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(788): ReflectionClass->__construct('App\Console\Ker...') #1 /home/ubuntu/fusion/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(667): Illuminate\Container\Container->build('App\Console\Ker...') #2 /home/ubuntu/fusion/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(265): Illuminate\Container\Container->resolve('App\Console\Ker...', Array, false) #3 /home/ubuntu/fusion/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(785): Illuminate\Container\Container->Illuminate\Container{closure}(Object(Illuminate\Foundation\Application), Array) #4 /home/ubuntu/fusion/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(667): Illuminate\Container\Container- in /home/ubuntu/fusion/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 788

This is what I have in my composer.json

    "require": {
            "php": "^7.1.3",
            "fideloper/proxy": "^4.0",
            "laravel/framework": "5.8.*",
            "laravel/tinker": "^1.0"
        },
        "require-dev": {
            "filp/whoops": "^2.0",
            "fzaninotto/faker": "^1.4",
            "mockery/mockery": "^1.0",
            "nunomaduro/collision": "^2.0",
            "phpunit/phpunit": "^7.0"
        }

Thanks!



via Chebli Mohamed

jeudi 20 octobre 2022

Laravel instantiating $response takes abnormally long

I have a Laravel 5.8 application, with very long loading times. Laravel’s speed is debugable within the public/index.php file. Which I have tried like this:

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

dd(microtime(true) - LARAVEL_START); 

Between LARAVEL_START being set, and the response being sent, it will take a staggering six to fourteen seconds to load. Switching my code to:

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

dd(microtime(true) - LARAVEL_START);    

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

Will yield an average loading time of about 0.6 to 2 seconds between Laravel booting and $kernel being set. This means that loading the kernel takes an average of 1.2 seconds, and processing the request takes about 11-13 seconds. Now, what I have tried to speed up the fetching of a page so far:

Dumping cache

Most Laravel problems are usually solved by clearing the cache, running php artisan optimize, dumping composer autoload, etc. This didn't yield any time difference.

Reinstalling the project

I tried to reinstall the project from it's GitHub repository, which also had no impact on the loading times. I rebuild the docker container from scratch as well, more about docker in the next paragraph

Docker

As I have been doing a lot of research into why my Laravel application could be slow, I stumbled upon many articles stating that docker could slow down Laravel substantially. To combat this, I’ve tried the following:

PHP artisan serve, instead of using docker, I’ve tried to use the built in webserver. This does not speed up the application.

  • I switched between a few PHP 7.X versions, to no avail.
  • My other projects work fine with the artisan serve command. Loading times are somewhere around 20-200 milliseconds.

Xampp, does not speed up the executable time.

  • My other projects work fine with xampp. Loading times are around 20-300 milliseconds.

Controller debugging

As I have eliminated the possibility of my webserver being the bottleneck, I timed the difference between the first and last line of my controller like this:

public function index() 
{
    $time_start = microtime(true)
    // controller code (about 40 lines)
    dd($time_end - $time_start)
}

This yields the following results:

0.31205701828003
0.24561214447021
0.23838305473328
0.12146878242493
0.25613188743591
0.30584192276001

While these seem like respectable times, my application didn’t take the average time of 0.22 seconds to boot, but rather took the expected eight to twenty seconds to boot. I tried it once again, now with a fully empty controller like this:

public function index() 
{
    $time_start = microtime(true)
    dd($time_end - $time_start)
}

Which yields an average controller execute time of 0.0 seconds. While remaining as slow as before.

Middleware

My next thought would be to debug the middlewares my project uses. As it is an enterprise application, there is a lot of validation going on under the hood, which is run before every request gets to a controller. I started off by completely removing all middlewares from the routes/web.php file. Rerunning my application does not yield any time difference. With no middleware being run, I can conclude that my slow loading times aren't due to a unoptimized middleware.

Service providers

Just like the middleware, service providers run on every request. Removing all non-essential service providers in config/app.php yields no loading time difference.

Where to go from here?

My routes/web.php now looks like:

<?php

use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
 */

Route::get('/greeting', function () {
    return 'Hello World';
});

It still takes 12 seconds to load. It seems as though something is slowing down:

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

Yet, removing practically the entire project has close to zero effect on the projects speed. How can I speed up this essential project?



via Chebli Mohamed

after updating PHP to 7.4 my BarcodeGeneratorHTML crashed | Laravel,PHP

i used to use my Laravel Project with PhP 5.6 and i'm using barcode Gnerator for my project some where and to do this i use this package .

laravel/laravel barcode_blog

now i upgraded my PhP To 7.4 (note: didn't upgrade my laravel yet). everything is working fine just when i search for a spasific barcode i got this error :

ErrorException in BarcodeGenerator.php line 293: 
Array and string offset access syntax with curly braces is deprecated (View:.../.../..)

now this is the code :

<tr>
    <td width="19%">serial NUM</td>
    <td style="width: 1%">:</td>
    <td colspan="2">
     @if (!empty($INSTANCE))
       <?php $generator = new \Picqer\Barcode\BarcodeGeneratorHTML(); ?>
       {!! $generator->getBarcode($INSTANCE->barcode, $generator::TYPE_CODE_128) !!}
    @endif
    </td>
   </tr>

And I know the problem is with $generator = new \Picqer\Barcode\BarcodeGeneratorHTML(); this line when i delete it my code is working fine but i need it in the code how to use it in php 7.4 i belive it get changed



via Chebli Mohamed

mercredi 19 octobre 2022

Convert Raw Sql to laravel Query buider format

I have a raw query which works correctly.

SELECT a.date_demande,a.row, a.nom,a.prenom,a.timestamp_statut,a.timestamp_statut_fmt,a.dossier_id_rapproche,a.type_enquete,
a.enquete_statut,a.code_couleur,a.code,a.type_demande_libelle, a.type_demande_couleur,a.type_demande_code,a.type_demande_icone,a.type_demande_contester,
a.type_demande_contester,a.date_demande_origin,a.date_demande,a.dossier_id, a.prestataire_equipe, a.ref_client, a.client,a.standalone,a.demandeur,
a.lieu_naissance,a.lieu_deces,a.no_boite_lettre,a.cp,a.ville,b.Phone FROM
(select
  distinct `dossiers`.`id`,
  `dossiers`.`id` as `row`,
  `nom`.`originalValue` as `nom`,
  `prenom`.`originalValue` as `prenom`,
  `dossiers`.`timestamp_statut` as `timestamp_statut`,
  DATE_FORMAT(timestamp_statut, "%d/%m/%Y") AS timestamp_statut_fmt,
  `dossiers`.`dossier_id_rapproche` as `dossier_id_rapproche`,
  CONCAT(t1.type_enquete, ' - ', t1.lib_type_enquete) as type_enquete,
  `enquete_statuts`.`libelle` as `enquete_statut`,
  `enquete_statuts`.`code_couleur` as `code_couleur`,
  `enquete_statuts`.`code` as `code`,
  `type_demande_client`.`libelle` as `type_demande_libelle`,
  `type_demande_client`.`code_couleur` as `type_demande_couleur`,
  `type_demande_client`.`code` as `type_demande_code`,
  `type_demande_client`.`icone` as `type_demande_icone`,
  `type_demande_client`.`contester` as `type_demande_contester`,
  `date_demande` as `date_demande_origin`,
  DATE_FORMAT(date_demande, "%d/%m/%Y") AS date_demande,
  `affectation`.dossier_id AS dossier_id ,
  `affectation`.prestataire_equipe AS prestataire_equipe ,
  `ref_client`,
  `clients`.`nom_raison_sociale` as `client`,
  `clients`.`standalone` as `standalone`,
  `clients`.`demandeur` as `demandeur`,
  CONCAT(t2.type_enquete, ' - ', t2.lib_type_enquete) as `type_enquete_retrouve`,
  (
    CASE
      WHEN date_de_naissance.originalValue not like "%/%/%" THEN DATE_FORMAT(`date_de_naissance`.`originalValue`, "%d/%m/%Y")
      ELSE date_de_naissance.originalValue
    END
  ) AS date_naissance,
  `lieu_de_naissance`.`originalValue` as `lieu_naissance`,
  (
    CASE
      WHEN date_de_deces.originalValue not like "%/%/%" THEN DATE_FORMAT(`date_de_deces`.`originalValue`, "%d/%m/%Y")
      ELSE date_de_deces.originalValue
    END
  ) AS date_deces,
  `lieu_de_deces`.`originalValue` as `lieu_deces`,
   `adresse_bp`.`originalValue` as `no_boite_lettre`,
  (
    CASE
      WHEN code_postal_particulier.originalValue is not null
      AND ville_particulier.originalValue is not null THEN code_postal_particulier.originalValue
      WHEN code_postal_professionnel.originalValue is not null
      AND ville_professionnel.originalValue is not null THEN code_postal_professionnel.originalValue
      ELSE code_postal_particulier.originalValue
    END
  ) as cp,
  (
    CASE
      WHEN code_postal_particulier.originalValue is not null
      AND ville_particulier.originalValue is not null THEN ville_particulier.originalValue
      WHEN code_postal_professionnel.originalValue is not null
      AND ville_professionnel.originalValue is not null THEN ville_professionnel.originalValue
      ELSE ville_particulier.originalValue
    END
  ) as ville
from
  `dossiers`
  left join `index_dossiers` as `nom` on `dossiers`.`id` = `nom`.`dossier_id`
  and `nom`.`zone` = 'etat_civil.nom'
  left join `index_dossiers` as `prenom` on `dossiers`.`id` = `prenom`.`dossier_id`
  and `prenom`.`zone` = 'etat_civil.prenom'
  left join `index_dossiers` as `date_de_naissance` on `dossiers`.`id` = `date_de_naissance`.`dossier_id`
  and `date_de_naissance`.`zone` = 'etat_civil.date_naissance'
  left join `index_dossiers` as `lieu_de_naissance` on `dossiers`.`id` = `lieu_de_naissance`.`dossier_id`
  and `lieu_de_naissance`.`zone` = 'etat_civil.lieu_naissance'
  left join `index_dossiers` as `date_de_deces` on `dossiers`.`id` = `date_de_deces`.`dossier_id`
  and `date_de_deces`.`zone` = 'etat_civil.date_deces'
  left join `index_dossiers` as `lieu_de_deces` on `dossiers`.`id` = `lieu_de_deces`.`dossier_id`
  and `lieu_de_deces`.`zone` = 'etat_civil.lieu_deces'
  left join `index_dossiers` as `code_postal_particulier` on `dossiers`.`id` = `code_postal_particulier`.`dossier_id`
  and `code_postal_particulier`.`zone` = 'adresses.particulier_cp'
  left join `index_dossiers` as `code_postal_professionnel` on `dossiers`.`id` = `code_postal_professionnel`.`dossier_id`
  and `code_postal_professionnel`.`zone` = 'adresses.professionnel_cp'
  left join `index_dossiers` as `ville_particulier` on `dossiers`.`id` = `ville_particulier`.`dossier_id`
  and `ville_particulier`.`zone` = 'adresses.particulier_ville'
  left join `index_dossiers` as `ville_professionnel` on `dossiers`.`id` = `ville_professionnel`.`dossier_id`
  and `ville_professionnel`.`zone` = 'adresses.professionnel_ville'
   left join `index_dossiers` as `adresse_bp` on `dossiers`.`id` = `adresse_bp`.`dossier_id`
  and `adresse_bp`.`zone` = 'adresses.particulier_no_boite_lettre'
   left join `index_dossiers` as `telephone` on `dossiers`.`id` = `telephone`.`dossier_id`
  and `telephone`.`zone` = 'telephones.numtel'
  inner join `entites` as `e1` on `dossiers`.`entite_id` = `e1`.`id`
  inner join `clients` on `clients`.`entite_id` = `e1`.`id`
  left join `enquete_statuts` on `dossiers`.`enquete_statut_id` = `enquete_statuts`.`id`
  left join `type_demande_client` on `dossiers`.`type_demande_client_id` = `type_demande_client`.`id`
  inner join `type_enquetes` as `t1` on `dossiers`.`type_enquete_id` = `t1`.`id`
  left join `type_enquetes` as `t2` on `dossiers`.`type_enquete_id_retrouve` = `t2`.`id`
  left join `sous_enquetes` as `se` on `dossiers`.`id` = `se`.`dossier_id`
  left join `affectation_dossiers` on `se`.`id` = `affectation_dossiers`.`sous_enquete_id`
  left join (
    SELECT
      sous_enquetes.dossier_id,
      GROUP_CONCAT(
        case
          when users.name IS NOT NULL then users.name
          ELSE case
            when equipes.libelle IS NOT NULL then equipes.libelle
            when prestataires.nom_raison_sociale IS NOT NULL then prestataires.nom_raison_sociale
          End
        END
      ) AS prestataire_equipe
    FROM
      affectation_dossiers
      JOIN sous_enquetes ON affectation_dossiers.sous_enquete_id = sous_enquetes.id
      LEFT JOIN users ON affectation_dossiers.user_id = users.id
      LEFT JOIN entites AS e ON affectation_dossiers.entite_id = e.id
      LEFT JOIN equipes ON e.id = equipes.entite_id
      LEFT JOIN prestataires ON e.id = prestataires.entite_id
    GROUP BY
      sous_enquetes.dossier_id
  ) AS affectation on `dossiers`.`id` = `affectation`.`dossier_id`
where
  `date_demande` is not NULL) AS a
  
  INNER JOIN
  
(  SELECT 
    `dossier_id`,
    GROUP_CONCAT(`originalValue`) AS `Phone`
FROM `index_dossiers`
WHERE zone = 'telephones.numtel'
GROUP BY `dossier_id`) AS b

ON a.row = b.dossier_id

I am able to write each part of the query which returns a and b seperately as query builder. I am however unable to get both to work together.

Any help or tips would be appreciated. I have tried using some online tools but to no avail I can run the query with DB::select(DB:raw('query') to get the correct results. However the results are returned as an array. The expected output is an instance of query builder for further filtering.



via Chebli Mohamed