lundi 8 janvier 2024

Laravel 5.3, empty() is treating a zero value as empty in a query

In my Laravel project (version 5.3), I'm sending a param in a URL:

&container=0

But by the time it gets into the PHP function that creates an SQL query, it treats the zero as empty and satisfies the empty string portion of this line:

$containerCL = empty($container) ? '' : "AND SHPTABLE.CNT IN (".implode(',',$container).")";

I do want to send an empty string into the query if no option is chosen for this, but in this case, I need to send the zero value as we have some records identified by that being the actual value. How can I let this catch empty parameters but still use zero as an actual value for the query?



via Chebli Mohamed

dimanche 31 décembre 2023

livewire 3 how to store foreach value using form

hello I'm new for livewire 3 I have table inside form, data table having radio button for yes or no after selecting yes or no I'm going to submit that form that time I want to store fetch detail like id and name along this. now I'm any getting radio button value, me to solve

form page enter image description here my code form

<div class="modal-body">
    <form wire:submit.prevent="Save" autocomplete="off">
      <div class="card card-bordered card-preview table-responsive ">
        <div class="card-inner "> 
          <table class="datatable  table   ">
            <thead>
              <tr>
                <th style=" border: 1px solid black; text-align: center;">SL</th>
                <th style=" border: 1px solid black; text-align: center;">ID No</th> 
                <th style=" border: 1px solid black; text-align: center;">NAME</th>
                <th style=" border: 1px solid black; text-align: center;">YES</th>
                <th style=" border: 1px solid black; text-align: center;">NO</th>
              </tr>
            </thead>
            <tbody> 
 @foreach ($UserDetail as $key=>$UserDetails) 
 @php $ID = 0+$key @endphp
<td style=" border: 1px solid black; text-align: center;">
                
              </td> 
              <td style=" border: 1px solid black; text-align: center;">
                
              </td>
              <td style=" border: 1px solid black; text-align: center;">
                
              </td>
              <td style=" border: 1px solid black; text-align: center;">
                <div class="custom-control custom-control-md custom-radio ">
                  <input type="radio" wire:model="TableInput..data" class="custom-control-input" name="TableInputs[]" id="sv2-preference-fedev" value="YES" required>
                  <label class="custom-control-label" for="sv2-preference-fedev"></label>
                </div>
              </td>
              <td style=" border: 1px solid black; text-align: center;">
                <div style="text-align: center;" class="custom-control custom-control-md custom radio"><input type="radio" wire:model="TableInput..data" class="custom-control-input" name="TableInputs[]" id="sv2-preference-uxdis" value="NO" required>
                  <label class="custom-control-label" for="sv2-preference-uxdis"></label>
                </div>
              </td> 
              </tr> 
      @endforeach 
            </tbody>
          </table>
        </div>
      </div>
      <br>
      <div  >
        <button type="submit" class="btn btn-md btn-primary">SAVE  </button>
      </div>
    </form>
  </div>

Controller class StudentAttendance extends Component {

public $name; 
public $id;  
public $TableInput = [];


public function mount()
{
  $this->User       = User::all();   
}

public function Save() 
{   
    $bel = Data::create([ 
         
        'Id'                     => $value['Id'],
        'name'                   => $value['name'],
        'data'                   => $value['data'],
    ]);
} 
} 

}



via Chebli Mohamed

mercredi 6 décembre 2023

FatalErrorException in Handler.php line 26

While migrating to Laravel 5.0 from 4.2 I am getting this error

FatalErrorException in Handler.php line 26: Uncaught TypeError: Argument 1 passed to App\Exceptions\Handler::report() must be an instance of Exception, instance of Error given, called in \vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php on line 74 and defined in C:\app\Exceptions\Handler.php:26 Stack trace: #0 \vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(74): App\Exceptions\Handler->report(Object(Error)) #1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Error)) #2 {main} thrown

I have migrated one application from laravel 4.2 to laravel 5.0, placed all the code according to requirement and done composer update command but white executing this I am getting this error.



via Chebli Mohamed

How can I use websockets in Flutter?

I am trying to implement WebSockets for a Laravel-Flutter project. For the Laravel side, I followed these steps. If you see anything wrong or missing, please feel free to say:

https://gist.github.com/emir-ekin-ors/79e670eb6ea970af38c476a8087c19ea

When I test it with Tinker, I can see the event in the dashboard. So I assume the Laravel part is working properly.

The problem is when I try to listen to the channel in Flutter. I can't see anything on the terminal. I tried to follow the documentation of the web_socket_channel package. I am open to all the suggestions since I know nothing about websockets. You can find the Flutter code below:


import 'dart:async';

import 'package:flutter/material.dart';
import 'package:web_socket_channel/web_socket_channel.dart';

void main() {
    runApp(MyApp());
}

class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return MaterialApp(
            home: MyWebSocketScreen(),
        );
    }
}

class MyWebSocketScreen extends StatefulWidget {
    @override
    _MyWebSocketScreenState createState() => _MyWebSocketScreenState();
}

