Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Laravel中注册后的用户权限_Php_Laravel - Fatal编程技术网

Php 在Laravel中注册后的用户权限

Php 在Laravel中注册后的用户权限,php,laravel,Php,Laravel,在我的数据库里我有这个 Schema::create('users', function (Blueprint $table) { $table->id(); $table->string('name'); $table->string('email')->unique(); $table->string('username')->unique();

在我的数据库里我有这个

Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->string('username')->unique();
            $table->string('admin')->nullable();
            $table->string('usertype')->nullable();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
这意味着在我的表格中我有这个

<select name="usertype">
                      <option>Select Usertype</option>

                      <option value="1">Landlord</option>
                      <option value="2">Agent</option>
                      <option value="3">Tenant</option>

                    </select>
当房东用户注册时,会将他们带到
http://127.0.0.1:8000/dashboard

我如何使每个用户的内容不同,即 1.我希望房东能够只是增加财产 2.我希望承租人能够编辑配置文件,查看他们购买的财产。 3.我希望代理能够像房东一样增加财产


如何实现这一点?

您可以使用Laravel策略。示例如果您有一个PropertyController,则可以使用以下方法创建PropertyPolicy:

/**
     * Determine whether the user can create models.
     *
     * @param  \App\User  $user
     * @return mixed
     */
    public function create(User $user)
    {
        return $user->usertype == 'Landlord';
    }
在视图中,您可以执行以下操作:

@can('create', $property)
    // link to create property
@endcan 

了解有关Laravel策略的更多信息,请访问您可以使用Laravel策略。示例如果您有一个PropertyController,则可以使用以下方法创建PropertyPolicy:

/**
     * Determine whether the user can create models.
     *
     * @param  \App\User  $user
     * @return mixed
     */
    public function create(User $user)
    {
        return $user->usertype == 'Landlord';
    }
在视图中,您可以执行以下操作:

@can('create', $property)
    // link to create property
@endcan 

了解有关Laravel策略的更多信息
at

我在视图中这样做了
@can('create',$apartmentType)
  • @endcan``和apartmentTypeController这样做了
    公共函数创建(User$User){$apartmenttype=apartmenttype::find($id);返回$user->usertype=='1';}```我收到了这个错误`未定义变量:apartmentType``它的工作方式是,控制器处理通常的CRUD功能。策略允许您为注册在
    AuthServiceProvider
    中的每个模型/资源创建授权逻辑,然后您可以使用刀片视图指令(如
    can
    )进行验证你应该仔细阅读这些文档来完全理解它是如何工作的。我是在查看
    @can('create',$apartmentType)
  • @endcan``中这样做的,而apartmentTypeController是在创建公共函数(User$User)时这样做的{$apartmenttype=apartmenttype::find($id);返回$user->usertype=='1';}```我收到了这个错误`未定义变量:apartmentType``它的工作方式是,控制器处理通常的CRUD功能。策略允许您为注册在
    AuthServiceProvider
    中的每个模型/资源创建授权逻辑,然后您可以使用刀片视图指令(如
    can
    )进行验证你应该仔细阅读这些文档,以充分了解其工作原理。