专为 Laravel 定制的 Visual Studio Code 编辑器

file

嗨 工匠,我从 Laravel4.1 到 5.4 一直再用它,我相信它仍然是最流行的PHP框架。它提供许多功能为快速开发 web 和 Api ,以及5.3支持 VueJs 前端开发。你也有很多神奇的功能在这吧?

我已经尝试使用了很多编辑器如 sublime,phpstorm(在用vs code之前都用它),atom 和现在用的 visual studio code 。每个编辑器都有它各自的优点,但是我第一次试用 visual studio code 的时候,我印象它又酷有强大,特别在 Git 管理,Debug(下面有尝试)及各种扩展插件??

file

设置 Laravel 的 Vscode 环境

安装下面的插件:

Auto Close Tag

自动添加 HTML/XML 的闭合标签,像 Visual Studio IDE 或 Sublime Text 一样。

file

 Beautify

在 Visual Studio Code 中格式化 javascriptJSON 、 CSSSass,以及 HTML

 Better Merge

Visual Studio Code 中非常好用的可视化合并冲突工具,灵感来自于 Atom 中的 merge-conflicts 插件。

file

 Debugger For Chrome

用于在谷歌浏览器中调试 JavaScript 代码的 VS Code 扩展,或支持 Chrome Debugging Protocol 其他功能。

file

 Eslint

此扩展使用安装在已打开的工作区文件夹内的 ESLint 库。如果文件夹没有提供这个库,将会匹配全局安装的版本。如果既没有局部安装、也没有全局安装 ESLint,可以通过运行npm install eslint 进行局部安装或者npm install -g eslint进行全局安装。

 Npm

此扩展支持定义在package.json文件里的 npm 脚本,并根据定义在package.json里的依赖项验证已安装的模块。

file

 Laravel Blade Snippets

Laravel blade 代码片段和语法高亮支持 Visual Studio Code。

 PHP Debug

此扩展由 Derick Rethan 开发,是一个 VS Code 与 XDebug 之间的调试适配器。XDebug 是一个 PHP 扩展(Linux 下的.so文件或 Windows 下的.dll),需要安装在你的服务器上。

 PHP Intellisense Crane

Crane 是 Visual Studio Code  的生产力增强扩展,提供了 PHP 代码的自动完成。它具有零依赖性,并可以极大程度地工作于任何规模的项目里。它仍在开发中,可能存在 Bug 或缺失某些功能。

file

 Git History

使用图表查看 Git 历史,查看 commit 的详情信息,例如作者名、邮件、日期、提交者的作者名、邮件、日期和提交注释。

查看先前文件的拷贝或者将其与工作区版本或先前版本进行比较,查看编辑器(Git Blame)里对活动行的更改。

file

我使用的 Dracula 主题和 Material Icon Theme 图标主题,现在尝试使用 Vscode 在 laravel 里进行调试吧,运行得好吗?

原文地址:https://medium.com/@ardanirohman/laravel...

译文地址:https://learnku.com/laravel/t/17409

本帖已被设为精华帖!
本文为协同翻译文章,如您发现瑕疵请点击「改进」按钮提交优化建议
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
讨论数量: 23

我觉得PHP智能感知用 bmewburn.vscode-intelephense-client 比较好

11个月前 评论

个人习惯是,前端开发我用VS Code,后台我用PHPstorm。

11个月前 评论

这个感觉没什么必要作为外文翻译,光看插件名和 gif 图都可以了。。。

11个月前 评论

我觉得PHP智能感知用 bmewburn.vscode-intelephense-client 比较好

11个月前 评论

@XiaohuiLam 正在用,除了提示信息的显示稍微简陋了一点,其它蛮好。

11个月前 评论

个人习惯是,前端开发我用VS Code,后台我用PHPstorm。

11个月前 评论

VS Code 写文档和博客还不错,PHP我还是用PhpStom(除了有时候太卡)

11个月前 评论

vscode 智能补全php 需要老长一段时间 比如补全命名空间

11个月前 评论

vscode 感觉对 Laravel PHP 支持不好。 打个 php 函数,老半天提示才出来(等个大概两三秒)。 暂时更适合前端。

11个月前 评论

没看出来哪里为 Laravel 专门定制了。。。

