Renzo
Table Data Visibility
Make it worked! 🙂
->modifyQueryUsing(function (Builder $query) {
$user = Auth::user();
// If the user is a Vendor, modify the query to only show their assigned workorders.
if($user->hasRole('Vendor')) {
$query->where('user_id', $user->id);
}
return $query;
})
4 replies
Table Data Visibility
Here's my schema for User and Workorder for reference:
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->boolean('user_preferred')->nullable();
$table->rememberToken();
$table->timestamps();
});
Schema::create('workorders', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('customer_id')->nullable();
$table->unsignedBigInteger('user_id')->nullable();
$table->string('wo_number')->nullable();
$table->string('wo_problem')->nullable();
$table->string('wo_problem_type')->nullable();
$table->string('wo_description')->nullable();
$table->string('wo_customer_po')->nullable();
$table->string('wo_asset')->nullable();
$table->string('wo_priority')->nullable();
$table->string('wo_trade')->nullable();
$table->string('wo_category')->nullable();
$table->string('wo_tech_nte')->nullable();
$table->string('wo_schedule')->nullable();
$table->string('wo_status')->nullable();
$table->timestamps();
});
4 replies