Laravel Mail why variable with array from database doesn’t work?

How can I add an array from the database to my email component in Laravel?

My controller:

$request = DB::table('Requests')->where('id', $id)->get();
$email = DB::table('Requests')->where('id', $id)->value('email');

 Mail::to($email)->send(new Order($request));

My e-mail component Order:

Dear {{ $request->name }}

I’ve read about to add an array with the compact(‘request’) function, but also this didn’t work.

Thanks for your help!

Function onkeyup and overlay

When I use the onkeyup function, the table that appears to me does not overlay the video. How can I overlay the table.

I post both the html code and the javascript

function finName(ogg) {
  var name = $.trim($(ogg).val());

  if (name.length < 3) {
    return;
  }

  $.ajax({
    type: "GET",
    url: "core/main.php",
    data: "ID=getName&name=" + escape(name),
    dataType: "html",
    cache: false,
    success: function(msg) {
      $('#box').html(msg);

    },
    error: function(x, t, m) {

    }
  });
}
<div class="col-sm-5">
  <div class="input-group input-group-sm">
    <span class="input-group-addon alert-secondary chgsize1" id="basic-addon3 overlay">Name</span>
    <input onkeyup="findName(this)" type="text" name="search" size="90" class="form-control" placeholder="Search">

    <div id='box'>
      <!-- box  -->
    </div>
  </div>
</div>

Laravel Carbon DiffForHumans Option (Years, Months, Days)

I have read through the documentation of DiffForHumans and it’s very straightforward, but is there a way to customize the date to print out:

  • 13 Years, 1 Month, 10 Days
  • 01 Year, 11 Months, 01 Day

where it will respect the Year/Years, Month/Months, Day/Days?

  • Approach 1:

    $date = Carbon::parse('2010-08-29');
    $formattedDate = $date->diffForHumans(['parts' => 3, 'join' => ', '];
    

    Will print out 13 years, 1 month, 4 weeks ago

  • Approach 2:

    $date = Carbon::parse('2010-08-29');
    $formattedDate = $date->diff(now())->format('%y Year, %m Months and %d Days')
    

    Will print out 13 Year, 1 Months and 28 Days

  • Approach 3 (Backup option):

    $date = Carbon::parse('2010-08-29');
    $formattedDate = $date->diff(now())->format('%y Year(s), %m Month(s) and %d Day(s)')
    

    Will print out 13 Year(s), 1 Month(s) and 28 Day(s)

Is there a vanilla PHP class that could accomplish something similar?

Oauth2 works in development, but not in production

I use the PHPLeague Oauth2 client library. It authenticates against a WP Oauth Server.
When logging in in my dev environment everything works as intended.
When logging in in my prod environment I get the following error:
“Invalid response received from Authorization Server. Expected JSON.”

How can that be? What am I missing here? I have double checked my certs, my keys and just about everything else I can think of.

CI 3 Routes Not Working in Ubuntu 20 using Nginx

I know this question have been asked for too many times.
I’ve been looking for answers for days and couldn’t find the correct answers after trying hundreeds of solutions over the internet.
Here is the condition that i’m facing :

I’m using an Ubuntu server version 20 with Nginx, PHP 7.4 and MariaDB for this application coded in CodeIgniter version 3.
After deployment, everything seems working, the database connected, the nginx conf is working, the default route of the CI is working.
After opening the page, it will redirect user to the login page and after trying the login, it’s working and redirect the user to the dashboard page.
But, everything is working except for 2 routes. The table page and the map page.

Here is the code and configuration looks like :

etc/nginx/sites-available/default

server {
    listen 80;
    listen [::]:80;

    #app-name is the application name
    root /var/www/app-name;

    index index.php index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        #I have changed this a lot and this one is the one that's worked.
        try_files $uri $uri/ /idnex.php;
    }

    location ~ .php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }
}

.htaccess
(I have tried changing this one a lot and nothing seems to be working. Some says that nginx doesn’t listen to .htaccess)

DirectoryIndex index.php
RewriteEngine on
 
RewriteCond $1 !^(index.php|(.*).swf|forums|images|css|downloads|jquery|js|robots.txt|favicon.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]

CI3 routes.php

$route['default_controller']                                = "login";
$route['404_override']                                      = '';
$route['translate_uri_dashes']                              = FALSE; 

/*********** LOGIN ROUTES ***********/
$route['gLogin']                                            = 'login/gLogin';
$route['gLogout']                                           = 'masyarakat/logout';
$route['loginMe']                                           = 'login/loginMe';
$route['logout']                                            = 'masyarakat/logout';

