If you’ve been learning Laravel recently, this post will help you quickly revise some important concepts in a simple and practical way.
1. How Password Reset Works with Token
Laravel uses a secure token-based system for password resets:
- When a user requests a reset, Laravel generates a unique token.
- This token is stored in the database (usually in
password_resetstable). - A reset link with the token is sent via email.
- When the user clicks the link, Laravel verifies the token.
- If valid, the user can set a new password.
👉 Think of the token as a temporary secure key that proves the request is valid.
2. Custom Factory State (Dummy Data)
Factories help generate fake data for testing.
- A state lets you define a specific variation of data.
Example:
User::factory()->state(['role' => 'admin'])->create();You can also define named states inside the factory:
public function admin()
{
return $this->state([
'role' => 'admin',
]);
}👉 Useful when you need different types of test users (admin, customer, etc.).
3. Laravel Fallback Route
A fallback route runs when no other route matches.
Route::fallback(function () {
return "Page not found";
});👉 It acts like a custom 404 handler.
4. Why Route Order Matters
Laravel checks routes from top to bottom.
Example:
Route::get('/user/{id}', ...);
Route::get('/user/create', ...);Problem:
/user/createwill be treated as{id}
Solution:
- Always define specific routes first, then dynamic ones.
👉 Rule: Top = priority
5. Route Model Binding
Automatically fetch model data from route parameters.
Example:
Route::get('/users/{user}', function (User $user) {
return $user;
});Laravel:
- Finds user by ID
- Injects it into the route
👉 Saves time and avoids manual queries like User::find().
6. Model Relationships
Laravel makes it easy to connect tables.
Common types:
- One to One → User → Profile
- One to Many → Post → Comments
- Many to Many → Users ↔ Roles
Example:
public function posts()
{
return $this->hasMany(Post::class);
}👉 Helps you work with related data easily using Eloquent.
7. Query Scopes
Scopes are reusable query filters.
Local Scope:
public function scopeActive($query)
{
return $query->where('status', 'active');
}Usage:
User::active()->get();👉 Keeps your queries clean and reusable.
8. Tinker (Laravel Playground)
Tinker lets you interact with your app in the terminal.
Run:
php artisan tinkerWhat you can do:
- Test queries
- Create records
- Debug code
Useful shortcuts:
exit→ quit tinkerCtrl + C→ cancel current command- Arrow ↑ ↓ → previous commands
👉 Think of Tinker as a live testing sandbox.
9. Resource Controller vs Normal Controller
Resource Controller:
php artisan make:controller PostController --resourceCreates methods like:
- index()
- create()
- store()
- show()
- edit()
- update()
- destroy()
Normal Controller:
- You define methods manually
👉 Resource controllers follow CRUD structure automatically.
10. Blade Naming Convention & “Dot” Syntax
Blade uses dot notation to map folders.
Example:
return view('admin.users.index');This maps to:
resources/views/admin/users/index.blade.php👉 Dot (.) = folder separator
🧠 11. Laravel Caching (Speed Booster)
Caching means storing frequently used data so Laravel doesn’t have to fetch it again and again from the database.
✅ Why use cache?
- Faster performance
- Reduced database load
🔹 Common Cache Methods
1. Cache::put() (Store data)
use Illuminate\Support\Facades\Cache;
Cache::put('user_name', 'John', 60); // store for 60 seconds
2. Cache::get() (Retrieve data)
$name = Cache::get('user_name');
3. Cache::remember() (Best one ⭐)
Stores data if not exists, otherwise returns cached data.
$users = Cache::remember('users', 60, function () {
return DB::table('users')->get();
});
👉 Very useful for DB queries.
4. Cache::forget() (Delete cache)
Cache::forget('users');
5. Cache::flush() (Clear all cache)
Cache::flush();
❌ When NOT to use cache
- Frequently changing data (like live stock prices)
- User-specific sensitive data
- Small/simple queries (not worth caching)
🔄 Clear cache when DB updates
Example:
public function update(Request $request, $id)
{
DB::table('users')->where('id', $id)->update([
'name' => $request->name
]);
Cache::forget('users'); // clear old cached data
}
🧭 12. Nested Routes (Clean URL Structure)
Nested routes help represent relationships.
🧩 Example: Posts & Comments
Route::resource('posts.comments', CommentController::class);
URL will look like:
/posts/1/comments/5
👉 Meaning: Comment 5 belongs to Post 1
✅ Why useful?
- Clean structure
- Easy relationship handling
- Better readability
📋 13. Form Request Validation (Clean Validation)
Instead of writing validation inside controllers, Laravel lets you move it into a separate class.
🔹 Create Form Request
php artisan make:request StoreUserRequest
🔹 Add validation
public function rules()
{
return [
'name' => 'required|max:255',
'email' => 'required|email|unique:users',
];
}
🔹 Use in Controller
public function store(StoreUserRequest $request)
{
User::create($request->validated());
}
👉 Cleaner controller, reusable validation!
🧩 14. Laravel Components (Reusable UI Blocks)
Components help you reuse UI parts like buttons, cards, layouts.
🔹 Create Component
php artisan make:component Alert
🔹 Blade file:
<div class="alert alert-{{ $type }}">
{{ $slot }}
</div>
🔹 Use it:
<x-alert type="success">
Data saved successfully!
</x-alert>
✅ Why useful?
- Reusable UI
- Cleaner Blade files
- DRY (Don’t Repeat Yourself)
🎨 15. Why npm run dev fixes CSS?
When your CSS isn’t working, running:
npm run dev
👉 It compiles assets (CSS, JS) using Vite.
💡 What’s happening?
- Laravel uses modern tools (Vite)
- Your CSS (especially Tailwind) is processed
- Output is generated in
/public/build
🧠 Without it:
Changes in CSS won’t reflect.
⚙️ 16. Understanding vite.config.js
This file controls how your frontend assets are built.
🔹 Example:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/app.js'],
refresh: true,
}),
],
});
🧩 What it does:
- Defines entry files (CSS & JS)
- Enables hot reload (auto refresh)
- Connects Laravel with Vite
🔥 Key benefits:
- Super fast builds
- Live reload
- Modern frontend workflow
Final Thoughts
These concepts are the building blocks of Laravel development:
- Routing controls flow
- Models manage data
- Blade handles UI
- Factories & Tinker help testing
- Faster (Caching)
- Cleaner (Form Requests & Components)
- Organized (Nested Routes)
- Modern (Vite & npm)
If you understand these well, you’re already on a solid path 🚀
