Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Glukinho's avatar

Glukinho wrote a reply+100 XP

3d ago

Is it good having approximately 900 lines of a function?

You may more or less understand what's going on inside the function right now. But after a month or half a year you'll be totally lost, for sure.

Glukinho's avatar

Glukinho wrote a reply+100 XP

3d ago

Filament Widget that gets data from WooCommerce via API

I'm getting the error: JSON ERROR: Syntax error

Where is it exactly? In browser window, in browser console, in logs?..

Glukinho's avatar

Glukinho wrote a reply+100 XP

4d ago

403 Forbidden issues in Laravel EC2 and Lightsail for Laravel, Filament, Nginx on login

How does the error look? Is it Laravel error or generic web server error?

Look into Nginx error logs.

Glukinho's avatar

Glukinho wrote a reply+100 XP

5d ago

Observer and scheduled publish dates

You misunderstand what observer is. It has nothing to do with your task. You should schedule a command every N minutes (whatever frequency you prefer) which:

  • takes records ready to be published (in other words, which have published_at in less than N minutes in future)
  • publishes them
  • applies service function you want to be applied to "scheduled" records.

Model observers are about events system, this is another topic.

Glukinho's avatar

Glukinho liked a comment+100 XP

1w ago

I accidentally deleted a Controller. How to recover?

If you use version control, such as Git, recovery is easy. Every developer should always use version control, even if they're working alone.

Another easy way is through an IDE. PhpStorm has a local history that shows file deletions, which you can revert. VS Code is a bit worse in this regard, but it's still possible.

Otherwise, you might be able to do it with some recovery tool. Recovering deleted files is less likely on SSDs than HDDs. Your best bet is to google "undelete tool" and try something to recover it. Recovery becomes less and less likely the longer you keep using the device.

Glukinho's avatar

Glukinho wrote a reply+100 XP

1w ago

I accidentally deleted a Controller. How to recover?

No, recovering your local deleted files is out of Laravel responsibility. You should search in your local system for such things.

If you use version control system (most likely Git) and committed your controller then search there. But I'm afraid that's not the case otherwise you wouldn't ask.

As last chance you can use some data recovery software and most likely you'll find your file as deleted files are not actually erased from disk. I successfully used R-Studio: https://www.r-studio.com/

But I think rewriting the class is the best option for you. It is not so hard to do, you'll polish the logic at the same time. Rewriting actually helps.

Glukinho's avatar

Glukinho wrote a reply+100 XP

1w ago

Best way to truncate very large data table?

INSERT INTO change_logs_backup SELECT * FROM change_logs;

It would take forever. For backup I'd rename change_logs to change_logs_backup and create change_logs from scratch. Same result but almost instantly.

Glukinho's avatar

Glukinho wrote a reply+100 XP

1w ago

Best way to truncate very large data table?

No valid SQL request would crash a database server, you may not worry about that. It is not a matter of table size in any case.

You can dump table structure using SHOW CREATE TABLE tablename or with mysqldump (there is an option for dumping structure only). After that drop a table and recreate with previously dumped structure.

I'm not sure if TRUNCATE does exactly the same as drop/create, but the result would be the same: clean table without rows.

What I wouldn't do is DELETE FROM tablename as it would be very slow and internal counter for auto increment primary key is preserved (so new row id would be something like 167 000 001 which doesn't seem preferable).

Another issue is reclaiming free space used by InnoDB files; the occupied space isn't released automatically especially if you have innodb_file_per_table = off. There are many articles about releasing occupied space; to be short, you have to make full database backup, set innodb_file_per_table = on and restore backup. After that all tables are stored in their own dedicated files and occupy only space really needed for data.

Glukinho's avatar

Glukinho liked a comment+100 XP

2w ago

Increment/Decrement on High Traffic

@eskiesirius You shouldn’t be using a single column to hold the balance. You should instead of some form of ledger table, where you write individual increments and decrements as their own rows, and then derive the balance from the sum of those increments and decrements. It’s not “expensive” if you have a proper index in place.

Glukinho's avatar

Glukinho wrote a reply+100 XP

2w ago

I wanted to query nested data until level 2 on a single model

Give your data structure (tables, columns) and actual code that "says relationship doesn't exist".

Glukinho's avatar

Glukinho wrote a reply+100 XP

