any help?
Aug 22, 2020
5
Level 3
View relationships data
Hello everyone,
- Every User has a subscription.
- Subscription have the subscription information beside the plan_id and user_id.
- The plan contains many features.
- Every feature has a file.
The plan with features added using the control panel
Then user in the website home page can choose one of these plans.
After the user having a subscription the admin can send a file for each feature to the user.
Here in these images, I am trying to show the status of every feature is it delivered or not. But when upload any file to a specific feature for the first user the second user feature status affected by this upload on the first user.
Second user page

First user page without any uploaded files in database

The status displayed by the following code
Controller
public function show($id)
{
$user = User::findOrFail($id);
return view('user_services.show', compact('user'));
}
Blade
@foreach ($user->subscription->custom_plan->custom_services as $index => $service)
<tr>
<td>{{ $loop->iteration }}.</td>
<td>{{$service->name}} // {{$service->id}}</td>
<td>{{$service->pivot->quantity}}</td>
<td>
@if($service->custom_files->isNotEmpty())
@foreach ($service->custom_files as $file)
@if ($file->user_id == $user->id)
@if ($file->custom_service_id == $service->id)
<span class="badge bg-success">Delivred </span>
@endif
@endif
@endforeach
@else
<span class="badge bg-warning">No files </span>
@endif
</tr>
@endforeach
Subscription
Schema::create('subscriptions', function (Blueprint $table) {
$table->id();
$table->foreignId('plan_id')->nullable()->constrained();
$table->foreignId('custom_plan_id')->nullable()->constrained();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->string('plan_type');
$table->tinyInteger('status')->default(0);
$table->timestamp('ends_at')->nullable();
$table->timestamps();
});
Plan
Schema::create('plans', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->decimal('price', 8, 2);
$table->tinyInteger('classification')->index();
$table->timestamps();
});
Service
Schema::create('services', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('plan_id');
$table->string('name');
$table->integer('quantity');
$table->string('icon');
$table->timestamps();
});
File
Schema::create('files', function (Blueprint $table) {
$table->id();
$table->foreignId('service_id')->constrained('services')->onDelete('cascade');
$table->foreignId('user_id')->constrained('users')->onDelete('cascade');
$table->string('file_name');
$table->timestamps();
});
User Default migration file
I really don't know where the problem is
Please or to participate in this conversation.