class _MyWebSocketScreenState extends State<MyWebSocketScreen> {
    late final _channel;
    late StreamSubscription _streamSubscription;

    @override
    void initState() {
        super.initState();
        _channel = WebSocketChannel.connect(Uri.parse('wss://localhost:6001'));
        _streamSubscription = _channel.stream.listen((data) {
            print('Received: $data');
        }, onError: (error) {
            print('Error: $error');
        });
    }

    @override
    Widget build(BuildContext context) {
        return Placeholder();
    }

    @override
    void dispose() {
        _streamSubscription.cancel();
        _channel.sink.close();
        super.dispose();
    }
}

This is the NewMessage class in Laravel if it necessary:


<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class NewMessage implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $message;

    public function __construct($message)
    {
        $this->message = $message;
    }

    public function broadcastOn(): array
    {
        return [
            new Channel('home'),
        ];
    }
}


via Chebli Mohamed

samedi 2 décembre 2023

I have encrypted data in the database how to decrypt it before displaying in the frontend in crocodic-studio / crudbooster?

I have the following form -

$this->form[] = ['label'=>'Client Name','name'=>'client_id','type'=>'select','validation'=>'required|integer|min:0','width'=>'col-sm-10','datatable'=>'client,client_name','datatable_where'=>'status=1'];
$this->form[] = ['label'=>'Client Code','name'=>'user_id','type'=>'select','validation'=>'required|integer|min:0','width'=>'col-sm-10','datatable'=>'cms_users,name','datatable_where'=>'id_cms_privileges = 3 and blocked=0','parent_select'=>'client_id'];

cms_users,name is encrypted using the laravel encryption - Crypt::encryptString($postdata['name'], env('ENC_KEY'));

Now the problem is when I am clicking on the Client name dropdown I get the encrypted value in the Client Code dropdown.

I want to decrypt the value before displaying to the Client Code dropdown. How to solve this issue??

enter image description here



via Chebli Mohamed

vendredi 1 décembre 2023

Laravel validation regex depends upon dependent answer

We have 2 questions 'temp_id_type' with Select Options 'A','B', 'C' 'temp_id' text field

Validation rule required on temp_id

  • requied_if:temp_id_type,A,B,C Also I need regex rule on temp_id
  • if temp_id_type=A - regex should match: ^[0-9]{13}$
  • if temp_id_type=B - regex should match: ^[0-9]{13,20}$
  • if temp_id_type=C - regex should match: ^[A-Z]{2}[0-9]{2}[A-Z0-9]{1,35}$


via Chebli Mohamed

mercredi 29 novembre 2023

Getting data from database in jquery

I want to get yeniseries values ​​from the database, i can use the API but I don't know what I should add to the javascript code, I would be happy if you help me.

var yeniSeries = [50, 80, 30];

window.addEventListener("load", function () {
  try {
    var grafikYapilandirma = {
      chart: {
        type: "donut",
        width: 370,
        height: 430,
      },
      colors: ["#622bd7", "#e2a03f", "#e7515a", "#e2a03f"],
      dataLabels: {
        enabled: false,
      },
      legend: {
        position: "bottom",
        horizontalAlign: "center",
        fontSize: "14px",
        markers: {
          width: 10,
          height: 10,
          offsetX: -5,
          offsetY: 0,
        },
        itemMargin: {
          horizontal: 10,
          vertical: 30,
        },
      },
      plotOptions: {
        pie: {
          donut: {
            size: "75%",
            background: "transparent",
            labels: {
              show: true,
              name: {
                show: true,
                fontSize: "29px",
                fontFamily: "Nunito, sans-serif",
                color: undefined,
                offsetY: -10,
              },
              value: {
                show: true,
                fontSize: "26px",
                fontFamily: "Nunito, sans-serif",
                color: "#1ad271",
                offsetY: 16,
                formatter: function (t) {
                  return t;
                },
              },
              total: {
                show: true,
                showAlways: true,
                label: "Total",
                color: "#888ea8",
                formatter: function (t) {
                  return t.globals.seriesTotals.reduce(function (n, e) {
                    return n + e;
                  }, 0);
                },
              },
            },
          },
        },
      },
      stroke: {
        show: true,
        width: 15,
        colors: "#0e1726",
      },
      series: yeniSeries,
      labels: ["Online", "Offline", "Rest"],
      responsive: [
        { breakpoint: 1440, options: { chart: { width: 325 } } },
        { breakpoint: 1199, options: { chart: { width: 380 } } },
        { breakpoint: 575, options: { chart: { width: 320 } } },
      ],
    };

    var grafik = new ApexCharts(
      document.querySelector("#chart-2"),
      grafikYapilandirma,
    );

    grafik.render();

    document
      .querySelector(".theme-toggle")
      .addEventListener("click", function () {
        var yeniSeries = [200, 300, 500];

        grafik.updateOptions({ series: yeniSeries });
      });
  } catch (hata) {
    console.log(hata);
  }
});

I would appreciate it if you could help, thank you



via Chebli Mohamed