2w ago

Subtle bug in orWhere subquery?

I agree scopes are good.

Glukinho's avatar

Glukinho wrote a reply+100 XP

2w ago

Subtle bug in orWhere subquery?

Isn't it your situation described? https://laravel.com/docs/8.x/eloquent-relationships#chaining-orwhere-clauses-after-relationships

How about this?

$products = Product::query()
    ->where('parent_id', '!=', 0)
    ->whereHas('flags', function ($query) use ($messages) {
        $query
            ->where('is_valid', 1)
            ->where(function ($query) use ($messages) {
                foreach ($messages as $message) {
                    $query->orWhere('message', 'LIKE', $message);
                }
            });
    })
    ->get();
Glukinho's avatar

Glukinho was awarded Best Answer+1000 XP

2w ago

No bootstrap.js file anymore in fresh laravel installations ?

You see no bootstrap.js and empty app.js because these files are absent/empty in laravel/laravel repository which is cloned to you every time you install new Laravel app.

The reason why these files were changed in the repository are described by the link I provided.

Something tells me it is related to some Axios vulnerabilities recently discovered.

Sorry maybe I don't fully understand the question...

Glukinho's avatar

Glukinho was awarded Best Answer+1000 XP

2w ago

Exception on server but works fine on localhost

I guess it's about @context, @type which Blade engine recognizes as directives.

See here: https://laravel.com/docs/13.x/blade#blade-and-javascript-frameworks

The @ symbol may also be used to escape Blade directives:

So I think you should either use double @ :

"@@context": "https://schema.org",
"@@type": "WebSite",

Or wrap your scripts with @verbatim ... @endverbatim which prevents it's inner content to be processed by Blade engine:

<script type="application/ld+json">
@verbatim
    {
        "@context": "https://schema.org",
        "@type": "WebSite",
        "name": "xxx",
        ...
    }
@endverbatim 
</script>
Glukinho's avatar

Glukinho wrote a reply+100 XP

2w ago

Exception on server but works fine on localhost

I guess it's about @context, @type which Blade engine recognizes as directives.

See here: https://laravel.com/docs/13.x/blade#blade-and-javascript-frameworks

The @ symbol may also be used to escape Blade directives:

So I think you should either use double @ :

"@@context": "https://schema.org",
"@@type": "WebSite",

Or wrap your scripts with @verbatim ... @endverbatim which prevents it's inner content to be processed by Blade engine:

<script type="application/ld+json">
@verbatim
    {
        "@context": "https://schema.org",
        "@type": "WebSite",
        "name": "xxx",
        ...
    }
@endverbatim 
</script>
Glukinho's avatar

Glukinho wrote a reply+100 XP

2w ago

No bootstrap.js file anymore in fresh laravel installations ?

You see no bootstrap.js and empty app.js because these files are absent/empty in laravel/laravel repository which is cloned to you every time you install new Laravel app.

The reason why these files were changed in the repository are described by the link I provided.

Something tells me it is related to some Axios vulnerabilities recently discovered.

Sorry maybe I don't fully understand the question...

Glukinho's avatar

Glukinho wrote a reply+100 XP

3w ago

problem installing Filament

Why you want v4? Filament 5 was released some time ago, and several updates came already.

Glukinho's avatar

Glukinho wrote a reply+100 XP

3w ago

Failed to mail send from laravel service Incoming email works, but outgoing (reply) fails: SECURITY PROBLEM: insecure server advertised AUTH=PLAIN

SECURITY PROBLEM: insecure server advertised AUTH=PLAIN (errflg=1)

This error strikes from IMAP connection which is used to access a mailbox, not for sending emails. Where this error goes from in your code? I mean specific file and line.

Glukinho's avatar

Glukinho wrote a reply+100 XP

3w ago

Weird error with a Laravel route

So the problem is definitely somewhere inside XAMPP settings. Sorry I'm not very familiar with it. Try to revert your latest changes or even reinstall it from scratch. Looking into Apache logs would be useful also.

...Or you may continue using php artisan serve instead of XAMPP web server.

Glukinho's avatar

Glukinho wrote a reply+100 XP

3w ago

Weird error with a Laravel route

Do you have the error when serving app with php artisan serve instead of XAMPP?

Use php artisan route:list, do you have all routes there?

