vendredi 8 février 2019

Laravel paginate is so slow

I have a problem with pagination it's so slow in big data more than 25K rows I try to get products saved by user in database by using:

$products = Item::has('product_save');

and I add same condition ...

$products = $products->where('active', 0);

I use this line to paginate :

$products = $products->paginate(20);

the all query take 0.06865 second. but is so slow more than 4.9 seconds! how i can make it very fast?



via Chebli Mohamed

active Attribute Casting making project environment fail

We have implemented the Attribute Casting in Laravel project for active field

protected $casts = [
    'active' => 'boolean',
];

and the field is in TINYINT (they are just synonyms) but the fact, since the time we have implemented that code in our Model it didn't thew any error and worked seamlessly but when we deployed on Production environment it threw 404 error so we changed the environment to local APP_ENV=local to check why its throwing error but when the environment switched to local it worked mysteriously so again we switched back to APP_ENV=production and thew 404 error so

Attribute Casting

is affecting the environment of the Application and can't find out why?



via Chebli Mohamed

mercredi 6 février 2019

After moving to another page Auth User NULL

I am all day with this issue and all ready checked all similar questions and there is no solutions that i need. Please help

I am using Laravel 5.7. The problem is, when login more than one user into CRM the sessions of users are switch, for example i login as my user and when i moving to another page my user is became to user of another user that is login to or became NULL in Auth::check function.

I can rewrite it to my auth rules not build in of laravel auth, but i want understand why it is happend.



via Chebli Mohamed

After moving to another page Auth User NULL

I all ready checked all similar questions and there is no solutions that i need.

I am using Laravel 5.7 with react. All view data is via ajax calls. The problem is, when i login in to CRM auth user exists, but when i moving to another page or some page in menu, auth user become NULL.

I all ready checked couple of answers and solution that i found was, to wrap all routs inside middleware web like this:

Route::group(['middleware' => 'web'], function() {
    Route::get('orders', 'HomeController@ordersList');
    Route::get('customers', 'HomeController@customersList');
    Route::get('agents', 'HomeController@agentsList');
    Route::get('agent-info', 'HomeController@agentInfo');
    Route::get('customer-info', 'HomeController@customerInfo');
    Route::get('order-details', 'OrdersController@showOrderInfo');
    Route::get('messages', 'MessageController@index');
});

This is not helping, the problem still the same. Thank you for help!



via Chebli Mohamed

samedi 2 février 2019

Is there any difference to create project in Plain PHP and Laravel

I want to build a project in web. but I’m confused to choose PHP or laravel for this. I know laravel is the framework of php etc. I have done one project with it. My Question is that is there any restriction in laravel than PHP? Or should I choose php or laravel for my project? Or how I determine that which one is best for this particular task? Or both are same?

Hope so this will make sense Thanks..



via Chebli Mohamed

How to show current weather report in laravel

I want apply new concept in my blog page(laravel).

I want to display a current weather information in my blog, first i want make a panel and want shows report of weather(in 3 section one for current or today date, 2nd for yesterday and 3rd is for day before yesterday).

Please help me in this so can implement, Please help me with this.



via Chebli Mohamed

vendredi 1 février 2019

QuickBooks desktop and Laravel- content type xml; charset=UTF-8 but expected text/xml

I'm trying to get one of the examples for consolibyte quickbooks-php working in Laravel (5.1). I'm having trouble getting it to work using a controller. The Web Connector's log shows client found response content type of 'xml; charset=UTF-8', but expected 'text/xml'.

The code I'm using is a slightly modified version of quickbooks-php demo. I've been unable to find an example of quickbooks-php desktop and laravel and am unsure of what I'm doing wrong.

Note- The require_once('../QuickBooks.php') is in app/config/app.php.

Controller