而且我想知道,就这几个插件如何做到取代 PHPStorm 的。。。。

11个月前 评论

VSCode 对 PHP 和 Laravel 补全的支持程度非常接近 PHPStorm 了。关键还是看插件的设置。
file

11个月前 评论

我最头疼的是 VSCode 对 blade(xxx.blade.php)格式,前端模板里面的代码不能格式化!!!有高手解决了吗?

11个月前 评论

我比较在意的是vscode的追踪代码插件和phpstorm自带的比起来还是差强人意.

11个月前 评论
zxk

@XiaohuiLam crane 那个停止更新了。

11个月前 评论

@zxk 我推荐的插件是 ben 的,不是 crane

11个月前 评论
zxk

Vscode 的PHP Debug 胜于 phpstorm , 无需配置就可以用

11个月前 评论
Destiny

@Handle PHP 用 PHPStrom、前端之前我用 Webstrom 现在慢慢转成 VS Code

11个月前 评论

对PHP的重构支持不好

8个月前 评论

@XiaohuiLam 你好,请问这个Laravel 语法的提示用的是 PHP Intelephense 插件吗?我用了这个怎么没有提示,是不是还要什么设置?

5个月前 评论

@gogoing 装了intelephense还需要composer装一个laravel-ide-helper

5个月前 评论

@XiaohuiLam 你好,能说说你是怎么弄的吗? 造福一下广大VsCode使用者,我Laravel是5.7版本。
1.在vscode里面,安装了 PHP--Intelephense
2.在项目目录下安装:composer require barryvdh/laravel-ide-helper
在config/app.php的providers 数组里面 注册了 Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
3.执行php artisan ide-helper:generate

还是没有提示,比如我 User::paginate() 都没有提示,->orderBy,->with, 都没有提示,你截图那样的提示,还要怎么配置

5个月前 评论