/*********** DASHBOARD ROUTES ***********/
$route['dasbor/utama']                                      = "dasbor/utama";

/*********** DATA ROUTES ***********/
# This is the 2 routes that doesn't work. Everything else is working. I don't know how.
$route['tabelData']                                         = "datautama/tabelData";
$route['petaData']                                          = "datautama/petaData";

/*********** REPORT ROUTES ***********/
$route['daftarLaporan']                                     = "laporan/daftarLaporan";

/*********** ADMIN ROUTES ***********/
$route['admin/masyarakat']                                  = "admin/masyarakat";
$route['admin/kategoriLaporan']                             = "admin/kategoriLaporan";

CI3 Controller That is working :
Laporan.php

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');

require APPPATH . '/libraries/PerpanjanganTangan.php';

class Laporan extends PerpanjanganTangan
{

    public function __construct()
    {
        parent::__construct();
        $this->load->model('laporan_model');
        $this->isLoggedIn();   
    }

    function daftarLaporan()
    {

        if($this->isKaling() == TRUE)
        {
            $this->loadThis();
        }
        else
        {

            $this->global['pageHeader'] = 'Siap PERKIM : Daftar Laporan';
            $this->global['pageTitle']  = 'Daftar Laporan';
            $this->loadViews("daftarlaporan/semua", $this->global, NULL , NULL);

        }

    }

}

CI3 Controllers That Doesn’t Work :
DataUtama.php

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');

require APPPATH . '/libraries/PerpanjanganTangan.php';

class Datautama extends PerpanjanganTangan
{

    public function __construct()
    {
        parent::__construct();
        $this->load->model('datautama_model');
        $this->isLoggedIn();   
    }

    function tabelData()
    {

        if($this->isKaling() == TRUE)
        {
            $this->loadThis();
        }
        else
        {

            $this->global['pageHeader'] = 'Siap PERKIM : Tabel Data';
            $this->global['pageTitle']  = 'Tabel Data';
            $this->loadViews("data_utama/tabeldata", $this->global, NULL , NULL);

        }

    }

    function petaData()
    {

        if($this->isKaling() == TRUE)
        {
            $this->loadThis();
        }
        else
        {

            $this->global['pageHeader'] = 'Siap PERKIM : Peta Data';
            $this->global['pageTitle']  = 'Peta Data';
            $this->loadViews("data_utama/petadata", $this->global, NULL, NULL);

        }

    }

}

Please help.
What did i do wrong?

I have tried renaming the Controllers.
Every controller name is capital on the 1st letter.
Every controller class name is capital on the 1st letter.
I have tried changing the controllers a lot.
I have tried changing the routes.
I have tried changing the nginx configuration.
I have tried changing the .htaccess file.

But nothing seems to work on me.

Laravel10 Form field that brings up another datable to search and select item, then that item is added to the field

i have 3 tables ie… Owners, Vehicles and Drivers.
On the add drivers view, how do i make a field when click will open up another window or hidden datatable to select the “Owner of vehicle” and other field to selected “vehicle” with search. Both these cannot be dropdown options as the owners and vehicle tables will be large.

ADD DRIVER VIEW