Glukinho's avatar

Glukinho wrote a reply+100 XP

3w ago

Weird error with a Laravel route

As usual, first of all try php artisan optimize:clear and recreate vendor folder (delete it and run composer install)

Glukinho's avatar

Glukinho wrote a reply+100 XP

3w ago

Reverting from PEST to PHPUnit

A clumsy and awkward approach of recreating conventional OOP logic in functional style?

Glukinho's avatar

Glukinho liked a comment+100 XP

3w ago

upgrading vsanilla php 5.4 to 8.x with laravel

@iamyannc Hey. I’ve done a lot of these type of re-factoring and re-platforming projects in the past. The way I’d approach it would be like this:

  • Get the application running on a newer version of PHP. So upgrade to 7, fix any usage of deprecated APIs and libraries, and then when possible upgrade to PHP 8 and do the same.
  • Once you’ve got the vanilla PHP application running on a modern version of PHP, create a new Laravel application and dump your legacy application’s file in the public directory.
    • Rename Laravel’s index.php file to something like laravel-index.php to avoid clashing with your legacy index.php file.
    • Tweak your .htaccess or nginx config to just load a file if it exists, or fall back to Laravel’s front controller.
  • You should now have a Laravel application, but with no requests actually being routed through it to start off with, and instead requests hitting your legacy application as before.
  • Slowly start re-factoring your legacy application to Laravel controllers, views, etc. Do this slowly, and one discreet part at a time. Trying to re-factor too much in one go just leads to lots of files being touched, none of them 100% converted, and the dreaded feeling of, “Urgh, I need to git reset this and start over.”
  • As you do the above, the number of files from the legacy application will decrease, and the number of Laravel files increase, until you’re left with nothing of the legacy application.