@gogoing 你可以把你项目的基础模型加上这个

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * 基础模型
 *
 * @method static \Illuminate\Database\Eloquent\Model make($attributes = array())
 * @method static \Illuminate\Database\Eloquent\Builder withGlobalScope($identifier, $scope)
 * @method static \Illuminate\Database\Eloquent\Builder withoutGlobalScope($scope)
 * @method static \Illuminate\Database\Eloquent\Builder withoutGlobalScopes($scopes = null)
 * @method static array removedScopes()
 * @method static \Illuminate\Database\Eloquent\Builder whereKey($id)
 * @method static \Illuminate\Database\Eloquent\Builder whereKeyNot($id)
 * @method static \Illuminate\Database\Eloquent\Builder where($column, $operator = null, $value = null, $boolean = 'and')
 * @method static \Illuminate\Database\Eloquent\Builder|static orWhere($column, $operator = null, $value = null)
 * @method static \Illuminate\Database\Eloquent\Builder latest($column = null)
 * @method static \Illuminate\Database\Eloquent\Builder oldest($column = null)
 * @method static \Illuminate\Database\Eloquent\Collection hydrate($items)
 * @method static \Illuminate\Database\Eloquent\Collection fromQuery($query, $bindings = array())
 * @method static \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|static[]|static|null find($id, $columns = array())
 * @method static \Illuminate\Database\Eloquent\Collection findMany($ids, $columns = array())
 * @method static \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|static|static[] findOrFail($id, $columns = array())
 * @method static \Illuminate\Database\Eloquent\Model|static findOrNew($id, $columns = array())
 * @method static \Illuminate\Database\Eloquent\Model|static firstOrNew($attributes, $values = array())
 * @method static \Illuminate\Database\Eloquent\Model|static firstOrCreate($attributes, $values = array())
 * @method static \Illuminate\Database\Eloquent\Model|static updateOrCreate($attributes, $values = array())
 * @method static \Illuminate\Database\Eloquent\Model|static firstOrFail($columns = array())
 * @method static \Illuminate\Database\Eloquent\Model|static|mixed firstOr($columns = array(), $callback = null)
 * @method static mixed value($column)
 * @method static \Illuminate\Database\Eloquent\Collection|static[] get($columns = array())
 * @method static \Illuminate\Database\Eloquent\Model[]|static[] getModels($columns = array())
 * @method static array eagerLoadRelations($models)
 * @method static \Generator cursor()
 * @method static bool chunkById($count, $callback, $column = null, $alias = null)
 * @method static \Illuminate\Support\Collection pluck($column, $key = null)
 * @method static \Illuminate\Contracts\Pagination\LengthAwarePaginator paginate($perPage = null, $columns = array(), $pageName = 'page', $page = null)
 * @method static \Illuminate\Contracts\Pagination\Paginator simplePaginate($perPage = null, $columns = array(), $pageName = 'page', $page = null)
 * @method static \Illuminate\Database\Eloquent\Model|$this create($attributes = array())
 * @method static \Illuminate\Database\Eloquent\Model|$this forceCreate($attributes)
 * @method static void onDelete($callback)
 * @method static static|mixed scopes($scopes)
 * @method static static applyScopes()
 * @method static \Illuminate\Database\Eloquent\Builder without($relations)
 * @method static \Illuminate\Database\Eloquent\Model|static newModelInstance($attributes = array())
 * @method static \Illuminate\Database\Query\Builder getQuery()
 * @method static \Illuminate\Database\Eloquent\Builder setQuery($query)
 * @method static \Illuminate\Database\Query\Builder toBase()
 * @method static array getEagerLoads()
 * @method static \Illuminate\Database\Eloquent\Builder setEagerLoads($eagerLoad)
 * @method static \Illuminate\Database\Eloquent\Model|static getModel()
 * @method static \Illuminate\Database\Eloquent\Builder setModel($model)
 * @method static \Closure getMacro($name)
 * @method static bool chunk($count, $callback)
 * @method static bool each($callback, $count = 1000)
 * @method static \Illuminate\Database\Eloquent\Model|object|static|null first($columns = array())
 * @method static mixed|$this when($value, $callback, $default = null)
 * @method static \Illuminate\Database\Query\Builder tap($callback)
 * @method static mixed|$this unless($value, $callback, $default = null)
 * @method static \Illuminate\Database\Eloquent\Builder|static has($relation, $operator = '>=', $count = 1, $boolean = 'and', $callback = null)
 * @method static \Illuminate\Database\Eloquent\Builder|static orHas($relation, $operator = '>=', $count = 1)
 * @method static \Illuminate\Database\Eloquent\Builder|static doesntHave($relation, $boolean = 'and', $callback = null)
 * @method static \Illuminate\Database\Eloquent\Builder|static orDoesntHave($relation)
 * @method static \Illuminate\Database\Eloquent\Builder|static whereHas($relation, $callback = null, $operator = '>=', $count = 1)
 * @method static \Illuminate\Database\Eloquent\Builder|static orWhereHas($relation, $callback = null, $operator = '>=', $count = 1)
 * @method static \Illuminate\Database\Eloquent\Builder|static whereDoesntHave($relation, $callback = null)
 * @method static \Illuminate\Database\Eloquent\Builder|static orWhereDoesntHave($relation, $callback = null)
 * @method static \Illuminate\Database\Eloquent\Builder withCount($relations)
 * @method static \Illuminate\Database\Eloquent\Builder|static mergeConstraintsFrom($from)
 * @method static \Illuminate\Database\Query\Builder select($columns = array())
 * @method static \Illuminate\Database\Query\Builder|static selectSub($query, $as)
 * @method static \Illuminate\Database\Query\Builder|static selectRaw($expression, $bindings = array())
 * @method static \Illuminate\Database\Query\Builder|static fromSub($query, $as)
 * @method static \Illuminate\Database\Query\Builder|static fromRaw($expression, $bindings = array())
 * @method static \Illuminate\Database\Query\Builder addSelect($column)
 * @method static \Illuminate\Database\Query\Builder distinct()
 * @method static \Illuminate\Database\Query\Builder from($table)
 * @method static \Illuminate\Database\Query\Builder join($table, $first, $operator = null, $second = null, $type = 'inner', $where = false)
 * @method static \Illuminate\Database\Query\Builder|static joinWhere($table, $first, $operator, $second, $type = 'inner')
 * @method static \Illuminate\Database\Query\Builder|static joinSub($query, $as, $first, $operator = null, $second = null, $type = 'inner', $where = false)
 * @method static \Illuminate\Database\Query\Builder|static leftJoin($table, $first, $operator = null, $second = null)
 * @method static \Illuminate\Database\Query\Builder|static leftJoinWhere($table, $first, $operator, $second)
 * @method static \Illuminate\Database\Query\Builder|static leftJoinSub($query, $as, $first, $operator = null, $second = null)
 * @method static \Illuminate\Database\Query\Builder|static rightJoin($table, $first, $operator = null, $second = null)
 * @method static \Illuminate\Database\Query\Builder|static rightJoinWhere($table, $first, $operator, $second)
 * @method static \Illuminate\Database\Query\Builder|static rightJoinSub($query, $as, $first, $operator = null, $second = null)
 * @method static \Illuminate\Database\Query\Builder|static crossJoin($table, $first = null, $operator = null, $second = null)
 * @method static void mergeWheres($wheres, $bindings)
 * @method static array prepareValueAndOperator($value, $operator, $useDefault = false)
 * @method static \Illuminate\Database\Query\Builder|static whereColumn($first, $operator = null, $second = null, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder|static orWhereColumn($first, $operator = null, $second = null)
 * @method static \Illuminate\Database\Query\Builder whereRaw($sql, $bindings = array(), $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder|static orWhereRaw($sql, $bindings = array())
 * @method static \Illuminate\Database\Query\Builder whereIn($column, $values, $boolean = 'and', $not = false)
 * @method static \Illuminate\Database\Query\Builder|static orWhereIn($column, $values)
 * @method static \Illuminate\Database\Query\Builder|static whereNotIn($column, $values, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder|static orWhereNotIn($column, $values)
 * @method static \Illuminate\Database\Query\Builder whereIntegerInRaw($column, $values, $boolean = 'and', $not = false)
 * @method static \Illuminate\Database\Query\Builder whereIntegerNotInRaw($column, $values, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder whereNull($column, $boolean = 'and', $not = false)
 * @method static \Illuminate\Database\Query\Builder|static orWhereNull($column)
 * @method static \Illuminate\Database\Query\Builder|static whereNotNull($column, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder whereBetween($column, $values, $boolean = 'and', $not = false)
 * @method static \Illuminate\Database\Query\Builder|static orWhereBetween($column, $values)
 * @method static \Illuminate\Database\Query\Builder|static whereNotBetween($column, $values, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder|static orWhereNotBetween($column, $values)
 * @method static \Illuminate\Database\Query\Builder|static orWhereNotNull($column)
 * @method static \Illuminate\Database\Query\Builder|static whereDate($column, $operator, $value = null, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder|static orWhereDate($column, $operator, $value = null)
 * @method static \Illuminate\Database\Query\Builder|static whereTime($column, $operator, $value = null, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder|static orWhereTime($column, $operator, $value = null)
 * @method static \Illuminate\Database\Query\Builder|static whereDay($column, $operator, $value = null, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder|static orWhereDay($column, $operator, $value = null)
 * @method static \Illuminate\Database\Query\Builder|static whereMonth($column, $operator, $value = null, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder|static orWhereMonth($column, $operator, $value = null)
 * @method static \Illuminate\Database\Query\Builder|static whereYear($column, $operator, $value = null, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder|static orWhereYear($column, $operator, $value = null)
 * @method static \Illuminate\Database\Query\Builder|static whereNested($callback, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder forNestedWhere()
 * @method static \Illuminate\Database\Query\Builder addNestedWhereQuery($query, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder whereExists($callback, $boolean = 'and', $not = false)
 * @method static \Illuminate\Database\Query\Builder|static orWhereExists($callback, $not = false)
 * @method static \Illuminate\Database\Query\Builder|static whereNotExists($callback, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder|static orWhereNotExists($callback)
 * @method static \Illuminate\Database\Query\Builder addWhereExistsQuery($query, $boolean = 'and', $not = false)
 * @method static \Illuminate\Database\Query\Builder whereRowValues($columns, $operator, $values, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder orWhereRowValues($columns, $operator, $values)
 * @method static \Illuminate\Database\Query\Builder whereJsonContains($column, $value, $boolean = 'and', $not = false)
 * @method static \Illuminate\Database\Query\Builder orWhereJsonContains($column, $value)
 * @method static \Illuminate\Database\Query\Builder whereJsonDoesntContain($column, $value, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder orWhereJsonDoesntContain($column, $value)
 * @method static \Illuminate\Database\Query\Builder whereJsonLength($column, $operator, $value = null, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder orWhereJsonLength($column, $operator, $value = null)
 * @method static \Illuminate\Database\Query\Builder dynamicWhere($method, $parameters)
 * @method static \Illuminate\Database\Query\Builder groupBy($groups = null)
 * @method static \Illuminate\Database\Query\Builder having($column, $operator = null, $value = null, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder|static orHaving($column, $operator = null, $value = null)
 * @method static \Illuminate\Database\Query\Builder|static havingBetween($column, $values, $boolean = 'and', $not = false)
 * @method static \Illuminate\Database\Query\Builder havingRaw($sql, $bindings = array(), $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder|static orHavingRaw($sql, $bindings = array())
 * @method static \Illuminate\Database\Query\Builder orderBy($column, $direction = 'asc')
 * @method static \Illuminate\Database\Query\Builder orderByDesc($column)
 * @method static \Illuminate\Database\Query\Builder inRandomOrder($seed = '')
 * @method static \Illuminate\Database\Query\Builder orderByRaw($sql, $bindings = array())
 * @method static \Illuminate\Database\Query\Builder|static skip($value)
 * @method static \Illuminate\Database\Query\Builder offset($value)
 * @method static \Illuminate\Database\Query\Builder|static take($value)
 * @method static \Illuminate\Database\Query\Builder limit($value)
 * @method static \Illuminate\Database\Query\Builder|static forPage($page, $perPage = 15)
 * @method static \Illuminate\Database\Query\Builder|static forPageBeforeId($perPage = 15, $lastId = 0, $column = 'id')
 * @method static \Illuminate\Database\Query\Builder|static forPageAfterId($perPage = 15, $lastId = 0, $column = 'id')
 * @method static \Illuminate\Database\Query\Builder|static union($query, $all = false)
 * @method static \Illuminate\Database\Query\Builder|static unionAll($query)
 * @method static \Illuminate\Database\Query\Builder lock($value = true)
 * @method static \Illuminate\Database\Query\Builder lockForUpdate()
 * @method static \Illuminate\Database\Query\Builder sharedLock()
 * @method static string toSql()
 * @method static int getCountForPagination($columns = array())
 * @method static string implode($column, $glue = '')
 * @method static bool exists()
 * @method static bool doesntExist()
 * @method static int count($columns = '*')
 * @method static mixed min($column)
 * @method static mixed max($column)
 * @method static mixed sum($column)
 * @method static mixed avg($column)
 * @method static mixed average($column)
 * @method static mixed aggregate($function, $columns = array())
 * @method static float|int numericAggregate($function, $columns = array())
 * @method static bool insert($values)
 * @method static int insertGetId($values, $sequence = null)
 * @method static bool insertUsing($columns, $query)
 * @method static bool updateOrInsert($attributes, $values = array())
 * @method static void truncate()
 * @method static \Illuminate\Database\Query\Expression raw($value)
 * @method static array getBindings()
 * @method static array getRawBindings()
 * @method static \Illuminate\Database\Query\Builder setBindings($bindings, $type = 'where')
 * @method static \Illuminate\Database\Query\Builder addBinding($value, $type = 'where')
 * @method static \Illuminate\Database\Query\Builder mergeBindings($query)
 * @method static \Illuminate\Database\Query\Processors\Processor getProcessor()
 * @method static \Illuminate\Database\Query\Grammars\Grammar getGrammar()
 * @method static \Illuminate\Database\Query\Builder useWritePdo()
 * @method static static cloneWithout($properties)
 * @method static static cloneWithoutBindings($except)
 * @method static void macro($name, $macro)
 * @method static void mixin($mixin, $replace = true)
 * @method static mixed macroCall($method, $parameters)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BaseModel newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BaseModel newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BaseModel query()
 * @mixin \Eloquent
 */
abstract class BaseModel extends Model
{
5个月前 评论

@XiaohuiLam 能提示了,哈哈!这个注释是怎么生成的

5个月前 评论

@gogoing 自己从ide_helper.php提取的

5个月前 评论

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!