DEV Community

Cover image for How to Use Global Scope in Laravel
Saddam Hossain
Saddam Hossain

Posted on

1

How to Use Global Scope in Laravel

In this tutorial i will show How to Use Global Scope in Laravel. we’ll explore the power of Laravel’s global scope using a practical example. We will be implementing a global scope to ensure we only retrieve posts that are set to published.

How to Use Global Scope in Laravel

After the step-by-step guide, I’ll provide some more examples and answer some frequently asked questions. You Can Learn How to Encrypt and Decrypt Model Data Using Casts in Laravel

Let’s get started! How to Use Global Scope in Laravel

Step 1: Create a Laravel Project

Begin by creating a new Laravel project if you haven’t already. Open your terminal and run:

composer create-project laravel/laravel blogapp
cd blogapp
Enter fullscreen mode Exit fullscreen mode

Step 2: Create the Model

Generate a model for the Post using the following Artisan command:

php artisan make:model Post
Enter fullscreen mode Exit fullscreen mode

Step 3: Create the Migration(s)

Now let’s create a migration for the posts table using the following command:
Read More

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more