aniket
aniket

Aniket Magadum

@aniket

PHP Laravel Web Developer

81 Posts 877 Views

  • No matching results...
  • Searching...

/ 255

Hey Laravel Developers

If you deal with a lot of external API integrations in your application, a common activity for you might be converting CURL requests from say Postman to HTTP Client in Laravel

Well for the same activity, found a tool created by Laravel Shift that converts a CURL Request to a Laravel Http Client Request

image

2

190

Glad you liked it !

23

Hey Laravel Developers

While debugging any error in the application a common method is commenting out code temporarily to check the impact of the commented code, eg, whether a particular PHP method or file is causing some failure in the application.

If these methods or files are huge commenting out the entire code can be a bit more work especially when you are debugging on a server with access to different editors like Vim.

In those scenarios what we can do is instead of commenting on the code entirely we can just write a return statement at the beginning of the method or file.

This way it's just easy to debug and revert back to the original version faster.

What do you think about this method? What strategies do you use in such kinds of scenarios?

image

63

Hey Laravel Developers

Laravel provides the Model class, which all your application models inherit from by default.

However, a general pattern I like to follow is inheriting the Model class into App\Models\Model and then having my application models extend this new model.

One major benefit of this approach is that I can define global scopes in App\Models\Model, such as active(), published(), and others, which will be available across all models for usage.

image

23

Hey Laravel Developers

One common mistake I’ve seen junior developers make is using the dd() method and expecting to find the request traces inside Laravel Telescope but it does not show any traces.

This happens due to how Laravel Telescope is configured to insert logs into the database.

Telescope doesn’t immediately write entries to the database when events occur.

Instead, it stores them in memory and inserts them together when the request is terminating.

This helps reduce the number of total queries made by Telescope for logging.

However, if you use a dd() statement, the in-memory entries won’t get stored in the database because the app-terminating event isn’t triggered—dd() halts the execution of the PHP script immediately.

So, always use the dump() or logger() functions when debugging with Laravel Telescope.

image

63

Hey Laravel Developers

Did you know that when adding where conditionals in the Query Builder, you can use dynamic method names?

For example, if you want to fetch an order matching a particular quantity, you can call a dynamic method like whereQuantity($quantity) instead of using where('quantity', $quantity).

It just reads so much better! What do you think?

image

4

763

Got your point !

53