public function sync(RequestInterface $request, InvoiceSyncService $obj){
    $this->logger->info('############################### Start QB sync (laravel) ######################################');

    $user = 'user';
    $pass = 'password';

    // Map QuickBooks actions to handler functions
    $map = array(
        QUICKBOOKS_ADD_CUSTOMER => array( array( $obj, 'addCustomerRequest' ), array( $obj, 'addCustomerResponse' ) ),
    );

    // This is entirely optional, use it to trigger actions when an error is returned by QuickBooks
    $errmap = array(
        500 => array( $obj, 'handleError500' ),
    );

    // An array of callback hooks
    $hooks = array(
    );

    // Logging level
    $log_level = QUICKBOOKS_LOG_DEVELOP;        // Use this level until you're sure everything works!!!

    // What SOAP server you're using
    $soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN;        // A pure-PHP SOAP server (no PHP ext/soap extension required, also makes debugging easier)

    $soap_options = array(      // See http://www.php.net/soap
    );

    $handler_options = array(
    );      // See the comments in the QuickBooks/Server/Handlers.php file

    $driver_options = array(
    );

    $callback_options = array(
    );

    $dsn = 'mysqli://username:password@localhost/database';

    if (!QuickBooks_Utilities::initialized($dsn))
    {
        // Initialize creates the neccessary database schema for queueing up requests and logging
        QuickBooks_Utilities::initialize($dsn);

        // This creates a username and password which is used by the Web Connector to authenticate
        QuickBooks_Utilities::createUser($dsn, $user, $pass);

        $primary_key_of_your_customer = 5;

        $Queue = new QuickBooks_WebConnector_Queue($dsn);
        $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_customer);
    }

    // Set the DSN string because some of our callbacks will use it
    $obj->setDSN($dsn);

    // Create a new server and tell it to handle the requests
    $Server = new QuickBooks_WebConnector_Server($dsn, $map, $errmap, $hooks, $log_level, $soapserver, QUICKBOOKS_WSDL, $soap_options, $handler_options, $driver_options, $callback_options);
    $response = $Server->handle(true, true);

    return response()->view('invoicing/sync', ['response' => $response])->header('Content-type', 'xml');
}

InvoiceSyncService

protected $_dsn;

private $logger;

public function __construct(LoggerFactory $loggerFactory)
{
    $this->logger = $loggerFactory->createLogger('invoice-sync');
}


public function setDSN($dsn)
{
    $this->_dsn = $dsn;
}

public function addCustomerRequest($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
    $this->logger->info('A request occurred');

    $xml = '<?xml version="1.0" encoding="utf-8"?>
        <?qbxml version="2.0"?>
        <QBXML>
            <QBXMLMsgsRq onError="stopOnError">
                <CustomerAddRq>
                    <CustomerAdd>
                        <Name>ConsoliBYTE Solutions (' . mt_rand() . ')</Name>
                        <CompanyName>ConsoliBYTE Solutions</CompanyName>
                        <FirstName>Keith</FirstName>
                        <LastName>Palmer</LastName>
                        <BillAddress>
                            <Addr1>ConsoliBYTE Solutions</Addr1>
                            <Addr2>134 Stonemill Road</Addr2>
                            <City>Mansfield</City>
                            <State>CT</State>
                            <PostalCode>06268</PostalCode>
                            <Country>United States</Country>
                        </BillAddress>
                        <Phone>860-634-1602</Phone>
                        <AltPhone>860-429-0021</AltPhone>
                        <Fax>860-429-5183</Fax>
                        <Email>Keith@ConsoliBYTE.com</Email>
                        <Contact>Keith Palmer</Contact>
                    </CustomerAdd>
                </CustomerAddRq>
            </QBXMLMsgsRq>
        </QBXML>';

    return $xml;
}


public function addCustomerResponse($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{

    $this->logger->info('A response occured');
}

public function handleError500($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
{


    // return true;         // If you return TRUE, it will continue to process requests
    return false;           // If you return FALSE, it will stop processing requests
}

public function hookLoginSuccess($requestID, $user, $hook, &$err, $hook_data, $callback_config)
{
    if ($this->_dsn)
    {
        return true;
    }

    return false;
}



via Chebli Mohamed