预订与管理 [英] Booking and Management

查看:57
本文介绍了预订与管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还是laravel的初学者...

I am still a beginner in laravel...

摩托车保留用于6/09/2019的培训,从8:0010:00(摩托车000001和以前的Alain的编号).

The motorbike is reserved for a training on 6/09/2019, from 8:00 to 10:00 (number of the motorbike 000001 & former Alain).

然后,将摩托车000001始终保留在06/09/2019上,对于前一个Alain,从12:0014:00.

Then, the motorbike 000001 is reserved always on 06/09/2019, from 12:00 to 14:00 for the former Alain.

我有一条错误消息=> duplicate//(第一个问题)

I have an error message => duplicate // (first problem)

07/09/2019revision早晨,从08:0012:00,使用摩托车000001

On 07/09/2019, revision the morning, from 08:00 to 12:00 with the motorbike 000001

如果要在07/09/2019training上预订,请使用摩托车00000108:0012:00.它阻止(重复)好吧!

If, I want to book on 07/09/2019 a training, from 08:00 to 12:00 with the motorbike 000001. It blocks (duplicate) OK , Well !

但是,我总是使用摩托车00000107/09/201918:00上输入07/09/2019training.它也会阻止(重复),这是一个问题(第二个问题)

However, I enter always on 07/09/2019 a training, from 16:00 to 18:00 with the motorbike 000001. It blocks (duplicate) also, it's a problem (second problem)

还有一个问题,如何管理培训师的管理?

Yet a problem, how to manage the management of trainers ???

我不能有两倍于同一位老师同时教一个行为……(第三个问题).

I can not have 2 times the same instructors who teach a conduct at the same time ... (third problem).

编辑05/09/2019

我现在的代码

public function store(Request $request)
    {
        $request->validate([
                'date_seance' => 'required',
                'hour_start' => 'required',
                'hour_end' => 'required',
                'fk_motorbike' => 'required',
                'fk_former' => 'required'


        ]);


       $date_start = $request->get('date_seance'); 
       $hour_start = $request->get('hour_start'); 
       $hour_end = $request->get('hour_end'); 
       $fk_motorbike = $request->get('fk_motorbike');
       $fk_former = $request->get('fk_former');


        $conflictTraining = Training::where('fk_motorbike', $fk_motorbike)  // Bike is conflicted?
        ->whereDate('date_seance', "=" , $date_start)  // Same day?
        ->where('hour_start', "<=" , $request->get('hour_start'))  // Within same time slot?
        ->where('hour_end', ">=" , $request->get('hour_end'))
        ->where('fk_former', $request->get('fk_former')) // Same trainer as requested?
        ->where('fk_motorbike', $request->get('fk_motorbike')) 
        ->first();  

        $conflictRevision = Revision::where('fk_motorbike', $fk_motorbike)
        ->whereDate('date_revision_start', "<=" , $date_start)
        ->whereDate('date_revision_end', ">=", $date_start)
        ->where('hour_start', "<=" , $request->get('hour_start'))  
        ->where('hour_end', ">=" , $request->get('hour_end'))
        ->first();  

        if(isset($conflictTraining) || isset($conflictRevision)){
            return redirect()->route('trainings.index')
                 ->with('error', 'Duplicate ');
        }

        else{
            Training::create($request->all());
                return redirect()->route('trainings.index')
                    ->with('success', 'Add');
    }



    }

我仍然需要通过摩托车号码来检查教练的姓名.

我添加了模型Former,我添加了模型Former,但是我不知道如何进行检查?

I added the model Former, I added the model Former, but I don't understand how I can do checkings ?

我有2个问题:

1)前者不能在两个小时内骑两辆不同的摩托车参加两次聚会

1)the former can not have 2 seances the same hour with two different motorbikes

2)摩托车在同一小时内不能有2次亮相

2)the motorbike can not have 2 seances the same hours

我正在尝试检查前者:

但是,我收到一条错误消息:SQLSTATE[42S22]: Column not found: 1054 Champ 'fk_former' inconnu dans where clause

However, I have an error message: SQLSTATE[42S22]: Column not found: 1054 Champ 'fk_former' inconnu dans where clause

$conflictFormer = Former::where('fk_former', $fk_former)  
        ->where('name',  $request->get('name')) 
        ->first();  


        if(isset($conflictTraining) || isset($conflictRevision) || isset($conflictFormer) ){
            return redirect()->route('trainings.index')
                 ->with('error', 'Duplicate ');
        }

在此先感谢您的帮助和解释.

Thank you in advance, for your help and your explanations.

推荐答案

您可以使用类似的逻辑来检查Training,Trainer和Revision的重复项.

You can use similar logic to check for duplicates for Training, Trainer, and Revision.

培训

由于培训是在一天中进行的,因此您可以查看是否在同一天,并且在与用户从表单中请求的时间范围相同的时间范围内进行培训.您还可以在同一查询中,检查所请求的教练是否正在该培训中,以及该摩托车是否是计划进行的培训:

Because training is on one day, you can see if there is a training on the same day, and within the same time frame as that requested by the user from the form. You can also, in the same query, check if the requested trainer is in that training, and if that particular motorbike is the one scheduled for the training:

 $conflictTraining = Training::where('fk_motorbike', $fk_motorbike)  // Bike is conflicted?
        ->whereDate('date_seance', "=" , $date_seance)  // Same day?
        ->where('hour_start', "<=" , $request->get('hour_start'))  // Within same time slot?
        ->where('hour_end', ">=" , $request->get('hour_end'))
        ->where('fk_former', $request->get('fk_former')) // Same trainer as requested?
        ->first();

修订

这会变得更加复杂,因为可能有很多天.如果您想知道seance表格要求的一天中的任何时间自行车是否正在修订中,那么上面的代码将可以正常工作.但是,如果您想看看自行车是否可以在下午进行训练,而早上才进行修改,那就不一样了.

This gets a little more complex because there are potentially multiple days. If you want to know if a bike is in revision at any time during the day requested by the form seance, your code above will work fine. However, if you want to look to see if maybe the bike can be in training in the afternoon when it is only in revision in the morning, that is different.

因为我们正在寻找特定日期的特定时间,该日期可能是修订的那几天的开始,中间或结束,所以我认为将其做得大一点是最容易解释的-您可以在以后重构并收紧(如果可行).首先,我将以与您的代码相同的方式获取与当天冲突的修订版本:

Because we are looking for a specific time on a specific day which may be at the beginning, middle, or end of that span of days for the revision, I think it would be easiest to explain by making this a bit big - you can refactor and tighten later if this works. First, I would grab the revision that conflicts with the day the same way as in your code:

$conflictRevision = Revision::where('fk_motorbike', $fk_motorbike)
        ->whereDate('date_revision_start', "<=" , $date_start)
        ->whereDate('date_revision_end', ">=", $date_start)
        ->first();

现在您所拥有的修订版与您的用户的日子相符,然后您可以查看该修订版中是否有用户要求的特定培训时间.困难的部分,您需要在工作流逻辑中确定的一点是,您是否假设如果进行了几个小时的修订,它总是只是修订的一天?如果是这样,您可以在培训中增加类似的条款来补充上面的查询:

Now that you have the revision which matches your user's day, you can then look to see if the specific hours requested by the user for training are in this revision. The hard part, and the point which you need to decide in your workflow logic is that do you assume that if it is in revision for a few hours, that it will always be just one day in revision? If so, you can augment the query above with similar clauses as your training:

$conflictRevision = Revision::where('fk_motorbike', $fk_motorbike)
        ->whereDate('date_revision_start', "<=" , $date_start)
        ->whereDate('date_revision_end', ">=", $date_start)
        ->where('hour_start', "<=" , $request->get('hour_start'))  
        ->where('hour_end', ">=" , $request->get('hour_end'))
        ->first();

如果用户可以偷懒"地输入一个修订版本,可能在8:00-11:00之间输入,但是您允许多天,则该版本将不会每次都有效,并且不会从逻辑上讲是没有道理的(如果您输入1月24日至1月30日的8:00-11:00,那么车库是哪一天?).如果您允许多天且仅几个小时,我不确定是否可以可靠地对此检查进行编码.没有简便的方法来检查小时数是否在seance的特定日期,如果开始和结束之间有多天.结尾.

If the user can enter a revision 'lazily' where it might be for 8:00-11:00, but you allow multiple days, this won't work every time, and doesn't make sense from a logic point of view (if you enter 8:00-11:00 for Jan 24-Jan 30, which day is it in the garage?). I'm not sure you can reliably code this check for it if you allow for multiple days AND only for a few hours. There is no easy way to check if the hours are on the specific day of seance if there are multiple days in between start & end.

如果可能的话,当每小时进行一次修订时,将用户限制在一天之内可能会变得更容易.

If possible, when a revision is hourly, it would probably make life easier to limit the user to one day for the revision.

这篇关于预订与管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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