`@extends(‘admin.admin_dashboard’)
@section(‘admin’)

    <div class="row profile-body">
        <!-- left wrapper start -->

        <!-- left wrapper end -->
        <!-- middle wrapper start -->
        <div class="col-md-8 col-xl-8 middle-wrapper">
            <div class="row">
                <div class="card">
                    <div class="card-body">

                        <h6 class="card-title">Add A Driver</h6>

                        <form method="POST" action="{{ route('store.operator') }}" class="forms-sample">
                            @csrf

                            <div class="mb-3">
                                <label for="exampleInputUsername1" class="form-label">Name</label>
                                <input type="text" name="name"
                                    class="form-control @error('name') is-invalid @enderror">
                                @error('name')
                                    <span class="text-danger">{{ $message }}</span>
                                @enderror

                            </div>


                            <div class="mb-3">
                                <label for="exampleInputUsername1" class="form-label">ID Number</label>
                                <input type="text" name="id_num"
                                    class="form-control @error('id_num') is-invalid @enderror">
                                @error('id_num')
                                    <span class="text-danger">{{ $message }}</span>
                                @enderror

                            </div>

                            <div class="mb-3">
                                <label for="exampleInputUsername1" class="form-label">Address</label>
                                <input type="text" name="address"
                                    class="form-control @error('address') is-invalid @enderror">
                                @error('address')
                                    <span class="text-danger">{{ $message }}</span>
                                @enderror

                            </div>

                            <div class="mb-3">
                                <label for="exampleInputUsername1" class="form-label">Phone</label>
                                <input type="text" name="phone"
                                    class="form-control @error('phone') is-invalid @enderror">
                                @error('phone')
                                    <span class="text-danger">{{ $message }}</span>
                                @enderror

                            </div>



                            <div class="mb-3">
                                <label for="exampleInputUsername1" class="form-label">Owner</label>
                                <input type="text" name="onwer_id"
                                    class="form-control @error('onwer_id') is-invalid @enderror">
                                @error('onwer_id')
                                    <span class="text-danger">{{ $message }}</span>
                                @enderror

                            </div>

                            <div class="mb-3">
                                <label for="exampleInputUsername1" class="form-label">Vehicle</label>
                                <input type="text" name="vehicle_id"
                                    class="form-control @error('vehicle_id') is-invalid @enderror">
                                @error('vehicle_id')
                                    <span class="text-danger">{{ $message }}</span>
                                @enderror

                            </div>

                            <div class="mb-3">
                                <label for="exampleFormControlSelect1" class="form-label">Blacklisted</label>
                                <select name="black_listed" class="form-select" id="exampleFormControlSelect1">

                                    <option selected="" disabled="">Select Option</option>
                                    <option>Yes</option>
                                    <option>No</option>


                                </select>
                            </div>

                            <div class="mb-3">
                                <label for="exampleFormControlTextarea1" class="form-label">Notes About Driver</label>
                                <textarea class="form-control" name="notes" id="exampleFormControlTextarea1" rows="5"></textarea>
                            </div>



                            <button type="submit" class="btn btn-primary me-2">Save Changes</button>

                        </form>

                    </div>
                </div>

            </div>
        </div>
        <!-- middle wrapper end -->

    </div>

</div>

@endsection
`

Not sure what is the right way to do this

Checking for duplicate values in MongoDB database with php

I need to do a task where I add “people” to a mongoDB database. One of their values is an ID value, I need to ensure that there is never a duplicate ID value in the DB, How can I go about checking the DB if the ID value is the same as what I am trying to insert before inserting a new “person” into the collection.

PHP – Limit and offset foreach loops

I am going to add limit and offset to this loop:

<?php
$images = get_field('am_c_gallery');
if( $images ): ?>
        <?php foreach( $images as $image ): ?>
          <div class="item-big"></div>
        <?php endforeach; ?>
<?php endif; ?>

offset 1 and 5 image like this:

   if first:
   <div class="item-big"></div>
        
   if 2-5:
   <div class="item-small"></div>
   <div class="item-small"></div>
   <div class="item-small"></div>
   <div class="item-small"></div>
    
   if 5 - unlimited:
   <div class="item-hide"></div>

mySQL trigger cause laravel application to hang

I have a trigger which updates another table(budget) after an insert to ledger table.

I can see that the execution is successful as the data is reflected on the tables but my page
is just a blank screen.

I am using laravel and mysql.

I was thinking if I can improve my trigger as I believe it is wheats causing the issue.

Here is the snippet of my code.

enter image description here

invalid datetime format 1366 incorrect integer value symfony 1.4

so if i check that checkbox admin will be nonactive, but i need t use active admin hostenter image description here

I want to debug the issue in here symfony 1.4 here is form

<?php

