Laravel 5.1 中文文档里,中间件可以接受额外的自定义参数,例如,如果你的应用需要在执行给定 的 action 之前验证被授予指定“角色”的认证用户,可以创建一个 RoleMiddleware 来接收角 色名称作为额外参数: namespace App\Http\Middleware; use Closure; class RoleMiddleware { /** * 运行请求过滤器. vendor 包发布语言文件的默认目录做了移动,所有 vendor 包语言文件从 resources/lang/packages/{locale}/{namespace}移动到了 resources/lang/vendor/{namespace}/{locale}目录。例如,Acme/Anvil 包的 acme/anvil::foo 英语语言文件将会从 resources/lang/pack 另一个通用的例子是路由群组分配同一个 PHP 命名空间给多个控制器,可以在群组属性数 组中使用 namespace 参数来指定群组中控制器的命名空间: 本文档由 Laravel 学院(LaravelAcademy.org)提供 22 Route::group(['namespace' => 'Admin'], function(){ // Controllers Within0 码力 | 307 页 | 3.46 MB | 1 年前3
Laravel 5.2 中文文档命名空间给其下的多个控制器,可以在分 组属性数组中使用 namespace 来指定群组中所有控制器的公共命名空间: Route::group(['namespace' => 'Admin'], function(){ // 控制器在 "App\Http\Controllers\Admin" 命名空间下 Route::group(['namespace' => 'User'], function(){ 保护中排 除 webhook 处理器路由。 要实现这一目的,你需要在 VerifyCsrfToken 中间件中将要排除的 URL 添加 到 $except 属性: namespace App\Http\Middleware; use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier; app/Http/Middleware 目录下创建一个新的中间件类 OldMiddleware,在这 个中间件中,我们只允许提供的 age 大于 200 的访问路由,否则,我们将用户重定向到主 页: namespace App\Http\Middleware; use Closure; class OldMiddleware { /** * 返回请求过滤器0 码力 | 377 页 | 4.56 MB | 1 年前3
Laravel 5.6 中文文档OrderChannel::class); 最后,可以将频道的授权逻辑放到频道类的 join 方法。join 方法中的代码等同于之前位于频道授权闭包中的处理逻辑。当然,你还可以使用频道模 型绑定: namespace App\Broadcasting; use App\User; use App\Order; class OrderChannel { /** * Create htmlspecialchars 函数的默认行为保持一致。如果 你想要维持不进行双重编码的旧状,可以使用 Blade::withoutDoubleEncoding 方法: namespace App\Providers; use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; Bootstrap 3 链接,需要在 AppServiceProvider 的 boot 方法中调 用 Paginator::useBootstrapThree 方法: namespace App\Providers; use Illuminate\Pagination\Paginator; use Illuminate\Support\ServiceProvider;0 码力 | 377 页 | 14.56 MB | 1 年前3
Laravel 5.3 中文文档驱动,不 过,编写自己的驱动很简单,你可以通过自己的搜索实现扩展 Scout。 你可以简单通过添加 Searchable trait 到模型让模型变得可搜索: namespace App; use Laravel\Scout\Searchable; use Illuminate\Database\Eloquent\Model; class Post 方法。 User 模型必须使用新的 Illuminate\Notifications\Notifiabletrait 以便邮件重置链接可以正常 发送: namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; 仍然有替代方案,那就是在控制器构造函数中使用 Closure 来直接定义中间件。请注意,在使用 这个方案的时候,确保你所使用的 Laravel 版本高于 5.3.4: namespace App\Http\Controllers; use App\User; use Illuminate\Support\Facades\Auth; use App\Http\0 码力 | 691 页 | 9.37 MB | 1 年前3
Laravel 6.0 中文文档$this->release(5); }); } 而在 Laravel 6.0 中,该业务逻辑可以被提取到任务中间件中,从而 将你的任务 handle 方法从频率限制中解放出来: namespace App\Jobs\Middleware; use Illuminate\Support\Facades\Redis; 本文档由学院君提供 学院君致力于提供优质 Laravel 中文学习 服务容器是一个用于管理类依赖和执行依赖注入的强大工 具。依赖注入听上去很花哨,其实质是通过构造函数或者某些情况下 通过「setter」方法将类依赖注入到类中。 让我们看一个简单的例子: namespace App\Http\Controllers; use App\User; use App\Repositories\UserRepository; use App\Http\Controllers\Controller; 类型提示。在具体实践中,这是大多数对象从容器中解析的方式。 容器会自动为其解析类注入依赖,例如,你可以在控制器的构造函数 中为应用定义的仓库进行类型提示,该仓库会自动解析并注入该类: namespace App\Http\Controllers; use App\Users\Repository as UserRepository; class UserController extends0 码力 | 1442 页 | 14.66 MB | 1 年前3
Learning Laravelyour application up Bring the application out of maintenance mode app:name Set the application namespace auth:clear-resets Flush expired password reset tokens cache:clear Flush the application cache php App/Admin.php change class name to Admin and set namespace if you use models different. it should look like App\Admin.php namespace App; use Illuminate\Foundation\Auth\User as Authenticatable; how you use the other guard then "web" My App\Http\Controllers\Admin\LoginController namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use Illuminate\Foundation\0 码力 | 216 页 | 1.58 MB | 1 年前3
Laravel 5.0 Documentation
lives directly within the app folder, and, by default, is organized to the App namespace. This default namespace can be quickly changed using the new app:name Artisan command. Controllers, middleware free method of validating user input. Let's dig in and look at a sample FormRequest : namespace App\Http\Requests; class RegisterRequest extends FormRequest { public function rules() models and controllers simply lived in the "global" namespace. For a quicker migration, you can simply leave these classes in the global namespace in Laravel 5 as well. Copy the new .env.example file0 码力 | 242 页 | 1.44 MB | 1 年前3
The Laravel Handbook
table to an array named $fillable : protected $fillable = ['name']; Like this: namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; then store the dog into the database. Finally we redirect to the index route: 32 namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Dog; class NewDogFormController we add the name to an array named $fillable : protected $fillable = ['name']; namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model;0 码力 | 111 页 | 14.25 MB | 1 年前3
Laravel 3.2 Documentationentity which has "latitude" and "longitude" properties. It could look something like this: namespace Trackler\Entities; class Location { public $latitude; public $longitude; public "services" directory, we could create a "validators" folder with the following class: namespace Trackler\Services\Validators; use Trackler\Entities\Location; class Location_Validator { is a relational database, Redis, or the next storage hotness. Let's look at an example: namespace Trackler\Repositories; use Trackler\Entities\Location; class Location_Repository {0 码力 | 139 页 | 1.13 MB | 1 年前3
《Slides Dev Web》 09. Services Web
l’entreprise – plus de code pour manipuler la requête et générer la réponse – plus flexible, extensible (namespace) – valider requêtes depuis WDSL – nécessité d’un framework (ex: nuSOAP en PHP) • REST – hérité0 码力 | 6 页 | 47.90 KB | 1 年前3
共 10 条
- 1













