iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🌿

Laravel 11 Storage Commands

に公開

This article is for Day 23 of the Exploring All Artisan Commands in Laravel 11 Advent Calendar 2024.

This time, I looked into the storage commands.

Environment

  • PHP 8.4.1
  • laravel/laravel 11.3.3
  • laravel/framework 11.33.2

Create the symbolic links configured for the application.

php artisan storage:link

When executed, it creates the symbolic links configured for the application.

By default, it creates a symbolic link from storage/app/public to public/storage.

advent-calendar-2024 % php artisan storage:link

   INFO  The [public/storage] link has been connected to [storage/app/public].

Configuration can be written in the following array in config/filesystems.php.
By adding values to the array, you can increase the number of symbolic links that are created.

config/filesystems.php
'links' => [
    public_path('storage') => storage_path('app/public'),
    public_path('images') => storage_path('app/images'), // Addition
],
advent-calendar-2024 % php artisan storage:link

   INFO  The [public/storage] link has been connected to [storage/app/public].

   INFO  The [public/images] link has been connected to [storage/app/images].
Option Description
--relative Create the symbolic links using relative paths
--force Recreate existing symbolic links
  • Adding --relative will create the symbolic links using relative paths.
    However, to use this option, the symfony/filesystem package must be installed.
  • Adding --force will delete any existing symbolic links and recreate them.

Delete the existing symbolic links configured for the application.

php artisan storage:unlink

When executed, it deletes the existing symbolic links.

The targets for deletion are the keys defined in the array in config/filesystems.php.
In the following case, public_path('storage') and public_path('images') are the targets for deletion:

config/filesystems.php
'links' => [
    public_path('storage') => storage_path('app/public'),
    public_path('images') => storage_path('app/images'),
],
GitHubで編集を提案

Discussion