PHP Developer Guide
Other documentationsDemoCommunityGitHub
  • Forest Admin
  • Getting started
    • How it works
    • Quick start
      • Symfony
      • Laravel
    • Create your agent
    • Troubleshooting
    • Migrating legacy agents
      • Pre-requisites
      • Recommendations
      • Migration steps
      • Code transformations
        • API Charts
        • Live Queries
        • Smart Charts
        • Route overrides
        • Smart Actions
        • Smart Fields
        • Smart Relationships
        • Smart Segments
  • Data Sources
    • Getting Started
      • Collection selection
      • Naming conflicts
      • Query interface and Native Queries
        • Fields and projections
        • Filters
        • Aggregations
    • Provided data sources
      • Doctrine
      • Eloquent
        • Polymorphic relationships
    • Write your own
      • Translation strategy
        • Structure declaration
        • Capabilities declaration
        • Read implementation
        • Write implementation
        • Intra-data source Relationships
      • Contribute
  • Agent customization
    • Getting Started
    • Actions
      • Scope and context
      • Result builder
      • Static Forms
      • Dynamic Forms
      • Related data invalidation
    • Charts
      • Value
      • Objective
      • Percentage
      • Distribution
      • Leaderboard
      • Time-based
    • Fields
      • Add fields
      • Move, rename and remove fields
      • Override binary field mode
      • Override writing behavior
      • Override filtering behavior
      • Override sorting behavior
      • Validation
    • Hooks
      • Collection hook
      • Collection override
    • Pagination
    • Plugins
      • Write your own
    • Relationships
      • To a single record
      • To multiple records
      • Computed foreign keys
      • Under the hood
    • Search
    • Segments
  • Frontend customization
    • Smart Charts
      • Create a table chart
      • Create a bar chart
      • Create a cohort chart
      • Create a density map
    • Smart Views
      • Create a Map view
      • Create a Calendar view
      • Create a Shipping view
      • Create a Gallery view
      • Create a custom tinder-like validation view
      • Create a custom moderation view
  • Deploying to production
    • Environments
      • Deploy on AWS
      • Deploy on Heroku
      • Deploy on GCP
      • Deploy on Ubuntu
    • Development workflow
    • Using branches
    • Deploying your changes
    • Forest Admin CLI commands
      • init
      • login
      • branch
      • switch
      • set-origin
      • push
      • environments:create
      • environments:reset
      • deploy
  • Upgrade
    • Laravel agent upgrade to v3
  • Under the hood
    • .forestadmin-schema.json
    • Data Model
      • Typing
      • Relationships
    • Security & Privacy
Powered by GitBook
On this page
  • Upgrade the forestadmin/laravel-forestadmin agent to v3.
  • Upgrading to v3
  • Breaking Changes

Was this helpful?

  1. Upgrade

Laravel agent upgrade to v3

PreviousdeployNext.forestadmin-schema.json

Last updated 8 months ago

Was this helpful?

This is the official documentation of the forestadmin/laravel-forestadmin v2+ and forestadmin/symfony-forestadmin PHP agents.

The purpose of this note is to help developers to upgrade their Laravel agent from v2 to v3. Please read carefully and integrate the following breaking changes to ensure a smooth update.​

Upgrade the forestadmin/laravel-forestadmin agent to v3.

Please be aware that while Forest Admin make every effort to ensure that our platform updates are broadly compatible and offer detailed instructions for upgrading, Forest Admin cannot guarantee that custom code developed by the developers will always be compatible with new versions of our software. This includes any custom modifications or extensions to core functionalities, such as method overrides or custom integrations. It is the responsibility of the developers to review and test their custom code to ensure compatibility with each new version. Our team provides comprehensive upgrade guides to assist in this process, but these cannot encompass the unique customizations that may be present in each customer's environment. Therefore, Forest Admin strongly recommend establishing a thorough testing protocol for your specific customizations to safeguard against potential issues during the upgrade process.

This upgrade allows users to cache their Laravel configuration with the native command php artisan config:cache

Upgrading to v3

Before upgrading to v3, consider the below .

As for any dependency upgrade, it's very important to test this upgrade in your testing environments. Not doing so could result in your admin panel being unusable.

To upgrade to version 3, follow these steps and then update your project as shown in the Breaking Changes section below.

Step 1: Install the new version

In your composer.json file specify the new package version:

"forestadmin/laravel-forestadmin": "^3.0"

Then update the package with the following command:

composer update forestadmin/laravel-forestadmin

Step 2: Publish the configuration files from our package to your application

php artisan vendor:publish --provider="ForestAdmin\LaravelForestAdmin\ForestServiceProvider" --tag=forest --tag=config

At this stage you should have 2 new files in your application:

  • config/forest.php

  • forest/forest_admin.php

Step 3: Remove the old configuration file

Take any customization you may have done in the old configuration file config/forest_admin.php and put it in the new one forest/forest_admin.php. Then delete the old configuration file config/forest_admin.php.

Step 4: Clear the cache

php artisan cache:clear && php artisan config:clear

Step 5: Launch your app

Restart your application.

Breaking Changes

The previous configuration prevented caching the configuration in Laravel with the command php artisan config:cache To comply with Laravel standards, agent configuration and settings are moved into 2 separate files.

Before

Settings

The settings are loaded into the package using the Laravel env() helper.

Agent configuration

<?php

use ForestAdmin\AgentPHP\Agent\Builder\AgentFactory;
use ForestAdmin\AgentPHP\DatasourceEloquent\EloquentDatasource;

return static function () {
    $forestAgent = app()->make(AgentFactory::class);
    $forestAgent->addDatasource(
        new EloquentDatasource(
            [
                'driver'   => env('DB_CONNECTION'),
                'host'     => env('DB_HOST'),
                'port'     => env('DB_PORT'),
                'database' => env('DB_DATABASE'),
                'username' => env('DB_USERNAME'),
                'password' => env('DB_PASSWORD'),
                // OR
                // 'url' => env('DATABASE_URL'),
            ]
        ),
    );
};

After

Settings

The settings are loaded from this new file using the Laravel config() helper. In the Laravel ecosystem, if you use the env() helper outside a configuration file, it returns null if the configuration is cached.

<?php
# config/forest.php

return [
    'debug'                => env('FOREST_DEBUG', true),
    'authSecret'           => env('FOREST_AUTH_SECRET'),
    'envSecret'            => env('FOREST_ENV_SECRET'),
    'forestServerUrl'      => env('FOREST_SERVER_URL', 'https://api.forestadmin.com'),
    'isProduction'         => env('FOREST_ENVIRONMENT', 'dev') === 'prod',
    'prefix'               => env('FOREST_PREFIX', 'forest'),
    'permissionExpiration' => env('FOREST_PERMISSIONS_EXPIRATION_IN_SECONDS', 300),
    'cacheDir'             => storage_path('framework/cache/data/forest'),
    'schemaPath'           => base_path() . '/.forestadmin-schema.json',
    'projectDir'           => base_path(),
];

Agent configuration

<?php
# forest/forest_admin.php

use ForestAdmin\AgentPHP\Agent\Builder\AgentFactory;
use ForestAdmin\AgentPHP\DatasourceEloquent\EloquentDatasource;

return static function () {
    $defaultDB = config('database.default');
    $forestAgent = app()->make(AgentFactory::class);

    $forestAgent->addDatasource(
        new EloquentDatasource(config('database.connections.' . $defaultDB)),
    );
};
breaking changes