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