reivaj86 / chef-auth
此包的最新版本(dev-master)没有可用的许可证信息。
dev-master
2015-08-17 12:49 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-09-28 17:49:15 UTC
README
##为Laravel 5实现“Chef-Captcha”登录的配方、成分和分类登录
这是一个强大的包,用于实现简单但有效的登录授权步骤。用此包替换正常的Word Captcha系统。它将为用户提供一种非常动态和互动的登录方式,并增加安全性。
安装
通过Composer安装此包。
{ "require": { "reivaj86/chef-auth": "dev-master" } }
Run
$ composer update
将包ChefAuthServiceProvider添加到您的应用服务提供者在config/app.php
中
'providers' => [ 'Illuminate\Foundation\Providers\ArtisanServiceProvider', 'Illuminate\Auth\AuthServiceProvider', ... 'Reivaj86\ChefAuth\ChefAuthServiceProvider', ],
将包迁移和配置文件发布到您的应用。
$ php artisan vendor:publish --provider="Vendor/Reivaj86/ChefAuth/ChefAuthServiceProvider" --tag="config"
$ php artisan vendor:publish --provider="Vendor/Reivaj86/ChefAuth/ChefAuthServiceProvider" --tag="migrations"
运行迁移。
$ php artisan migrate
配置文件 --- chef-auth.php
您可以更改模型连接、slug分隔符,还有一个实用的可烹饪功能。查看配置文件以获取更多信息。
用法
首先,在您的User
模型中包含HasIngredient
特性和实现HasIngredientContract
。
use Reivaj86\ChefAuth\Contracts\HasIngredientContract; use Reivaj86\ChefAuthTraits\HasIngredient; class Recipe extends Model implements HasIngredientContract { use HasIngredient;
您就可以开始了。您可以创建第一个配方、成分和分类数据库。
use Reivaj86\ChefAuth\Models\Recipe; $recipe = Recipe::create([ 'name' => 'Carbonara', 'slug' => 'carbonara', 'img' => 'assets/imgs/carbonara.png' 'description' => 'Delicious italian pasta dish' // optional ]);
然后您可以创建第一个成分并将其附加到一个配方上。
use Reivaj86\ChefAuth\Models\Ingredient; use Reivaj86\ChefAuth\Models\Recipe; $ingredient = Ingredient::create([ 'name' => 'Eggs', 'slug' => 'eggs', 'description' => '' // optional ]); $recipe = Recipe::find($id)->attachIngredient($ingredient); // Can pass whole object, or only its id
您可以检查当前配方是否有必需的成分。
if ($recipe->cooks('eggs')) // you can pass an id or slug { return 'eggs'; // Or an image (return recipe->img;) }
您也可以这样做
if ($recipe->cooksEggs()) { return 'eggs'; }
当然,还有检查多个成分的方法
if ($recipe->cooks('eggs|cheese')) // or $recipe->cooks('eggs, cheese') and also $recipe->cooks(['eggs', 'cheese']) { // if recipe has at least one ingredient } if ($recipe->cooks('eggs|cheese', 'All')) // or $user->cooks('eggs, cheese', 'All') and also $recipe->cooks(['eggs', 'cheese'], 'All') { // if recipe has all ingredients }
当您创建成分时,还有一个可选的参数img
。默认设置为null
,但您可以覆盖它,然后您可以这样做
if (!$ingredient->img = null) { // code }
让我们来谈谈类别。您可以给成分或特定的成分(当然,也可以取消附加)附加一个类别。
use Reivaj86\ChefAuth\Models\Category; use Reivaj86\ChefAuth\Models\Ingredient; $category = Category::create([ 'name' => 'Dairy', 'slug' => 'dairy', 'description' => 'Dairy products' // optional ]); Ingredient::find($id)->attachCategory($category); if ($ingredient->is('dairy') // you can pass an id or slug { return 'Is a Dairy Product!'; }
您可以使用与成分相同的方式检查多个类别。
这个条件检查当前配方是否是提供的成分的所有者。如果不是,它将在成分类别中查找我们之前创建的行。
if ($ingredient->steamed('dairy', $product, false)) // now owner check is disabled { $product->save(); }