lundi 19 septembre 2022

I want to create a settings popup in which the user can select the custom directory to read files. How can I do that?

I have tested some files from the public folder of my Laravel app and the path for that is;

C:\xampp\htdocs\EDI_System\public\files\pending

but this one is static I want to make a setting popup where users can set a custom path for that like if the files exist in D:\new_files the setting popup appears and the selection of the directory can be made.

i want my settings to be like that

Your help will be much appriciated. Thank you



via Chebli Mohamed

vendredi 16 septembre 2022

XMLRPC library for API in laravel

I want to use XMLRPC to get my API results and show them in XML format in laravel project. I've seen numerous examples for XMLRPC for PHP but can't find any for laravel yet. API i'm using is Wired wubook api: https://tdocs.wubook.net/wired.html

To access the rates of rooms I've generated the permanent token and lcode to run this code in laravel project: fetch_rooms(token, lcode, ancillary=0) I just don't know the method of XMLRPC through which I can call my wubook api results inside laravel project.

enter image description here

Any help through which I can use XMLRPC in laravel and call my API results in project?



via Chebli Mohamed

jeudi 15 septembre 2022

fix double payments - double purchases

i'm implementing an online payment platform similar to paypal, the problem is that when they click on the buy button 2 times or more quickly and this causes the payment to register twice instead of once

When you click buy execute this action:

     public function invoke(Request $request) {
    
      $payment_id = $request->get('payment_id');
    
      $credenciales = config('services.mercadopago.token');
      $request->get('user_id'));
    
      $response = Http::get("https://api.mercadopago.com/v1/payments/$payment_id" . "?access_token=$credenciales");
      
      $response = json_decode($response);

  $request->session()->put('order', $response->order->id);
  $request->session()->put('ingreso', $response->transaction_details->net_received_amount);
  $request->session()->put('monto', $response->transaction_details->total_paid_amount);
  $request->session()->put('method', $response->payment_type_id); 
 $status = $response->status;

If the answer is approved run this:

if($status == 'approved') {


  Income::insert([
    'user_id'       => Session::get('user_id'),
    'evento_id'       => Session::get('variableName'),
    //Guardar el personal seleccionado
    'mp_id'  => Session::get('order'),
    'metodo'        => Session::get('metodo'),
    'monto'        => Session::get('monto'),
    'rrpp_id'         => Session::get('rrpp'),
    'ingreso'        => Session::get('ingreso'),


  ]);

  OrderNew::insert([
    'user_id'       => Session::get('user_id'),
    'dia_id'       => Session::get('variableName'),
    //Guardar el personal seleccionado
    'whatsapp'  => Session::get('telefono'),
    'cantidad'        => Session::get('cantidad'),
    'anticipada'        => Session::get('anticipada'),
    'horario'        => Session::get('horario'),
    'rrpp'         => Session::get('rrpp'),
    'pagado'        => '1',
    'tipo'        => 'vip',
    'codigo'        => rand(1580, 4005),


  ]);

in the first model I register the incoming money and in the second model I register the customer's order

and there is the problem, if they click on Buy several times, the records are duplicated and they get free products

How can I limit or solve this problem?



via Chebli Mohamed

mardi 13 septembre 2022

Laravel import Seed Class into Command [closed]

I want to execute a Seed Class by running a Laravel Command. My problem is that I can`t correctly import, so my code get thrown with

Target class [TestSeeder] does not exist. inside TestCommand.php.

I am on Laravel 5 and have created both classes via CLI make:seed and make:command, as result the classes are saved in the according folders. I have read some solutions regarding composer dump-autoload but this gets stuck in endless loop, maybe because its a huge codebase..

database\seeds\TestSeeder.php

<?php

use App\Models\Hotel;
use Illuminate\Database\Seeder;

class TestSeeder extends Seeder
{
    public function run(int $id)
    {
       // do stuff with {id}..
    }
}

app\console\commands\TestCommand.php

<?php

use Illuminate\Console\Command;
use Database\Seeds\TestSeeder;

class TestCommand extends Command
{

    protected $signature = 'test:data';

    protected $description = 'Add default data to the database for specific id via Seeder';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        $id = $this->ask('Please enter the id for which you want to add the seed data');

        if (!$id) {
            $this->error('No id given');
            return;
        }

        // $this->call(TestSeeder::class, ['id' => $id]);
        $testSeeder = new TestSeeder();
        $testSeeder->run($id);
    }
}



via Chebli Mohamed

lundi 12 septembre 2022

How to read 2 date formats in laravel-excel (maatsweb v 2.1)

I am using Laravel excel (maatsweb excel v 2.1 https://docs.laravel-excel.com/2.1/import/dates.html) and laravel 5.5.

I have an issue when the field is date and there are 2 formats.

The first format is visible when opening the xcel with an xcel reader like LibreOffice. Lets say the user sees date as "02 Jan 2022"

The second format is visible when I click on the date cell - it shows another format. Lets say "01/02/2022"

When I call

$this->excelObj->get()

this returns one format (lets say "01/02/2022") But when I read the same file with

$this->excelObj->chunk(..

It returns the other format ("02 Jan 2022")

How can I have it read the same way? Is there a setting to make them behave the same?



via Chebli Mohamed

samedi 10 septembre 2022

Undefined variable: sub inside the foreach loop in laravel

Controller:

public function dashboard()
{
    $course = Course::all();
    return view('content.dashboard',compact('course'));
}

View:

@foreach($course as $year)

    $sub = \App\Models\SubCourse::where('course_id',$year->id)->first();
    @dd($sub->id);

@endforeach

In the above code I am trying to get value of SubCourse but it throw an error i.e. Undefined variable: sub (View: C:\xampp\htdocs\example\resources\views\content\dashboard.blade.php). I don't know why? Please help me.

Thank you



via Chebli Mohamed

vendredi 9 septembre 2022

i want to arrange the data as in text file but its format has been changed when i tried to get the file from directory and displayed in an app

I want to arrange the data as in a text file but its format has been changed when I tried to get the file from a directory and displayed it in an app the problem for me is it has no reference point at the line ending so I don't know how can I explode it Here is the file format: This is how data should look

and this is how I am getting data: This is how m getting the data now

one more thing from these lines I want to pick some data to be stored how can I pick data without reference points?

I mean as you see here:

PIDF***HEMP ZONE ULTRA THIN ROLLING PAPERS 1.25" 25CT~

we have * and ~ to explode and get the data in array format but how can we pick data when the data is like that:

B84921501625VSSE ALTO MENT 463405005397BX00090500360078000

"as I want to pick the name "ALTO MENT" 4, "63405005397

how can I pick that data?

Here is what I did till now:

     public function read_confirmation(){
    $cpath = public_path('confirmations\pending');
    $c_allfiles = scandir($cpath);
    $c_allfiles = array_diff(scandir($cpath), array('.', '..'));
    foreach ($c_allfiles as $fname) {
        $file= File::get(public_path('confirmations\pending/'.$fname));
        return $file;}

 }


via Chebli Mohamed