Happy for you to reach out if you have any questions. DM me on Twitter 𝕏 (https://x.com/martinbean) and I can share my email address.

Glukinho's avatar

Glukinho was awarded Best Answer+1000 XP

1mo ago

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

Laravel Telescope does not track HttpClient calls fired from tinker/jobs...

I checked and confirm the same behavior.

See here: https://github.com/laravel/telescope/issues/189#issuecomment-635909972

It's rather old thread, but still applicable to recent versions. I see my HTTP request made from Tinker in Telescope after app()->terminate() in the same tinker session.

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

How does wasChanged work with related tables?

What will wasChanged() show for Product A? What about for Product B?

How about just try it out yourself? In tinker or some test artisan command.

Glukinho's avatar

Glukinho was awarded Best Answer+1000 XP

1mo ago

Migration with geography ?

There are some packages, like this, which seems pretty mature: https://github.com/matanyadaev/laravel-eloquent-spatial

Otherwise you should use something like DB::raw(POINT(100 200)), refer to your database spatial type manual.

It would be nice to see Laravel internal support for such things.

Having simple JSON column seems bad to me as you would want to use DB internal capabilities to calculate area of given polygon or distance between given points. With JSON column you have to calculate them by yourself.

Glukinho's avatar

Glukinho liked a comment+100 XP

1mo ago

Is it worth it to learn all the courses and coding when AI can make the production level application

As of today, AI agents can't make proper apps on their own. What they can do is produce junk that passes tests. To use it for any proper product, you have to understand the code and correct its issues.

It's clear that AI will be useful, but the hype is completely overblown. If you were to go back and read the marketing from two years ago, you'd think you have no future in tech if you didn't use [insert any AI tool hot at the time]. Now those AI models are obsolete, and if you spent the time learning the fundamentals of computer science instead, you'd be much better off.

Some of the recent layoffs in the tech sector can be attributed to pandemic-era over-hiring and the general downturn in the US economy. But I'm sure the over-hyping of generative AI is partly to blame. I believe we'll see more service degradation over the following years.

What you should do ultimately depends on your goals. If you're a non-programmer who wants something on the screen, you may not need to understand the code. I just don't see anyone hiring an "AI prompter" who's helpless when something doesn't work.

Glukinho's avatar

Glukinho was awarded Best Answer+1000 XP

1mo ago

Migration and seeding for big master data

Do you need all 80k rows of data for developing?

Can you use some fake data in your local dev database (let's say 100 rows which is easily faked and seeded as often as you want) and have the whole real 80k rows on production database?

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

Is there a way to use certificates for auth?

This can be handled on web server, not Laravel: https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_client_certificate

I tried it once successfully (web server allowed to view a page only after a browser provides valid certificate), but it was only a test out of curiosity, no real implementation.

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

Migration and seeding for big master data

Do you need all 80k rows of data for developing?

Can you use some fake data in your local dev database (let's say 100 rows which is easily faked and seeded as often as you want) and have the whole real 80k rows on production database?

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

Migration with geography ?

There are some packages, like this, which seems pretty mature: https://github.com/matanyadaev/laravel-eloquent-spatial

Otherwise you should use something like DB::raw(POINT(100 200)), refer to your database spatial type manual.

It would be nice to see Laravel internal support for such things.

Having simple JSON column seems bad to me as you would want to use DB internal capabilities to calculate area of given polygon or distance between given points. With JSON column you have to calculate them by yourself.

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

GraphQL 🤔

Probably if he doesn't know if he needs it, he doesn't.

Glukinho's avatar

Glukinho liked a comment+100 XP

1mo ago

If anyone knows to bind policy to the controller in Laravel 13.

@armanhozyn I’ll never understand why Laravel removed this, as it was great for applying to policy methods to resourceful controller actions.

Nevertheless, you can get it back by importing the AuthorizesRequests trait in your controller:

+ use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

  class CommentController extends Controller
  {
+     use AuthorizesRequests;

      public function __construct()
      {
          $this->authorizeResource(Comment::class);
      }
  }
Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

No way to set HTTP status

abort function puts a message to response body, not in status string. Maybe you should write your own helper function for that.

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

Controller's helper fn

Moving to a model seems more appropriate since this helper interacts with database. Utilize local scope: https://laravel.com/docs/13.x/eloquent#local-scopes

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

Glukinho's avatar

Glukinho liked a comment+100 XP

1mo ago

Axios Hacked! ⚠️

That's why I miss the good old pencil and paper days. Or at least the old MSDOS days.

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

Forum only not displaying on Firefox 149.0 64 bit

It's interesting to know what caused the problem.

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

Database migration

I would use this package: https://github.com/kitloong/laravel-migrations-generator

No matter what you do, Backup first.

+1000000

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

Forum only not displaying on Firefox 149.0 64 bit

I checked with Firefox 149.0 on Windows and I confirm the problem.

Also "Forum" link in a header doesn't work, browser just doesn't navigate to https://laracasts.com/discuss (other nav links work fine).

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

Change page title of relationship infolist

It's getTitle() method in Filament/<...>Resource/Pages/View<...>.php:

public function getTitle(): string|Htmlable
{
    return $this->getRecord()->title;
}
Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

Am I the only one who genuinely prefers on-prem over the cloud?

I share your view. "A cloud" means "someone else's servers". Having your own gives flexibility and security (if you are really able to manage an infrastructure).

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

Relationships using LIKE

It seems it is needless to say such structure is wrong, you probably know that already.

Did you try something like this? https://stackoverflow.com/questions/38608244/laravel-eloquent-query-where-like-relationship

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

I wonder why I didn't receive any email

It's strange, smtp.gmail.com should provide valid certificate and you should be able to verify it. Are you sure you have this mail host? What config('mail.mailers.smtp.host') shows?

At least the problem is localized, that's good.

Try to add to config/mail.php:

'mailers' => [
        'smtp' => [
			// ...
            'verify_peer' => false,
        ],
]

And see what happens on sending test mail.

Glukinho's avatar

Glukinho wrote a reply+100 XP

1mo ago

I wonder why I didn't receive any email

Check here: https://knowledge.workspace.google.com/admin/gmail/send-email-from-a-printer-scanner-or-app?visit_id=639094163082632677-2170550345&rd=1

Gmail was always tricky for sending emails via SMTP.

Do you get a message if you invoke test sending, using php artisan tinker?

Mail::to('d****@yahoo.com')->send(new TestMail);
Glukinho's avatar

Glukinho wrote a reply+100 XP

2mos ago

Working with multiple screens... and one in portrait mode

Using the upper half of the screen for PHPStorm, the lower half for the docs in a browser, and the landscape screen for the actual output made my workflow significantly faster.

You should try three monitors, even more comfortable.