I'm completely new to Laravel. Can someone please guide me on how to set up a relationship between BorrowersRequest and Cars?
I have done it on Request Status which is also a foreign key of BorrowersRequest and it's totally working. Now I'm thinking why it isn't working with the cars.
model
class BorrowerRequest extends Model
{
public $timestamps = false;
public function requestStatus() {
return $this->belongsTo('App\RequestStatus');
}
public function requestedCar() {
return $this->belongsTo('App\Car');
}
}
this is in my borrowershistory Page. The request status works perfectly fine.
<tr>
<td><p class="text-muted"><small>Car to be Rented:</small></td>
<td><h6></h6></td>
</tr>
<tr>
<td><p class="text-muted"><small>Date of Return:</small></td>
<td><h6></h6></td>
</tr>
<tr>
<td><p class="text-muted"><small>Request Status:</small></td>
<td><h6><em></em>
</h6></td>
</tr>
here's my controller
public function viewBorrowManager()
{
$borrower_requests = BorrowerRequest::all();
$request_statuses = RequestStatus::all();
return view('/borrowmanager', [
'borrower_requests' => $borrower_requests,
'request_statuses' => $request_statuses
]);
}
and my in migration
public function up()
{
Schema::create('borrower_requests', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('car_id');
$table->timestamps();
$table->string('borrowers_name', 50);
$table->string('email')->unique();
$table->bigInteger('contact_number');
$table->date('return_date');
$table->unsignedBigInteger('request_status_id')->default(0);
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('car_id')->references('id')->on('cars');
$table->foreign('request_status_id')->references('id')->on('request_statuses');
});
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire