How to check for all software updates in your windows system

Using winget from your windows terminal you can check and even do upgrades to all your applications, not only Microsoft related applications.

Windows Package Manager winget command-line tool is available on Windows 11 and modern versions of Windows 10 as a part of the App Installer.

CommandDescription
infoDisplays metadata about the system (version numbers, architecture, log location, etc). Helpful for troubleshooting.
installInstalls the specified application.
showDisplays details for the specified application.
sourceAdds, removes, and updates the Windows Package Manager repositories accessed by the winget tool.
searchSearches for an application.
listDisplay installed packages.
upgradeUpgrades the given package.
uninstallUninstalls the given package.
hashGenerates the SHA256 hash for the installer.
validateValidates a manifest file for submission to the Windows Package Manager repository.
settingsOpen settings.
featuresShows the status of experimental features.
exportExports a list of the installed packages.
importInstalls all the packages in a file.

“winget” is a command-line package manager for Windows 10 and Windows 11 operating systems. It allows users to search, install, update, and uninstall software packages from the command line or PowerShell. Winget provides a streamlined way to manage software installations and updates without requiring a separate graphical user interface.

The primary user of “winget” is developers, system administrators, and power users who prefer command-line interfaces for managing software. Here are some use cases for “winget”:

  • Software Installation
  • Automated Scripts and Deployment
  • Package Management
  • Integration with Development Workflows

For more information, you can go to this url:

https://learn.microsoft.com/en-us/windows/package-manager/winget/

Facing a hard time installing Gulp?

If you are trying to install Gulp and you always get errors related to node-sass, here is a small tip that could fix it for you

Simply uninstall node-sass and install dart-sass

npm uninstall gulp-sass
npm install gulp-dart-sass

Then, update your Gulpfile.js to use gulp-dart-sass instead of gulp-sass for compiling Sass.

By following these steps, you should be able to resolve the compatibility issue with Node Sass and successfully run gulp watch without encountering the “Node Sass does not yet support your current environment” error.

How to abort with custom message in Laravel

If you want to abort with a custom message, you will find that in some code like this,

abort(400, 'custom error message');

the above code will show you the standard 400 error without any custom messages. You need to write the code like this

abort(
    response()->json(['message' => "My Custom error message"], 400)
  );

How to solve “Attempt to read property of Null”

Sometimes in Laravel, when you try to show a property of an object, for example :

{{ $user->name }}

you get an error like this :

Attempt to read property on null

which simply means that the object itself “user” is null and you can’t get a name property of Null. To solve this, you need to make sure that the user object is there first and then get the name but that will be a lot of coding and if statement, while there is a one-character solution to this, it is called a Nullsafe Operator and it is in PHP 8
the code will look like this

{{ $user?->name }}

you can use the same method in a chain of objects or even methods

$country = $session?->user?->getAddress()?->country;

There are other options that you can check in this article

Nothing to migrate in Laravel

If you are trying to migrate a single class you will do something like this

php artisan migrate --path = path_to_migration_file

if you get something like :

Nothing to migrate

and you are sure the file is there, then you can try to write the command like this

php artisan migrate --path="database/migrations/2022_11_04_1235_create_table.php"

Log Laravel

You can easily log your data in Larave, all you have to do is to use Log, and then log whatever you want, here is an example

<?php
 
namespace App\Http\Controllers;
 
use Log;
use App\User;
use App\Http\Controllers\Controller;
 
class UserController extends Controller
{
    /**
     * Show the profile for the given user.
     *
     * @param  int  $id
     * @return Response
     */
    public function showProfile($id)
    {
        Log::info('User ID: '.$id);
 
        return view('user.profile', ['user' => User::findOrFail($id)]);
    }
}

You can also use an array of contextual data

Log::info('User failed to login.', ['id' => $user->id]);

Laravel provides 8 levels of logging

Log::emergency($error);
Log::alert($error);
Log::critical($error);
Log::error($error);
Log::warning($error);
Log::notice($error);
Log::info($error);
Log::debug($error);

You can view the log file at: storage/laravel.log but you may find a huge file with thousands of line as this is the main file where all the logs are saved.

If you want to create your own log file, you will need to add a new channel in the config/logging.php

'channels' => [
        'myLog' => [
                    'driver' => 'single',
                    'path' => storage_path('logs/myLog.log'),
                    'level' => 'info',
                ],

where myLog.log is the file name you want to save your logs in

To write to your custom log file, you have to specify the channel you just created

Log::channel('myLog')->info('This is testing for my log file.');

ps. Don’t forget to empty the config cache for the updates to be active

from your terminal, you write: php artisan cache:clear

Finally, when you open myLog.log file, you will see something like this:

[2022-08-25 09:13:20] local.INFO: This is testing for my log file.

API request not working locally but works fine on the server

If you are trying to get some data from an external API and it is working on the Postman or on the live server but is not working locally, and you may also face an error like:

SSL certificate problem: unable to get local issuer certificate

here is a quick solution for this issue:

Change it to:

curl.cainfo = “C:\wamp64\bin\php\php8.1.0\cacert.pem

  • Make sure you remove the semicolon at the beginning of the line and double-check the path of the php folder
  • Save changes to php.ini,
  • Restart WampServer (or any other local server you have)

How to use withSum() with where condition

You can use withSum in query with where condition, here is an example:

If you want to list all Projects with the sum of all invoices that were issued this year:

$projects = Project::select('id', 'name', 'created_at')
            ->withSum(
                 ['invoices as prev_invoices' => function($query) {
                     $query->whereYear('invoices.issue_date', date('Y'));
                }], 'amount' 
             )
            ->get();

How to set a function in a model as an attribute

If you have a model with a function that you want to use it as an attribute, all you have to do is to use protected $appends in the Model class

For example, you have a Project class with a function that gets the sum of all invoices for that project

class Project extends Model
{
protected $appends = ['prev_invoices'];
....
public function getPrevInvoicesAttribute()       
    {
        $sum = Invoice::where('project_id', $this->id)
            
            ->sum('amount');
        return $sum;
    } 

Note that the function name must be formatted like that: “get” at the beginning, “Attribute” at the end, and the name to be CamelCase.

Create your own custom Excel function

If you want to make your own function as the built-in ones SUM() for example you go to:
Developer tab and click on the Visual Basic icon

in the new window of Microsoft Visual Basic for Applications, you click on Insert > Module

Now you can write your code, for example, if you want to write a function that extracts the url of a link in a cell, the code could be like this

Function GetURL(cell As Range)
    GetURL = cell.Hyperlinks(1).Address
End Function

Now, you can use this function “GetURL” as any ordinary function in Excel.

Note that if you want to save the file, you have to save it as Excel Macro-Enabled Workbook (*.xlsm)

Visit this page for more information:

https://support.microsoft.com/en-us/office/create-custom-functions-in-excel-2f06c10b-3622-40d6-a1b2-b6748ae8231f