/**
 * User form.
 *
 * @package    now
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class UserForm extends BaseUserForm {

    public function configure() {
        $this->disableCSRFProtection();

        unset($this['created_by'], $this['created_at'], $this['updated_at'], $this['updated_by'], $this['phone_number'], $this['position'], $this['group_id']);
        $userId=$this->getObject()->getId();
        $this->setWidgets(array(
            'id' => new sfWidgetFormInputHidden(),
            'username' => new sfWidgetFormInputText(),
            'password' => new sfWidgetFormInputPassword(),
            'again_password' => new sfWidgetFormInputPassword(),
            'firstname' => new sfWidgetFormInputText(),
            'lastname' => new sfWidgetFormInputText(),
            'mobile' => new sfWidgetFormInputText(),
            'email' => new sfWidgetFormInputText(),
            'user_groups_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'UserGroup', 'expanded' => true)),
            'status'           => new sfWidgetFormInputCheckbox(array(), array('value' => 1)),

//            'status'           => new sfWidgetFormInputCheckbox(array(), array('value' => 1)),
//            $this->widgetSchema->setDefaults(array(
//                'status' => 1,  ))
        ));


        $required_array = array('required' => true);

        $this->setValidators(array(
            'id' => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
            'username' => new sfValidatorString($required_array, array('required' => 'Нэвтрэх нэрийг заавал оруулна уу')),
            'password' => new sfValidatorString(array('max_length' => 100, 'required' => false)),
            'again_password' => new sfValidatorString(array('required' => false)),
            'firstname' => new sfValidatorString(array('max_length' => 50, 'required' => true)),
            'lastname' => new sfValidatorString(array('max_length' => 50)),
            'mobile' => new sfValidatorString(array('max_length' => 255)),
            'email' => new sfValidatorEmail(array(), array('invalid' => 'Та имэйл хаягийг зөв оруулна уу', 'required' => 'Та имэйлийг заавал оруулна уу')),
            'user_groups_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'UserGroup', 'required' => false)),
            'status'           => new sfValidatorBoolean(array('required' => false)),
        ));
//        11f3d53bd59be0c5a1ea7e354516528c
//        5ef0c862efa8ced872fa54c4e9453276
        $this->widgetSchema->setNameFormat('user[%s]');

        $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(
            new sfValidatorDoctrineUnique(array('model' => 'User', 'column' => array('username')), array('invalid' => 'Нэвтрэх нэртэй хэрэглэгч бүртгэгдсэн байна')),
            new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'again_password', array(), array('invalid' => 'Нууц үгүүд ижилхэн байх ёстой!'))
        )));

//        $this->validatorSchema->setPostValidator(
//                new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'again_password', array(), array('invalid' => 'Нууц үгүүд ижилхэн байх ёстой!'))
//        );
        $this->widgetSchema['username']->setAttributes(array('class' => 'form-control'));
        $this->widgetSchema['password']->setAttributes(array('class' => 'form-control'));
        $this->widgetSchema['again_password']->setAttributes(array('class' => 'form-control'));
        $this->widgetSchema['firstname']->setAttributes(array('class' => 'form-control'));
//        $this->widgetSchema['status']->setAttributes(array('class' => 'form-control'));
        $this->widgetSchema['lastname']->setAttributes(array('class' => 'form-control'));
        $this->widgetSchema['email']->setAttributes(array('class' => 'form-control'));
        $this->widgetSchema['mobile']->setAttributes(array('class' => 'form-control'));

        $this->widgetSchema->setLabels(
            array(
                'username' => 'Нэвтрэх нэр:',
                'password' => 'Нууц үг:',
                'again_password' => 'Нууц үг давтах:',
                'firstname' => 'Өөрийн нэр:',
                'lastname' => 'Эцгийн нэр:',
                'mobile' => 'утас:',
                'email' => 'Имэйл:',
                'status' => 'Идэвхгүй болгох эсэх:',
                'user_groups_list' => 'Хандах эрх:',
            ));
    }

}

i want to know about how to fix the checkbox when i using local server i need to change my admin level and choose active checkbox but it doesn’t work eventhough error was called in the status section will need datetime.

Laravel 5.6 booting is extremely slow when the DB is external to the server

I have a Laravel 5.6 application with legacy code and I am willing to fix and upgrade, but first I wanted to separate the web application from the DB.

With the debugbar I have seen that when the APP connects to the local mysql the booting takes 100ms. When it connects to the remote database, the booting takes 2seconds.

debugbar in with local bd and remote bd

I have debugged how long it takes to make a query with a select (like DB::table('users')->limit(100)->get()) and the query executes fast both locally and remotely, so I can rule out a latency issue or a database problem.

In addition, I have created a url with a simple controller that only returns a static html to make the tests and that there are no strange things that can make the legacy code.

I also have to say that the tests have been done with different servers, with the same versions and the booting problem always occurs. In production I use mariaDB 10.5 but in development I have a mysql 8, I have done the same tests with both versions and always the same thing happens, local fast, remote slow.

Could someone give me some help?

Unable to reverse value for property path “meeting”: The choice “340” does not exist or is not unique

My question is in title. I have had read the same case but doesn’t help me.
I want to display a sion click field on a radio button. If a match is made, then there is a fill. If there is no match, then another fill is made in the same field. The latter case is defined in a function, the first case is defined in the controller

My FormType

 ->add('meeting', EntityType::class,[

                        'class' => Meeting::class,
                        'choice_label' => function ($meeting) {
                            return 'RDV-'.$meeting->getId() . ' : ' . $meeting->getCompanyName();
                        },

                        'query_builder' => function(MeetingRepository $repository) use ($data) {

                           $date = new DateTimeImmutable( 'now - 420 days');

                                 return $repository->createQueryBuilder('m')
                                     ->where("m.siren = :siren")
                                     ->andWhere('m.commercial = :commercial')
                                     ->andWhere('m.status = 9')
                                     ->andWhere('m.date > :date')
                                     ->setParameters(['siren' => $data['siren'], 'commercial' => $data['commercial'], 'date' => $date]);

                        },
                        'expanded' => false,
                        'multiple' => false,
                        'label' => 'RDV *',
                        'label_attr' => [
                            'class' => 'form-label',
                        ],

                        'attr' => [
                            'class' => 'js-select form-select',
                            'autocomplete' => "off",
                            'data-hs-tom-select-options' => "{ "placeholder": "Sélectionnez un rendez-vous...", "dropup": true}"
                        ],
                        'row_attr' => [
                            'class' => 'mb-3 col-2 tom-select-custom',
                            'data-hs-validation-validate-class'
                        ],
                    ]);

My controller :

 let siren = $('#order_odyc_siren').val();
        let commercial = $('#order_odyc_commercial').val();
        let rdvTmkOui = $('#order_odyc_rdvTmk_0');

        let data = $(event.currentTarget).prop('id') === 'order_odyc_rdvTmk_0'
            ? {
                "order_odyc[rdvTmk]": 1,
                "order_odyc[siren]": siren,
                "order_odyc[commercial]": commercial,
                "order_odyc[match]": false
            }
            : ''

        const form = $(event.currentTarget).closest('form');
        $(event.currentTarget).parent().after('<div id="load-rdv-tmk" class="d-inline"><div class="spinner-border spinner-border-sm ms-2 text-primary" role="status" aria-hidden="true"></div>')

        $.ajax({
            "url": form.attr('action'),
            "method": 'POST',
            "headers": {
                "Content-Type": "application/x-www-form-urlencoded;charset:UTF-8"
            },
            "data": data,
            "complete": (function (html) {

                if($('#order_odyc_tmk').length === 0){
                    $('#order_odyc_rdvTmk_0').parent().parent().after($(html.responseText).find('#order_odyc_tmk').parent())
                    $('#order_odyc_tmk').parent().after($(html.responseText).find('#order_odyc_meeting').parent())

                    console.log('Siren : ' + siren + ' et commercial : ' + commercial)
                    SireneV3.getRdvBySirenAndCommercial(siren, commercial, rdvTmkOui);


                }else{
                    $('#order_odyc_tmk').parent().replaceWith($(html.responseText).find('#order_odyc_tmk').parent())
                    $('#order_odyc_meeting').parent().replaceWith($(html.responseText).find('#order_odyc_meeting').parent())

                }

                $('#load-rdv-tmk').remove()

                HSCore.components.HSTomSelect.init('#order_odyc_tmk')
                HSCore.components.HSTomSelect.init('#order_odyc_meeting')

            })
        });

In function if field in controller will not print :

function valid(){
                       
                        let choice = $('input[name=formRadio]:checked')
                        
                        //window.alert('RDV-' + choice[0].dataset.id + ' : ' + choice[0].dataset.companyname + ' (' + choice[0].dataset.siren + ')')
                        
                        let div = $('<div class="mb-3 col-2 tom-select-custom" data-hs-validation-validate-class><label class="form-label" for="order_odyc_meeting">RDV *</label></div>')

                        let select = $('<select class="js-select form-select" id="order_odyc_meeting" name="order_odyc[meeting]" data-hs-tom-select_option="{ \\"placeholder\\": \\"Sélectionnez un rendez-vous...\\", \\"dropup\\": true}"></select>');
                        let option = $('<option value="'+choice[0].dataset.id+'" selected >RDV-' + choice[0].dataset.id + ' : ' + choice[0].dataset.companyname+'</option>')

                        $(select).append(option)
                        $(div).append(select)

                        //$('#order_odyc_rdvTmk_0').trigger('click');
                        
                        setTimeout(()=>{
                            $('#order_odyc_meeting').parent().replaceWith(div)
                            HSCore.components.HSTomSelect.init('#order_odyc_meeting')
                        },250)
                        
                        $('#order_odyc_rdvTmk_0').data('meeting', choice[0].dataset.siren)
           
                        $('#btn_modal_lastMeetings').trigger('click')
                        
                    }
                    
                </script>`

                break;