jeudi 20 octobre 2022

Cannot move image/files temp to public directory Laravel 9

I am trying to upload image in Laravel. Getting following error:

enter image description here

My code is given below:

public function uploadImage($image, $image_path)
{
    $path = config('global.' . $image_path . '_image_path');

    file_exists($image) && unlink($image);

    $image_name = 'bvend-' . $image_path . '-' . time() . '.' . $image->getClientOriginalExtension();

    $image->move($path, $image_name); // $path: public_path('uploads/products')
    return $image_name;
}

I understand its a simple issue but still no clue where it causing issue.



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

Call to undefined function Collective\Html\is_iterable()

`(2/2) ErrorException Call to undefined function Collective\Html\is_iterable() (View: /home/finocoin/public_html/mocktest/Themes/themeone/views/exams/quiz/update-questions.blade.php)

in FormBuilder.php (line 741) at CompilerEngine->handleViewException(object(FatalThrowableError), 1) in PhpEngine.php (line 47)`



via Chebli Mohamed

lundi 17 octobre 2022

Validating filename of uploaded file in Laravel 5.4

How can I validate the filename of uploaded image file?

The scenario is:

When a user upload an image the filename must its id, if not then it will throw an message that the filename must the user id.

This is my code:

    $validation = Validator::make($request->all(), [
            'documenttosubmit' => 'required|array',
            'datesubmitted' => 'required|array',
            'file' => 'array',
            'file.*' => 'mimetypes:' . implode(",", $allowedMimes) . '|max:' . (AppDocSubmitted::MAX_FILE_SIZE * 1024), 
        ], [
            'file.*.mimetypes' => 'File must be an image (jpg/jpeg/png) or a document (pdf).',
            'file.*.max' => 'File size must be less than the maximum size of ' . AppDocSubmitted::MAX_FILE_SIZE . 'MB',
        ]);


via Chebli Mohamed

Laravel 9 - How to validate user with sanctum in Request

I have a route with the sanctum middleware, the idea of ​​this route is that only those users with a token can access it.

If I make a call with a correct token, the method works, if I try to make the query with an INVALID token, it returns an error that I can't control.

What I try by code is that if the token is not valid, it returns a 401 (unauthorized)

Route

Route::middleware('auth:sanctum')->post('cars', [CarsController::class, 'videoStore'])
    ->name('api.cars.store');

Request

 /** 
 * @param CarStoreRequest $request
 * @return Application|ResponseFactory|\Illuminate\Http\Response
 */
 public function carStore (CarStoreRequest $request)
 {

     $user = Auth::user();

     if ($user === null) {
         return response('Unauthorized', Response::HTTP_UNAUTHORIZED);
    }
 }

API action

<?php

namespace App\Http\Requests\V1;

use Illuminate\Foundation\Http\FormRequest;

class CarStoreRequest extends FormRequest
{

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {

        return [
            'image' => 'required|mimes:jpeg,jpg|max:30000',
        ];
    }
}

This is the error received with 401 http status code.

{
    "message": "",
    "exception": "Symfony\\Component\\HttpKernel\\Exception\\HttpException",
    "file": "C:\\xampp\\htdocs\\test-api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php",
    "line": 1151,
    "trace": [
        {
            "file": "C:\\xampp\\htdocs\\test-api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\helpers.php",
            "line": 45,
            "function": "abort",
            "class": "Illuminate\\Foundation\\Application",
            "type": "->"
        },
        {
            "file": "C:\\xampp\\htdocs\\test-api\\app\\Exceptions\\Handler.php",
            "line": 56,
            "function": "abort"
        },


via Chebli Mohamed

why .env file configuration in laravel is not working it can't work

$this->ketnoi = mysqli_connect($_ENV['DB_HOST'], $_ENV['DB_USERNAME'], $_ENV['DB_PASSWORD'], $_ENV['DB_DATABASE']) or die('Error => DATABASE');



via Chebli Mohamed