Code Pie

Code Pie

Share

This Page is About Help in Various Problems and issues in WordPress

01/06/2026

Title:
Stop Returning Raw Eloquent Models From Laravel APIs

Post:
A common Laravel mistake is exposing Eloquent models directly in API responses. It works fast, but it leaks internal fields, creates inconsistent payloads, and makes versioning painful later.

Use API Resources to control exactly what your frontend gets. They let you shape response data, hide sensitive attributes, and keep your API stable as your database evolves.

This becomes especially important when working with mobile apps, Next.js frontends, or external integrations where response contracts must stay predictable.

Code Example (if applicable):

php
use App\Http\Resources\UserResource;
use App\Models\User;

Route::get('/users/{user}', function (User $user) {
return new UserResource($user);
});

php
// app/Http/Resources/UserResource.php
namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class UserResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
'created_at' => $this->created_at->toISOString(),
];
}
}

Quick Tip:
If your API response changes often, wrap every model in a Resource now — it saves painful refactors later.

Hashtags:

23/05/2026

Title:
Boost Flutter Performance with `const` Widgets Everywhere

Post:
In Flutter, minimizing widget rebuilds is critical for smooth UI performance. One practical way is to use `const` constructors wherever possible. Marking widgets as `const` signals to Flutter that these widgets are immutable and can be reused across rebuilds, preventing unnecessary widget creation.

Real-world tip: Avoid defining widgets inline without `const`. Instead, extract them as `const` stateless widgets or wrap static parts of your UI in `const`. This reduces widget rebuild costs drastically, especially in large lists or complex UIs.

Code Example:

```dart
// Inefficient - widget rebuilt every time setState triggers
Widget build(BuildContext context) {
return Text('Hello Flutter');
}

// Efficient - widget is a const compile-time constant
Widget build(BuildContext context) {
return const Text('Hello Flutter');
}

// Extracted const widget example
class Greeting extends StatelessWidget {
const Greeting({Key? key}) : super(key: key);


Widget build(BuildContext context) {
return const Text('Hello Flutter');
}
}
```

Quick Tip:
Use Flutter’s `dart analyze` with `prefer_const_constructors` lint rule enabled to catch places where you can add `const`.

Hashtags:

22/05/2026

Do you think flutter is too slow for heavy Apps?

Want your business to be the top-listed Computer & Electronics Service in Islamabad?
Click here to claim your Sponsored Listing.

Website

Address


Islamabad