mercredi 27 février 2019

Get data from database with condition and show it in a view

This is the data that I have in database

This is what I want to make in the view.blade.php

What I want to do is I want to get the data from the database, if the data inside the column is 1, I want to get the column name as you can see in image 2, but there could be more than 1 column name because the column with data can be column A,B,C... etc.. and I want to show the student name and the subject (a,b,c... etc) if the data in it is '1' in the view. I stuck on how to get all those subject A,B,C.. this is the code that I have written, but it is incomplete because I don't know what to add on it to make it as what I have mentioned above. Hopefully, someone can help me. Thanks in advance

if($row->'A'=='1'){i dont know what should i put here so that i cant get the column name 'A' and print it in view.blade.php}



via Chebli Mohamed

mardi 26 février 2019

Why does laravel \Storage::store method cause this error?

In my local environment why I do following, it works.

    if( $request->file ){

        $path = $request->file('file')->store('public/chat/files');

        $mime_type = $request->file('file')->getMimeType(); 


        if( strstr( $mime_type, 'video' ) ){
            $data['message_type'] = 'video';
        }else if( strstr( $mime_type, 'image' ) ){
            $data['message_type'] = 'image';
        }else if( strstr( $mime_type, 'audio' ) ){
            $data['message_type'] = 'audio';
        }

But on apache running on Digital Ocean droplet when I run the same code I get the following error.

[2019-02-26 11:45:48] local.ERROR: The file "" does not exist {"userId":3,"email":"user@user.com","exception":"[object] (Symfony\\Component\\HttpFoundation\\File\\Exception\\FileNotFoundException(code: 0): 
The file \"\" does not exist a$
[stacktrace]
#0 /var/www/html/plugin_love_api/vendor/symfony/http-foundation/File/File.php(79): Symfony\\Component\\HttpFoundation\\File\\MimeType\\MimeTypeGuesser->guess('')
#1 /var/www/html/plugin_love_api/vendor/symfony/http-foundation/File/File.php(58): Symfony\\Component\\HttpFoundation\\File\\File->getMimeType()
#2 /var/www/html/plugin_love_api/vendor/laravel/framework/src/Illuminate/Http/FileHelpers.php(60): Symfony\\Component\\HttpFoundation\\File\\File->guessExtension()
#3 /var/www/html/plugin_love_api/vendor/laravel/framework/src/Illuminate/Http/UploadedFile.php(35): Illuminate\\Http\\UploadedFile->hashName()
#4 /var/www/html/plugin_love_api/app/Http/Controllers/ChatController.php(71): Illuminate\\Http\\UploadedFile->store('public/chat/fil...')
#5 [internal function]: App\\Http\\Controllers\\ChatController->sendMessage(Object(Illuminate\\Http\\Request))
#6 /var/www/html/plugin_love_api/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array(Array, Array)
#7 /var/www/html/plugin_love_api/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction('sendMessage', Array)
#8 /var/www/html/plugin_love_api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(219): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(App\\Http\\Controllers\\ChatController), 'se$
#9 /var/www/html/plugin_love_api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(176): Illuminate\\Routing\\Route->runController()
#10

PHP version is : PHP 7.2.15-0ubuntu0.18.04.1 (cli) (built: Feb 8 2019 14:54:22) ( NTS )

Also I have set 777 permissions on storage folder and all it's descendants.

UPDATE:

This seems to be the issue with the size of file that I am uploading.

it does not work with more than 2MB but works with ~6kb file.



via Chebli Mohamed

lundi 25 février 2019

Google calendar api not showing the organizer name and sending notification emails - laravel

I'm using a laravel package for the google calendar api integration. In that i am able to create events with just attendees only. I've tried creating organizer but its not coming up. The following is the code i've used. The organizer name here defaults to the email from which the api credentials are created also the email notifications are not coming. The package I'm using is "spatie/laravel-google-calendar". Can anyone tell me what i'm doing wrong here.

Event::create([
               'name' => 'Latest Event dsfdsfsdfsdf',
               'location' => '800 Howard St., San Francisco, CA 94103',
               'description' => 'A chance to hear more about Google\'s developer products.',           
               'startDateTime' => Carbon\Carbon::now(),
               'endDateTime' => Carbon\Carbon::now()->addHour(),
               'sendNotifications' => true,
               'sendUpdates' => 'all',
               'organizer' => array('email' => 'test@gmail.com','displayName' => 'Darshan')
               'attendees' => array(
                array('email' => 'test@gmail.com','displayName' => 'Darshan', 'organizer' => true),
                array('email' => 'darshan@test.com','displayName' => 'Ryan')
              )
            ]); 



via Chebli Mohamed

vendredi 22 février 2019

Is There Any Way to Bypass Model::created() Event on Laravel?

UserModel.php

In my user model there is created event which is called every time when new user is created using User::Save()

 protected static function boot()
    {
        parent::boot();
    self::created(function (User $user) {
        // Some operation goes here
    });
}

Now what i want is for some reason i don't want to call that created when i create new user record.

Is there any way to bypass createdEvent ??



via Chebli Mohamed

mercredi 20 février 2019

Laravel PhpUnit: How to trigger events on DOM elements

I am using Laravel 5.1 and PHPUNIT 4.8 and PHP 7.0. I am trying to test my login functionality. My login form is opened after clicking a div. As far as I have read documentation and tried different things, I am only able to click if there is a button or there is a link. Please guide

class ExampleTest extends TestCase
{
/**
 * A basic functional test example.
 *
 * @return void
 */

    public function testUrl(){
        $this->visit('/')->click("#login_popup");
    }

    public function checkAssert(){
        $this->assertTrue(true);
    }
}

Here I have a div with id #login_popup. When I run test it gives following error

InvalidArgumentException: Could not find a link with a body, name, or ID attribute of [#login_popup].



via Chebli Mohamed

mardi 12 février 2019

Laravel eloquent subquery alias

How to do this in Laravel 5.1?

SELECT *
FROM
(
    SELECT subscriber_id, COUNT(*) as count
        FROM mailing_group_subscriber
        WHERE mailing_group_id IN ('99', '15498855416270870')
    GROUP BY subscriber_id
) table_count
WHERE count = 2;

Thanks!



via Chebli Mohamed

dimanche 10 février 2019

The gathering Database data's are how to display text box while clicking dropdown box using laravel

screenshot

In the image contains the html document, it combines with the controller and route, My question is how to display data's using select box clicking it will display into another textbox respective fetching data



via Chebli Mohamed

vendredi 8 février 2019

production.ERROR: Call to undefined function Illuminate

I'm very new to Laravel. Initially, my project was working perfectly, few weeks now uploaded images refused to display, all uploaded images are broken. When I checked my Laravel Log here is what I get`

production.ERROR: Call to undefined function Illuminate\Filesystem\finfo_file() {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Call to undefined function Illuminate\Filesystem\finfo_file() at /home/crescen1/crescentlaravel/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:299)

Here is the code I have in my filesystem.php: line 299`

/**
 * Get the mime-type of a given file.
 *
 * @param  string  $path
 * @return string|false
 */
public function mimeType($path)
{
    return finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
}

/**
 * Get the file size of a given file.
 *
 * @param  string  $path
 * @return int
 */
public function size($path)
{
    return filesize($path);
}



via Chebli Mohamed

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