You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PhpStorm 2021.1.4中配置Laravel链式调用格式化规则?

PhpStorm 2021.1.4 调整Laravel链式调用格式化缩进配置步骤

当前格式化后链式调用缩进效果:

$totalVotesCount = Vote::getByName($filterName, true)
                       ->getByStatus($filterStatus)
                       ->getByIsQuiz($filterIsQuiz)
                       ->getByIsHomepage($filterIsHomepage)
                       ->with('voteCategory')
                       ->with('creator')
                       ->getByVoteCategoryId($filterVoteCategoryId)
                       ->count();

期望格式化效果:

$totalVotesCount = Vote::getByName($filterName, true)
    ->getByStatus($filterStatus)
    ->getByIsQuiz($filterIsQuiz)
    ->getByIsHomepage($filterIsHomepage)
    ->with('voteCategory')
    ->with('creator')
    ->getByVoteCategoryId($filterVoteCategoryId)
    ->count();

配置步骤如下:

  • 打开设置面板:使用快捷键Ctrl+Alt+S(Windows/Linux)或Cmd+,(Mac),或通过顶部菜单「File」→「Settings」(Windows/Linux)/「PhpStorm」→「Preferences」(Mac)进入。
  • 定位到PHP代码风格配置:左侧导航依次展开「Editor」→「Code Style」→「PHP」。
  • 调整链式调用缩进规则:
    1. 切换到「Wrapping and Braces」标签页。
    2. 找到「Chained method calls」分组,取消勾选「Align when multiline」选项(该选项会让链式调用对齐到赋值语句的等号位置)。
    3. 确保「Indent chained calls」的缩进值设置为你需要的空格数(比如4,对应示例中的效果)。
  • 保存配置:点击「Apply」→「OK」,之后执行格式化代码操作(Ctrl+Alt+L/Cmd+Opt+L)即可生效。

内容的提问来源于stack exchange,提问作者mstdmstd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 10:01:43