Create form for the tasks:
<div class="col-md-12 mb-3">
<label for="clientId" class="fw-bold">Client*</label>
<select name="clientId" class="form-control">
@foreach ($clients as $client)
<option value="{{$client->id}}">{{$client->client}}</option>
@endforeach
</select>
@error('clientId') <small class="text-danger">{{ $message }}</small> @enderror
</div>
<div class="col-md-12 mb-3">
<label for="Object1" class="fw-bold">Address*</label>
<select name="Object1" class="form-control">
@foreach ($clients as $client)
<option value="{{$client->id}}">{{$client->object}}</option>
@endforeach
</select>
@error('adressObject1') <small class="text-danger">{{ $message }}</small> @enderror
</div>
The idea is that I want in the address field to be shown only the address for the selected client and I also have trouble setting the foreign keys from the tasks table to the clients table. Here is the controller I made
<?php
namespace AppHttpControllers;
use AppHttpRequestsTasksFormRequest;
use AppModelsClients;
use AppModelsTasks;
use IlluminateHttpRequest;
class TasksController extends Controller
{
public function index(){
$tasks = Tasks::orderBy("created_at","desc")->paginate(10);
}
public function create(){
$clients = Clients::all();
return view("pages.tasks.create", compact("clients"));
}
public function store(TasksFormRequest $request){
$task = new Tasks();
$task->fill($request->all());
$task->save();
}
}
TasksFormRequest
<?php
namespace AppHttpRequests;
use IlluminateFoundationHttpFormRequest;
class TasksFormRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, IlluminateContractsValidationValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'dateOfMeasurement' => 'required|date',
'mk' => 'nullable|boolean',
'osv' => 'nullable|boolean',
'sh' => 'nullable|boolean',
'vent' => 'nullable|boolean',
'klim' => 'nullable|boolean',
'f-0' => 'nullable|boolean',
'z' => 'nullable|boolean',
'm' => 'nullable|boolean',
'izol' => 'nullable|boolean',
'dtz' => 'nullable|boolean',
'wayOfShowingDocumentation'=> 'required|string',
'certifaciteNumber'=> 'required|string',
'nextMeasurment'=> 'nullable|date',
'mkNext' => 'nullable|boolean',
'osvNext' => 'nullable|boolean',
'shNext' => 'nullable|boolean',
'ventNext' => 'nullable|boolean',
'klimNext' => 'nullable|boolean',
'f-0Next' => 'nullable|boolean',
'zNext' => 'nullable|boolean',
'mNext' => 'nullable|boolean',
'izolNext' => 'nullable|boolean',
'dtzNext' => 'nullable|boolean',
];
}
}
And the migration file:
<?php
use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('tasks', function (Blueprint $table) {
Schema::create('tasks', function (Blueprint $table) {
$table->id();
$table->date('dateOfMeasurement');
$table->boolean('mk')->nullable();
$table->boolean('osv')->nullable();
$table->boolean('sh')->nullable();
$table->boolean('vent')->nullable();
$table->boolean('klim')->nullable();
$table->boolean('f0')->nullable();
$table->boolean('z')->nullable();
$table->boolean('m')->nullable();
$table->boolean('izol')->nullable();
$table->boolean('dtz')->nullable();
$table->string('wayOfShowingDocumentation');
$table->string('certificateNumber');
$table->date('certificateDate');
$table->date('nextMeasurement');
$table->boolean('mkNext')->nullable();
$table->boolean('osvNext')->nullable();
$table->boolean('shNext')->nullable();
$table->boolean('ventNext')->nullable();
$table->boolean('klimNext')->nullable();
$table->boolean('f0Next')->nullable();
$table->boolean('zNext')->nullable();
$table->boolean('mNext')->nullable();
$table->boolean('izolNext')->nullable();
$table->boolean('dtzNext')->nullable();
$table->timestamps();
});
});}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tasks');
}
};
Thank you in advance for the help!
I tried with
<option value="{{$client->id}}">{{$client->object}}</option>
to show the specific address for client but it lists all of the addresses