从租赁表中租赁可用的汽车 [英] Rent available cars from rentals table

查看:56
本文介绍了从租赁表中租赁可用的汽车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的桌子上有租金

id| user_id| car_id | starting_date | ending_date

这是汽车桌子

id | name

我不知道该怎么处理.我有N辆车,我只想退还特定日期的可用车.

I don't know how to habndle the situation.. I have N cars, and I want to return only available cars for specific dates.

例如,我想在此期间租一辆车: 20.02.2018-23.02.2018

For example I want to rent a car on this period: 20.02.2018 - 23.02.2018

但是我不知道如何使用Laravel来检查每种情况下的汽车是否可用.

But I don't know how to check every case to see if a car is available in that period using Laravel.

推荐答案

使用如果没有关系,请在Car模型中定义它:

If you don't have the relationship, define it in the Car model:

public function rentals()
{
    return $this->hasMany(Rental::class);
}

这篇关于从租赁表中租赁可用的汽车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