简体   繁体   English

如何在Laravel Auth系统上使用第二张表

[英]How use second Table on Laravel Auth System

What method should I use when capturing user-specific data from a table other than the table created by the laravel auth system? 从laravel auth系统创建的表以外的其他表中捕获特定于用户的数据时,应该使用哪种方法?

public function fonksiyonum($id)
{
$xler= Xmodel::WhereRaw('uye_id=? and durum=1',array($id))->get();

return view('profil',array('xler'=>$xler));
}


Route::get('/profil/{id}', array('as'=>'profil','uses'=>'xkontrol@fonksiyonum')->middleware('auth');

It happens this way, but I do not want to use get. 它以这种方式发生,但我不想使用get。 Just like in the auth system. 就像在auth系统中一样。

$id=Auth::user()->id 

to display the data in the other table to the logged-in user 向登录用户显示另一个表中的数据

Use this package: 使用此软件包:

Step 1: Install Through Composer 步骤1:通过Composer安装

composer require hesto/multi-auth 作曲者需要hesto / multi-auth

Step 2: Add the Service Provider (only for laravel lower than 5.5) 步骤2:添加服务提供商(仅适用于低于5.5的laravel)

You'll only want to use these package for local development, so you don't want to update the production providers array in config/app.php. 您只想将这些软件包用于本地开发,所以您不想更新config / app.php中的生产提供程序数组。 Instead, add the provider in app/Providers/AppServiceProvider.php, like so: 而是,将提供程序添加到app / Providers / AppServiceProvider.php中,如下所示:

      public function register()
 {
if ($this->app->environment() == 'local') {
    $this->app->register('Hesto\MultiAuth\MultiAuthServiceProvider');
}
  }

Step 3: Install Multi-Auth files in your project 步骤3:在专案中安装Multi-Auth档案

      php artisan multi-auth:install {singular_lowercase_name_of_guard} -f

// Examples php artisan multi-auth:install admin -f php artisan multi-auth:install employee -f php artisan multi-auth:install customer -f //示例php artisan multi-auth:安装管理员-f php artisan multi-auth:安装员工-f php artisan multi-auth:安装客户-f

Notice: If you don't provide -f flag, it will not work. 注意:如果不提供-f标志,它将不起作用。 It is a protection against accidental activation. 这是防止意外激活的保护措施。

Alternative: 选择:

If you want to install Multi-Auth files in a subdomain you must pass the option --domain. 如果要在子域中安装Multi-Auth文件,则必须传递--domain选项。

     php artisan multi-auth:install admin -f --domain
     php artisan multi-auth:install employee -f --domain
     php artisan multi-auth:install customer -f --domain

To be able to use this feature properly, you should add a key to your .env file: 为了能够正确使用此功能,应在.env文件中添加一个密钥:

     APP_DOMAIN=yourdomain.com

This will allow us to use it in the routes file, prefixing it with the domain feature from Laravel routing system. 这将使我们能够在路由文件中使用它,并在它前面加上Laravel路由系统的域功能。

Using it like so: ['domain' => '{guard}.' 像这样使用它:['domain'=>'{guard}。' . env('APP_DOMAIN')] env('APP_DOMAIN')]

Step 4: Migrate new model table 步骤4:迁移新模型表

    php artisan migrate

Step 5: Try it 步骤5:尝试

     Go to: http://project_url/GuardName/login

      Example: http://myproject.dev/customer/login

Options If you don't want model and migration use --model flag. 选项如果不想模型和迁移,请使用--model标志。

   php artisan multi-auth:install admin -f --model

If you don't want views use --views flag. 如果您不希望视图使用--views标志。

   php artisan multi-auth:install admin -f --views

If you don't want routes in your routes/web.php file, use --routes flag. 如果您不想在路由/web.php文件中使用路由,请使用--routes标志。

   php artisan multi-auth:install admin -f --routes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM