samedi 25 avril 2020

Slow photo loading in Laravel

I have Laravel code below in my project on local machine and running it on development mode. Photos are stored in public folder. In current example I have 17 photos in mobile_photos folder, the weight of all of them is 572kB. The problem is slow loading of mentioned images even they are not heavy, exact time you can find on photo below. I expected to load these ptohos in ms but as you can see loading time for one photo is more then more then 1s. Any idea how to fix this problem?

  <link rel="stylesheet" href="/css/justifiedGallery.css" />       
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/jquery.justifiedGallery.js"></script>

    <div id="basicExample" class="justified-gallery">
    @foreach ($photo as $photo)                       

    <a href="">
    <img alt="caption for image" src=""/>
    </a>  
    @endforeach     
    </div>

  <script>
        $( document ).ready(function() {                
            $("#basicExample").justifiedGallery({
                rowHeight : 120,
                lastRow : 'justify',
                margins : 3                    
            });           
        });          
   </script>

enter image description here



via Chebli Mohamed

Getting Token expired for all json post requests

I am passing token in all the headers but it only works for login, after that for all requests it says "Token Expired"

Token Setup :

enter image description here

enter image description here

Output in Result tree :

enter image description here

Also when I look at my website, I can see 2 tokens :

<!-- CSRF Token -->
<meta name="csrf-token" content="AqrfjMcG1adWWDlx8YYkYqOCy3Mwp7fRynwut222">


<input type="hidden" name="_token" value="AqrfjMcG1adWWDlx8YYkYqOCy3Mwp7fRynwut222">

So I am passing _token for all request headers as above both has same content/value.

I am also not sure about x-socket-id, It came be default as I recorded script. is it ok to remove it?



via Chebli Mohamed

Send CSV file as Email attachement in Laravel

I am working on Laravel file attachment. I have successfully generated a .pdf file and sent as attachment in mail. Now I have to send CSV file as attachment in mail with Laravel. When I click the submit button it just download the file rather then to send an email.

Controller Code:

$data["email"] = $request->recipient_email;
$data["subject"] = 'Cashup Report for '. $venue->name;
$data["bodyMessage"] = $venue->name.' from '.$start.' to '.$end ;

 $excel = Excel::create(uniqid().'Cashups', function($excel) use($transactions,$start,$end,$venue) {
                        $excel->sheet('New sheet', function($sheet) use($transactions,$start,$end,$venue) {
      $sheet->loadView('excel.cashups', array('transactions' => $transactions, 'start'=> $start, 'end' => $end, 'venue' => $venue));
            });
 });

     //Feedback mail to client
 Mail::send('emails.cashups_report', $data, function($message) use ($data,$excel){
    $message->from(config('mail.from.address'));
    $message->to($data["email"]);
    $message->subject($data["subject"]);
    //Attach PDF doc
    $message->attachData($excel->output(),'cashups-report.xlsx');
});

I dont know where i am going wrong. I would appreciate if someOne Guide me through this. Thanks



via Chebli Mohamed

is there anyway to remove laravel telescope database without running another migration?

I have completely removed this package from my project but the databases still there, is another way to remove them too?



via Chebli Mohamed

vendredi 24 avril 2020

Property [categories] does not exist on this collection instance. (View: D:\xampp\htdocs\olshop\resources\views\backend\product\index.blade.php)

this is my Model

//relation from model products to model categorys
public function categorys()
{
    return $this->belongsTo('App\Category');
}

 //relation from model products to model categorys
public function categorys()
{
    return $this->belongsTo('App\Category');
}

this is my controller

 public function index()
{
    //controller buat manggil foreachnya
    $data['title'] ='Product';
    $data['page'] = 'Semua Product';
    $data['products'] = Product::all();
    return view('backend.product.index', $data);
}

**this is my **

                @foreach($products->categorys as $key => $value)
                <tr>
                    <!-- view bladenya  -->
                    <td></td>
                    <td></td>
                    <td></td>

I am trying to using $products->$categorys but its gone wrong



via Chebli Mohamed

If output of \Log::info depens on some options?

If output of

 \Log::info('text');

function is dependable on some options ?

in .env I have :

APP_DEBUG=false

and in config/app.php

'debug' => env('APP_DEBUG', false),

Also in config/logging.php I have options(seems default):

<?php

use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;

return [


    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['daily'],
        ],

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
        ],

        'daily' => [
            'driver' => 'daily',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
            'days' => 14,
        ],

        'slack' => [
            'driver' => 'slack',
            'url' => env('LOG_SLACK_WEBHOOK_URL'),
            'username' => 'Laravel Log',
            'emoji' => ':boom:',
            'level' => 'critical',
        ],

        'papertrail' => [
            'driver' => 'monolog',
            'level' => 'debug',
            'handler' => SyslogUdpHandler::class,
            'handler_with' => [
                'host' => env('PAPERTRAIL_URL'),
                'port' => env('PAPERTRAIL_PORT'),
            ],
        ],

        'stderr' => [
            'driver' => 'monolog',
            'handler' => StreamHandler::class,
            'formatter' => env('LOG_STDERR_FORMATTER'),
            'with' => [
                'stream' => 'php://stderr',
            ],
        ],

        'syslog' => [
            'driver' => 'syslog',
            'level' => 'debug',
        ],

        'errorlog' => [
            'driver' => 'errorlog',
            'level' => 'debug',
        ],
    ],

];

The quesion is that with my options on live server I expected

 \Log::info('text');

would not log lines, but it writes lines anyway.

I read here https://laravel.com/docs/5.7/logging do not see any dependencies.

? Laravel 5.7

Thanks!



via Chebli Mohamed

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or focused. I can seem to figure out a way to receive notification or perform am action while browser tab is open or focused, It works well when browser is at the background.I upgraded to firebase version 7.8.0 and below is the code am using

     <script>
    // Your web app's Firebase configuration
  var firebaseConfig = {
   apiKey: "xxxx",
   authDomain: "xxx",
   databaseURL: "xxxxx",
   projectId: "xxxx",
 storageBucket: "xxx",
messagingSenderId: "xxx",
appId: "xxx"
};
 // Initialize Firebase


  if (!("Notification" in window)) {
   console.error("Notification isn't enabled");
   } else if (Notification.permission === "granted") {
   console.log("Notification is enabled");
   } else if (Notification.permission !== "denied") {

  // Retrieve an instance of Firebase Messaging so that it can handle background
 // messages.
 firebase.initializeApp(firebaseConfig);
 const messaging = firebase.messaging();

messaging.onMessage((payload) => {
 console.log('Message received. ', payload);
 // ...
 });

  messaging
  .requestPermission()
  .then(function () {
    // MsgElem.innerHTML = "Notification permission granted." 
    //console.log("Notification permission granted.");

     // get the token in the form of promise
      return messaging.getToken()
     })
    .then(function(token) {
    // print the token on the HTML page
   //TokenElem.innerHTML = "token is : " + token
         $.ajax({
        type:'POST',
        url:'/SaveNotificationToken',
        data:{token : token, _token: "<?php echo csrf_token(); ?>",UserId:     },
             success:function(data){
            //alert(data+"You will receive notiications from clients that viewed your service ");
            $("#msg").html(data);
        }
     }); 

   })
  .catch(function (err) {
   //ErrElem.innerHTML = ErrElem.innerHTML + "; " + err
   console.log("Unable to get permission to notify.", err);
     });

 }


 </script>


via Chebli Mohamed