Posts

Handling undefined variables in laravel

Handling undefined variables in your laravel code is critically important because it can help prevent errors and improve the stability of your program. Undefined or null variables occur when you try to access a variable that has not been declared or assigned a value. If you try to use an undefined variable in your code, it can cause errors that can break your program or produce incorrect results. By handling undefined variables correctly in your laravel project, you can ensure that your program runs smoothly and produces the desired results in production. There are several ways to handle undefined variables, such as checking for their existence before using them, setting default values,  using type coercion, or using try-catch blocks to handle errors.   the try catch is a great way to achieve error handling. its better to wrap  your controller route connected methods with try-catch block. but when a handling small variable the try catch block not always great. here some...

Where to get cheaper '.com' domains? checkout these registrars

Image
    .com is a wildly used domain extension. most companies prefer .com. Today, there are various domain name extensions. companies and individual can buy most matched domain extension to the business.but still, the .com extension is more used than all those domains.    source  : https://domainnamestat.com/statistics/tld/others    according to the Wikipedia, .com domain added in 1985 . current root level registrar is Verisign. ( https://en.wikipedia.org/wiki/.com )   There are several things to look for when we buy a domain. It is not only the price of the domain. Some of them are ,   The registrar of the domain is a trusted domain registrar. Renewal rates and terms.   Privacy protection.   Ability to easily transfer the domain.   support service quality.     Such things can be termed as some of those things.  if you are planning to buy a local domain, such as, .lk , .in, .us, .uk etc better to buy it from a...

Easy Config / Settings save and read class with caching PHP/Laravel

Image
    Photo by Emile Perron on Unsplash     Commonly most web applications require save configs and settings . there are many ways and methods to save and retrieve configs and settings. today i will share with you my method to save and retrieve settings data in laravel application.   Create migration and and Model php artisan make:model Settings -m in your migration file: add these fields: public function up () { Schema :: create ( 'settings' , function ( Blueprint $table ) { $table -> id (); $table -> string ( 'key' ); $table -> string ( 'value' ); $table -> unsignedBigInteger ( 'updated_user' )-> nullable (); $table -> timestamps (); }); } use 'updated_user' to track who changed value last time. you can also use 'text' or any suitable type to 'value' field I used string(varchar255) here. DB Model class <?php namespace A...

laravel with inertiajs - practice i just used for inertia projects to prevent repetitively executing inertia share method

Image
  image : https://unsplash.com/photos/TNO9gxHhhj0  Hello guys , i just thought to share my little experience in inertia js. inertia js(https://inertiajs.com/) getting quite popular with laravel now.  I had develop web project with inertia js. its easy and handle lot of Ajax tasks through the package. this helped lot  to create single page like application. but i faced issue is , there is a middlware calllded 'HandleInertiaRequests' and it have method callded 'share' . this share method calling every time we running a request through inertia service . I had created some sql query running tasks in this 'share' method, for update UI according to the updated data. things worked normally. Later I had created some ajax calling with separate routes which have their own tasks to update ui. but that not connected with inertiajs. but when I checking that ajax requests with "laravel debugbar" I saw there are lot of query executing for a little ajax call. how posb...

Laravel: Got "on behalf of" mess in email header? say No more!

Image
  If you use email service like mail gun, they default set 'sender' header part (not 'from' header) as "example.com@mailsubdomain.example.com". and  we mostly using only "from" function to set who sent the email (eg: contact@example.com) .. but some email client take this seriously . if original "example.com@mailsubdomain.example.com" is not equal to "from" that email client inform user to by showing like - "<info= example.com@mailsubdomain.example.com on behalf of contact@example.com"  this email client do for prevent misleading users. mostly this is harmless but users who don't know about this can be panic when they saw email like this . so how we fix this?? in Laravel there are two major functions in emails "from" and "sender" to set who sent the email...  "sender" is more accurate that "from" for some reasons Laravel mosly documented only "from" function. but ...

laravel-dompdf print with text watermark in every page

Image
  I stuck with a problem that is print watermark text to every page. after searching various areas of internet i found a working solution to my problem. i'm now shearing it. so it will useful to someone who have same problem first you have to install laravel-dompdf wrapper. then need to add 'PDF' word to app config aliases list(rootfolder/config/app.php) 'PDF' => Barryvdh\DomPDF\ Facade :: class , import pdf class to controller(or any kind of class object) use PDF ; create pdf wrapper object by loading blade file to laravel-dompdf $pdf = PDF :: loadView ( 'print.view' , compact ( ' yourviewdata' )); set paper size (i set L means 'letter size') $pdf -> setPaper ( 'L' ); then need to render it(we can't call dompdf render function directly. we can use output function for that comes with laravel-dompdf $pdf -> output (); now this need to get core dompdf object from laravel-dompdf wrapper to get canvas(canvas need to ad...

Popular posts from this blog

How to use Spatie packages to enhance your Laravel development experience

Some Briefs of Data Mining

What's New in PHP 8.2 ?