🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# laravel [laravel5.5中文文档](https://laravelacademy.org/laravel-docs-5_5) - 安装 ``` <pre class="calibre14">``` composer create<span class="token">-</span>project laravel<span class="token">/</span>laravel project<span class="token">-</span>name <span class="token">--</span>prefer<span class="token">-</span>dist <span class="token4">"5.5.*"</span> composer require barryvdh<span class="token">/</span>laravel<span class="token">-</span>ide<span class="token">-</span>helper <span class="token">--</span>dev composer require barryvdh<span class="token">/</span>laravel<span class="token">-</span>debugbar <span class="token">--</span>dev composer require barryvdh<span class="token">/</span>laravel<span class="token">-</span>cors 解决跨域 composer require laravel<span class="token">/</span>passport 认证 composer require caouecs<span class="token">/</span>laravel<span class="token">-</span>lang<span class="token2">:</span><span class="token">~</span><span class="token3">4.0</span> 中文<span class="token2">,</span>需要复制src下中文到语言下 composer require <span class="token4">"spatie/laravel-query-builder"</span> api开发必须 composer require encore<span class="token">/</span>laravel<span class="token">-</span>admin composer require tymon<span class="token">/</span>jwt<span class="token">-</span>auth composer require spatie<span class="token">/</span>laravel<span class="token">-</span>permission权限设计 在app<span class="token">/</span>Http<span class="token">/</span>Kernel<span class="token2">.</span>php protected $middleware <span class="token">=</span> <span class="token2">[</span> \Barryvdh\Cors\HandleCors<span class="token2">:</span><span class="token2">:</span>class<span class="token2">,</span> <span class="token2">]</span><span class="token2">;</span> 全局跨域 protected $middlewareGroups <span class="token">=</span> <span class="token2">[</span> <span class="token4">'web'</span> <span class="token">=</span><span class="token">></span> <span class="token2">[</span> <span class="token2">]</span><span class="token2">,</span> <span class="token4">'api'</span> <span class="token">=</span><span class="token">></span> <span class="token2">[</span> \Barryvdh\Cors\HandleCors<span class="token2">:</span><span class="token2">:</span>class<span class="token2">,</span> <span class="token2">]</span><span class="token2">,</span> <span class="token2">]</span><span class="token2">;</span> 异常处理<span class="token3">404</span><span class="token2">;</span>app<span class="token">/</span>Exceptions<span class="token">/</span>Handler<span class="token2">.</span>php 的 render 方法添加如下代码 <span class="token5">if</span> <span class="token2">(</span>$exception <span class="token5">instanceof</span> <span class="token1">ModelNotFoundException</span><span class="token2">)</span> <span class="token2">{</span> <span class="token5">return</span> <span class="token1">response</span><span class="token2">(</span><span class="token2">)</span><span class="token">-</span><span class="token">></span><span class="token1">json</span><span class="token2">(</span><span class="token2">[</span> <span class="token4">'error'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'Resource not found.'</span> <span class="token2">]</span><span class="token2">,</span><span class="token3">404</span><span class="token2">)</span><span class="token2">;</span> <span class="token2">}</span> ``` ``` 常用命令 ``` <pre class="calibre14">``` php artisan cache<span class="token2">:</span>clear 清理缓存 php artisan make<span class="token2">:</span>model Article <span class="token">-</span>m 创建article模型 php artisan migrate 执行迁移文件 php artisan make<span class="token2">:</span>seeder ArticlesTableSeeder 生成填充器 php artisan db<span class="token2">:</span>seed <span class="token">--</span>class<span class="token">=</span>ArticlesTableSeeder 填充数据 $faker <span class="token">=</span> \Faker\Factory<span class="token2">:</span><span class="token2">:</span><span class="token1">create</span><span class="token2">(</span><span class="token4">'zh_CN'</span><span class="token2">)</span><span class="token2">;</span> php artisan make<span class="token2">:</span>controller ArticleController 创建控制器 php artisan make<span class="token2">:</span>migration <span class="token">--</span>table<span class="token">=</span>users adds_api_token_to_users_table 创建迁移文件AddsApiTokenToUsersTable php artisan make<span class="token2">:</span>auth 生成登陆注册认证 php artisan migrate ``` ``` redis 支持设置 phpredis和predis ``` <pre class="calibre14">``` composer require predis<span class="token">/</span>predis ``` ``` - 引用第三方类库 ``` <pre class="calibre16">``` 在app下建立Lib目录<span class="token2">,</span>然后创建类文件 在composer<span class="token2">.</span>js里面添加文件路径 <span class="token4">"classmap"</span><span class="token2">:</span> <span class="token2">[</span> <span class="token4">"database/seeds"</span><span class="token2">,</span> <span class="token4">"database/factories"</span><span class="token2">,</span> <span class="token4">"app/Lib"</span> <span class="token2">]</span><span class="token2">,</span> <span class="token4">"files"</span><span class="token2">:</span> <span class="token2">[</span><span class="token4">"app/Lib/function.php"</span><span class="token2">]</span><span class="token2">,</span> <span class="token6">//用于加载函数</span> 执行composer dumpautoload语句 使用某个类 use Mock<span class="token2">;</span>然后直接使用即可<span class="token2">;</span>没有使用命名空间的可以不用use<span class="token2">,</span>直接\Mock<span class="token2">:</span><span class="token2">:</span>title也是可以的 ``` ```