david2000

david2000

Member Since 2 Months Ago

Experience Points
2,740
Total
Experience

2,260 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
2,740 XP
Oct
18
3 weeks ago
Activity icon

Started a new Conversation Adapt My Code By Adding Start_time And Stop_time In My Booking

I have to add in my TrainingController two variables => start_time & stop_time.

In my old code I had this:

 $conflictTraining = Training::where('fk_motorbike', $request->get('fk_motorbike')) 
 ->whereDate('date_seance', "=" , Carbon::parse($date_seance)) 
 ->where('hour_start', "<=" , $request->get('hour_start')) 
 ->where('hour_end', ">=" , $request->get('hour_end'))
 ->where('fk_former', $request->get('fk_former'))
 ->first();

My problem is that I would like to do a checking. How Can I avoid a duplicate for my request $conflictTraining with start_time & stop_time..

Here is my code for now:

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

        
        $start_time = Carbon::createFromFormat('d-m-Y H:s', $date_seance . ' ' . $hour_start);
        $stop_time = Carbon::createFromFormat('d-m-Y H:s', $date_seance . ' ' . $hour_end);

    
        $conflictTraining = Training::where('fk_motorbike', $request->fk_motorbike)
            ->where('start_time', "<=", $start_time)
            ->where('stop_time', ">=", $stop_time)
            ->first();
 
 
        if (isset($conflictTraining)) {
            return redirect()->route('trainings.index')
                ->with('error', 'training duplicate');
        }
 
      
        $data = $request->all();
        $data['start_time'] = $start_time;
        $data['stop_time'] = $stop_time;
        Training::create($data);
        return redirect()->route('trainings.index')
            ->with('success', 'Add');
 
 
    }

I thank you in advance for your help.

Activity icon

Replied to Checking Date Payment For My Function Update()

I have found my erreur it was the cache pfffffff... :-(

php artisan config:cache
php artisan cache:clear
php artisan view:clear

It woks now !

Thank you for your help.

Activity icon

Replied to Checking Date Payment For My Function Update()

I explain ... If the date_payment is 10/10/2019. Then I enter the date_seance 12/10/2019. Here, there is no problem.

Now, if I change the value 12/10/2019 by 01/01/2018 there must be a message that says the date_seance must be later the date_payment.

I don't know how to do this check in my update() ... :-(

Oct
17
3 weeks ago
Activity icon

Replied to Checking Date Payment For My Function Update()

Hekki @nakov ,

Concerning the dump below:

dd($request->get('fk_student'), $date_seance);

For the test

Training::find($id); 

I have this:

My dateFormat is null ???

In the routes file, I have this:

Route::resource('/trainings', 'TrainingController');
Activity icon

Replied to Checking Date Payment For My Function Update()

@nakov : I tried this, but my checking does not work. I think it's a problem with ID? Is my "if" condition is placed correctly?

public function update(Request $request, $id)

    {

        $request->validate([

                'date_seance' => 'required',

                'hour_start' => 'required',

                'hour_end' => 'required',

                'fk_motorbike' => 'required',

                'fk_former' => 'required',

                'fk_student' => 'required'

        ]);



       $date_seance = $request->get('date_seance');

       $hour_start = $request->get('hour_start');

       $hour_end = $request->get('hour_end');

       $fk_motorbike = $request->get('fk_motorbike');

       $fk_student = $request->get('fk_student');

       $fk_former = $request->get('fk_former');

       $fk_typeseance = $request->get('fk_typeseance');



       $datePayment = Payment::where('fk_student', $request->get('fk_student'))
->whereDate('date_payment', ">" , $date_seance)
->first();

if(isset($datePayment)){
    return redirect()->route('trainings.index')
    ->with('error', 'There is a problem with the payment date! ');
}

else{
   $trainings = Training::find($id);
   $trainings->date_seance = $request->get('date_seance');
   ...
   $trainings->save();
   return redirect()->route('trainings.index')
    ->with('success', 'Update!')->withInput();
   }

    }

Oct
16
3 weeks ago
Activity icon

Replied to Function Rules(), Store() And Update() In Laravel

Hello,

I have tried the regle "ignore" , but I think that I have a problem with the syntax ?

'matriculation' => 'required|string|max:15|min:6|unique:motorbikes->ignore($matriculation->id)' 

Activity icon

Replied to Checking Date Payment For My Function Update()

Hello @nakov,

Here is my code... My condition between my date_seance and date_payment is ok for the method store(), however I am stuck in my method update.

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


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



        $datePayment = Payment::where('fk_student', $request->get('fk_student'))
        ->whereDate('date_payment', ">" , $date_seance)
        ->first();

        if(isset($datePayment)){
            return redirect()->route('trainings.index')
            ->with('error', 'There is a problem with the payment date! ');
        }
        else{
            Training::create($request->all());
                return redirect()->route('trainings.index')
                    ->with('success', 'Add');
        }

       

    }

   
    public function edit($id)
    {
        $trainings = Training::find($id);
        $students = Student::all();
        $formers = Former::all();
        $motorbikes = Motorbike::all();
        $payments = Payment::all();

        return view('admin.trainings.edit', compact('trainings', 'students', 'formers', 'motorbikes', 'payments'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $request->validate([
                'date_seance' => 'required',
                'hour_start' => 'required',
                'hour_end' => 'required',
                'fk_motorbike' => 'required',
                'fk_former' => 'required',
                'fk_student' => 'required'
        ]);

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



        $datePayment = Payment::where('fk_student', $request->get('fk_student'))
        ->whereDate('date_payment', ">" , $date_seance)
        ->first();



        $trainings = Training::find($id);
        $trainings->date_seance = $request->get('date_seance');
        $trainings->hour_start = $request->get('hour_start');
        $trainings->hour_end = $request->get('hour_end');
        $trainings->fk_motorbike = $request->get('fk_motorbike');
        $trainings->fk_former = $request->get('fk_former');
        $trainings->fk_student = $request->get('fk_student');
        $trainings->save();
        return redirect()->route('trainings.index')
            ->with('success', 'Update!')->withInput();
     
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $trainings = Training::find($id);
        $trainings->delete();
        return redirect()->route('trainings.index')
                    ->with('error', 'Delete! ');
    }


File Edit

<form class="panel-body" action="{{route('trainings.update',$trainings->id)}}" method="POST">
              <input name="_method" type="hidden" value="PATCH">
              @csrf
                <fieldset class="form-group {{ $errors->has('date_seance') ? 'has-error' : '' }}">
                <label for="form-group-input-1">Date séance</label>
                <input type="date" name="date_seance" id="date_seance" class="form-control" required="required" value="{{$trainings->date_seance->format('Y-m-d')}}">
                {!! $errors->first('date_seance', '<span class="help-block">:message</span>') !!}
          </fieldset>

          <fieldset class="form-group {{ $errors->has('hour_start') ? 'has-error' : '' }}">
                <label for="company-content">Hour start</label>
                  <select class="form-control" name="hour_start">
                      <option value="07:00" @if (old('hour_start') == '07:00') selected="selected" @elseif($trainings->hour_start == '07:00') selected="selected" @endif>07:00</option>
                      <option value="10:00" @if (old('hour_start') == '10:00') selected="selected" @elseif($trainings->hour_start == '10:00') selected="selected" @endif>10:00</option>
                      <option value="13:00" @if (old('hour_start') == '13:00') selected="selected" @elseif($trainings->hour_start == '13:00') selected="selected" @endif>13:00</option>
                      <option value="16:00" @if (old('hour_start') == '16:00') selected="selected" @elseif($trainings->hour_start == '16:00') selected="selected" @endif>16:00</option>
                  </select> 
              </fieldset>

          <fieldset class="form-group {{ $errors->has('hour_end') ? 'has-error' : '' }}">
                <label for="company-content">Hour end</label>
                  <select class="form-control" name="hour_end">
                      <option value="09:00" @if (old('hour_end') == '09:00') selected="selected" @elseif($trainings->hour_end == '09:00') selected="selected" @endif>09:00</option>
                      <option value="12:00" @if (old('hour_end') == '12:00') selected="selected" @elseif($trainings->hour_end == '12:00') selected="selected" @endif>12:00</option>
                      <option value="15:00" @if (old('hour_end') == '15:00') selected="selected" @elseif($trainings->hour_end == '15:00') selected="selected" @endif>15:00</option>
                      <option value="18:00" @if (old('hour_end') == '18:00') selected="selected" @elseif($trainings->hour_end == '18:00') selected="selected" @endif>18:00</option>
                  </select> 
              </fieldset>

            <fieldset class="form-group {{ $errors->has('fk_motorbike') ? 'has-error' : '' }}">
               <label for="company-content">Number motorbike </label>
              <select name="fk_motorbike" id="" class="form-control">
                  @foreach($motorbikes as $motorbike)
                    <option value="{{$motorbike->id}}" @if($trainings->fk_motorbike == $motorbike->id) selected @endif > {{$motorbike->number_motorbike}}  
                    </option>
                @endforeach
              </select>
            </fieldset>

            <fieldset class="form-group {{ $errors->has('fk_former') ? 'has-error' : '' }}">
               <label for="company-content">Former </label>
              <select name="fk_former" id="" class="form-control">
                  @foreach($formers as $former)
                    <option value="{{$former->id}}" @if($trainings->fk_former == $former->id) selected @endif >{{$former->name}} 
                    </option>
                @endforeach
              </select>
            </fieldset>

             <fieldset class="form-group {{ $errors->has('fk_student') ? 'has-error' : '' }}">
               <label for="company-content">Name student </label>
              <select name="fk_student" id="" class="form-control">
                  @foreach($students as $student)
                    <option value="{{$student->id}}" @if($trainings->fk_student == $student->id) selected @endif >{{$student->name}} {{$student->firstname}}  
                    </option>
                @endforeach
              </select>
            </fieldset>
Oct
15
4 weeks ago
Activity icon

Started a new Conversation Function Rules(), Store() And Update() In Laravel

I am trying to change the value of my fields matriculation and number_motorbke but visibly the values exist already. I have a problem of validation.

In my function rules() I have this: (no problem)

public function rules()
    {
        return [
            'matriculation' => 'required|string|max:15|min:6|unique:motorbikes,matriculation',
            'number_motorbike' => 'required|string|max:6|min:6|unique:motorbikes,number_motorbike'
        ];
    }

In my function store() I have this: (no problem)

ublic function store(MotoRequest $request)
    {
        

       $exists = Motorbike::where('matriculation', $request->get('matriculation'))->where('number_motorbike', $request->get('number_motorbike'))->count();

       if (!$exists){
            Motorbike::create($request->all());
            return redirect()->route('motorbikes.index')
                ->with('success', 'new data created successfully');
        }

        else{
            return redirect()->route('motorbikes.index')
                ->with('error', 'duplicate');

        }   

    }

My problem is in my function update(), when I want for example change only the value of my field matriculation , I get an error message "The number motorbike has already been taken."

Here my function update() but I think the problem is in my function rules()?

public function edit($id)
    {
        $motorbikes = Motorbike::find($id);
        return view('admin.motorbikes.edit', compact('motorbikes'));
    }

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(MotoRequest $request, $id)
{
    
    $motorbikes = Motorbike::find($id);
    $motorbikes->matriculation = $request->get('matriculation');
    $motorbikes->number_motorbike = $request->get('number_motorbike');
    $motorbikes->save();
    return redirect()->route('motorbikes.index')
        ->with('success', 'Update!')->withInput();
}
Activity icon

Replied to Checking Date Payment For My Function Update()

Here is an example with 2 screenshot.

In my listing payment I have a field date_payment with the value 15/10/2019.

Then, in my listing training I have a field date_seance with the value 25/10/2019

If the user wants to change the value of the date_seance by 10/10/2019, the date_seance is smaller that the date_payment. I want to have an error message.

My method store() is OK

$datePayment = Payment::where('fk_student', $request->get('fk_student'))
->whereDate('date_payment', ">" , $date_seance)
->first();

 if(isset($datePayment)){
            return redirect()->route('trainings.index')
                ->with('error', 'There is a problem with the payment date! ');
}

I am stuck for the method update() ... :-(

Oct
14
4 weeks ago
Activity icon

Replied to Checking Date Payment For My Function Update()

In the store I retrieve the date => "2019-10-25".

In my update, I want to change the date "2019-10-25", I retrieve "2019-10-26".

Activity icon

Started a new Conversation Checking Date Payment For My Function Update()

I have to do a checking between the payment date and the seance date in my method store(). The method store() is OK!

$datePayment = Payment::where('fk_student', $request->get('fk_student'))
->whereDate('date_payment', ">" , $date_seance)
->first();

 if(isset($datePayment)){
            return redirect()->route('trainings.index')
                ->with('error', 'There is a problem with the payment date! ');
}

My problem is in my function update(), I am stuck. When, I change the value of the date_seance, there is no checking.

$datePayment = Payment::where('fk_student', $request->get('fk_student'))
->whereDate('date_payment', ">" , $date_seance)
->first();

if(isset($datePayment)){
    return redirect()->route('trainings.index')
    ->with('error', 'There is a problem with the payment date! ');
}

else{
   $trainings = Training::find($id);
   $trainings->date_seance = $request->get('date_seance');
   ...
   $trainings->save();
   return redirect()->route('trainings.index')
    ->with('success', 'Update!')->withInput();
   }

I know my problem is here in the condition:

if(isset($datePayment)){
        return redirect()->route('trainings.index')
        ->with('error', 'There is a problem with the payment date! ');
    }

Thank you for your help.

Oct
12
1 month ago
Activity icon

Started a new Conversation Form For The Hours

I have 2 fields which are beginHour and endHour in format dateTime.

$table->dateTime('beginHour');
$table->dateTime('endHour');

In my form HTML, is possible to encode the hours ??

<div class="form-group{{ $errors->has('beginHour') ? 'has-error' : '' }}">
                <label for="form-group-input-1">Hour start</label>
                <input type="datetime" name="beginHour" id="beginHour" class="form-control" required="required" value="{{ old('beginHour')}}"/>
                {!! $errors->first('beginHour', '<span class="help-block">:message</span>') !!}
          </div>
Oct
11
1 month ago
Activity icon

Started a new Conversation Adapt My Method Store () For Update ()

Here is my method store(). there is a check on the ceiling not to be reached.

For information, the code is correct for the method show().

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


       $date_seance = $request->get('date_seance'); 
       $hour_start = $request->get('hour_start'); 
       $hour_end = $request->get('hour_end'); 
       $fk_student = $request->get('fk_student');

        $thisStudentsTrainings = Training::where('fk_student', $fk_student)->get();

        $thisStudentsPayments = Payment::where('fk_student', $request->get('fk_student'))->get();


        if(count($thisStudentsTrainings) >= count($thisStudentsPayments) * 5) {
            return redirect()->route('trainings.index') 
                ->with('error', 'ceiling reached!'); 
        }


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

       
    }

I want to create my method update () but I am stuck ... I don't understand how I could adapt my code of my method store in my method update() ?

public function update(Request $request, $id)
{  

   
   $request->validate([
                'date_seance' => 'required',
                'hour_start' => 'required',
                'hour_end' => 'required',
                'fk_student' => 'required',
      
               
        ]);

 
   if{
       $trainings = Training::find($id);
       $trainings->date_seance = $request->get('date_seance');
       $trainings->hour_start = $request->get('hour_start');
       $trainings->hour_end = $request->get('hour_end ');
       $trainings->fk_student = $request->get('fk_student ');
       $trainings->save();
       return redirect()->route('trainings.index')
              ->with('success', 'Update!')->withInput();

   }

}


Oct
09
1 month ago
Activity icon

Replied to Eloquant Date & Hours

Ehh no why?

Oct
08
1 month ago
Activity icon

Started a new Conversation Eloquant Date & Hours

I am stuck about a problem concerning the hours en laravel.

In my form Training, I have several recordings.

For example, I want to add an other recording

On 20/09/2019 From 08:00 to 10:00

When, I confirm, I have a duplicate system...

The problem is that I don't have a recording for on 20/09/2019 From 08:00 to 10:00

In fact, my code blocks the hours even if the dates are different, how can I solve this problem?

 $date_seance = Carbon::parse($request->get('date_seance'))->format('Y-m-d');
 $hour_start = $request->get('hour_start'); 
 $hour_end = $request->get('hour_end'); 

 $fk_motorbike = $request->get('fk_motorbike');
 $fk_student = $request->get('fk_student');
 $fk_former = $request->get('fk_former');
 $fk_typeseance = $request->get('fk_typeseance');

       
 $conflictTraining1 = Training::where('fk_motorbike', $request->get('fk_motorbike')) 
 ->whereDate('date_seance', "=" , Carbon::parse($date_seance)) 
 ->where('hour_start', "<=" , $request->get('hour_start')) 
 ->where('hour_end', ">=" , $request->get('hour_end'))
 ->where('fk_former', $request->get('fk_former'))
 ->first();

 $conflictTraining2 = Training::where('fk_motorbike', $request->get('fk_motorbike')) 
 ->where('hour_start', "<=" , $request->get('hour_start')) 
 ->where('hour_end', ">=" , $request->get('hour_end'))
 ->where('fk_former', $request->get('fk_former'))
 ->first();
Activity icon

Replied to Future Date Check

Hello @nakov,

Great ! Thank you, my problem is solved.

Thank you a lot !

Activity icon

Started a new Conversation Future Date Check

I have a small problem in my dates. For example, I encoded the following date:

date training : 10/09/2019 | hour_start : 08:00 | hour_end : 10:00 | motorbike : 000001

Then, I want to encode for on 11/09/2019 the same informations

My checking compares only the hours (start & end) and no the date.

So, for my example, I have a blocking...

My problem is in my code

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


$conflictTraining = Training::where('fk_motorbike', $request->get('fk_motorbike')) 
->whereDate('date_seance', "=" , $date_seance)  
->where('hour_start', "<=" , $request->get('hour_start')) 
->where('hour_end', ">=" , $request->get('hour_end'))
->where('fk_former', $request->get('fk_former'))
->first();

 if(isset($conflictTraining)){
            return redirect()->route('trainings.index')
             ->with('error', 'The training is already booked');
        }

For information my hours are in format string is it a problem ?

 Schema::create('trainings', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->date('date_seance');
            $table->string('hour_start');
            $table->string('hour_end');

Thank you for your help.

Oct
05
1 month ago
Activity icon

Replied to Verifications Payment & Training

Hello @jlrdw ,

Sorry, but I don't understand... :(

Activity icon

Started a new Conversation Verifications Payment & Training

When I add a payment for a student in my form payment

the student can have 2 trainings (so, 1 payment = 2 trainings)

When, I want to add a second training in my form training, it blocks

In my Controller Training I have this:

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


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


       $payments = Payment::where('fk_student', $request->get('fk_student'))->first();


        if(!isset($payments)){ 
            return redirect()->route('trainings.index')
                    ->with('error', 'No payment, no training! ');
        }
       
        $thisStudentsTrainings = Training::where('fk_student', $fk_student)->get();

        if(count($thisStudentsTrainings) >= 2){ 
            return redirect()->route('trainings.index')
                ->with('error', 'The ceiling is 2 trainings! ');
        }

        $thisStudentsPayments = Payment::where('fk_student', $request->get('fk_student'))->get();


        if( count($thisStudentsPayments) < (count($thisStudentsTrainings) * 2) ) { 
            return redirect()->route('trainings.index') 
                ->with('error', 'test!'); 
          }


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

       

    }

I think the problem is here ?

if( count($thisStudentsPayments) < (count($thisStudentsTrainings) * 2) ) { 
            return redirect()->route('trainings.index') 
                ->with('error', 'test!'); 
          }

Thank you for your help.

Oct
03
1 month ago
Activity icon

Started a new Conversation Checking Payment

For each payment, the student can follow a training.

For example, I encode a payment for the student Menier.

enter image description here

Then, I encode a training for the student Menier.

enter image description here

It's correct !

Now, when I encode another payment for the same student Menier

enter image description here

I can't add a training, it's blocking ???

enter image description here

How to put to zero the checking, after each payment of the student?

$conflitpayment = Payment::where('fk_student', $request->get('fk_student'))
        ->whereDate('date_payment', ">" , $date_seance)
        ->first();

        if(isset($conflitpayment)){
            return redirect()->route('trainings.index')
                ->with('error', 'Payment! ');
        }
        
        $thisStudentsTrainings = Training::with(['payments' => function($query) use($fk_student){
        $query->where('fk_student', $fk_student);
        }])->get();

        $hasPaidForThisTraining = $thisStudentsTrainings ->contains('id', $request->get('fk_training'));

   

        if( count($thisStudentsTrainings) >= 1) { 
            return redirect()->route('trainings.index')
            ->with('error', 'No payment ! ');
        }
        
        
        
        else{
            Training::create($request->all());
                return redirect()->route('trainings.index')
                    ->with('success', 'Add');
        }

Thank you for your help.

Sep
29
1 month ago
Activity icon

Started a new Conversation Login With Two Different Roles

I have an admin which can create several recordings in the form Members.

In the table Members, there are 2 fields user_id and team_id.

Here is an example below:

enter image description here

Now, my problem is that I want to log for example with the user [email protected].

I have to see only my informations. Here is an example:

enter image description here

DataBase:

public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

public function up()
    {
        Schema::create('members', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned()->nullable();
            $table->foreign('user_id')->references('id')->on('users');
            $table->integer('team_id')->unsigned()->nullable();
            $table->foreign('team_id')->references('id')->on('teams');
            $table->timestamps();
        });
    }

 public function up()
        {
            Schema::create('teams', function (Blueprint $table) {
                $table->increments('id');
                $table->string('name');
                $table->integer('user_id')->unsigned()->nullable();
                $table->foreign('user_id')->references('id')->on('users');
                $table->timestamps();
            });
        }

I'm trying to understand the syntax to do?

 public function index(Request $request)
    {   
        
        $user = $request->user();
        $members = Member::query()
        ->when($user->hasRole('admin') !== true, function (Builder $query) use ($user) {
         $query->where('id???', $user->email); ????
        })
        ->when($request->has('search'), function (Builder $query) use ($request) {
        $query->where('name??', 'like', '%' . $request->input('search') . '%');
         })->with('team:id,name') 
        ->paginate(5);

        return view('admin.members.index', compact('members'))
        ->with('display_search', $user->hasRole('admin'));
   
    }

Thank you in advance for your help.

Activity icon

Replied to I Always Have The Same Student Which Appears After Each Recording

Thank you a lot, but I think my model "Student" is doesnt' correct ?

Sep
28
1 month ago
Activity icon

Replied to I Always Have The Same Student Which Appears After Each Recording

I have edtied my first message.

Thank you

Activity icon

Started a new Conversation I Always Have The Same Student Which Appears After Each Recording

When I add a recording, I always have the same student which appears ???

I think the problem is perhaps in my function index() ?

public function index(Request $request)
  {   
     $user = $request->user();
     $payments = Payment::query()
     ->when($user->hasRole('admin') !== true, function (Builder $query) use ($user) {
     $query->where('email', $user->email);
     })
     ->when($request->has('search'), function (Builder $query) use ($request) {
    $query->where('name', 'like', '%' . $request->input('search') . '%');
         })->with('students:id,name') 
    ->paginate(5);

    return view('admin.payments.index', compact('payments'))
    ->with('display_search', $user->hasRole('admin'));
    }

For information my table students has 3 fields (id, name, email) and the table payments has 6 fields (id, date_payment, number_seance, price, total, fk_student).

My relationships:

Model Student:

protected  $fillable = ['user_id', 'name', 'email', 'payment_id'];

public function payments(){

        return $this->hasMany('App\Payment', 'fk_student');
    }

  public function user()
    {
        return $this->belongsTo('App\User', 'id', 'payment_id');
    }

Model Payment:

protected  $fillable = ['date_payment', 'fk_student', 'number_seance',  'price', 'total'];
    
    public function students(){

    return $this->belongsTo('App\Student', 'fk_student');
    }

    public function user()
    {
        return $this->belongsTo('App\User', 'id', 'payment_id');
    }

Model User

public function students()
    {
        return $this->hasOne('App\Student', 'user_id', 'id');
    }

    public function payments()
    {
        return $this->hasOne('App\Student', 'payment_id', 'id');
    }

Index blade

<th>Date payment</th>
<th>Number seance</th>
<th>Price</th>
<th>Total</th>
 <th>Name</th>

</tr>
</thead>
@foreach($payments as $payment)
<tr>
   <td> {{$payment->date_payment->format('d/m/Y') }}</td>
   <td> {{$payment->number_seance}}</td>
   <td> {{$payment->price}}</td>
   <td> {{$payment->total}}</td>
   <td> {{$payment->students->first()->name}}</td> 
   <td>

Thank you for your help.

Activity icon

Replied to Request Controller On 2 Tables

@bobbybouwmann thank you , my problem is solved.

Activity icon

Replied to Request Controller On 2 Tables

Thank you, but I have to use a wherahas or not ? I don't understand... In fact, I want that when I encode a payment, the student consults his payment after login.

In my model Payment

public function eleves(){

    return $this->belongsTo('App\Student', 'fk_student');
    }

In my model Student I have this

public function payments(){

        return $this->hasMany('App\Payment', 'fk_student');
    }

My relationship are correct ?

Thank you

Activity icon

Started a new Conversation Request Controller On 2 Tables

I have a table students with the fields (id, name) and a table named payments with 6 fields (id, date_payment, number_seance, price, total, fk_student)

So, in my Controller Payment I have this (for now)

public function index(Request $request)
{
    $user = $request->user();
    $payments = Payment::query()
        ->when($user->hasRole('admin') !== true, function (Builder $query) use ($user) {
            $query->where('email', $user->email);
        })
        ->when($request->has('search'), function (Builder $query) use ($request) {
            $query->where('name', 'like', '%' . $request->input('search') . '%');
        })
        ->paginate(5);

    return view('admin.payments.index', compact('payments'))
        ->with('display_search', $user->hasRole('admin'));
}

In fact, I have to replace where by whereHas

$query->where('name', 'like', '%' . $request->input('search') . '%');

I don't know how do I have to include the whereHas

Thank you for your help

Sep
27
1 month ago
Activity icon

Replied to Need Help On A Syntax Please

Hello @snapey ,

Yes... :-(

Activity icon

Started a new Conversation Need Help On A Syntax Please

Hello,

My table is named Cars with 2 fields (id, matriculation), how to adapt my syntax below ?

 'input_field' => 'unique:<table name>,<column name for this input field>, <unique id>, <unique id column in table>';

I have tried this: ???

 'matriculation' => 'required|unique:cars,matriculation, uniqueID ???? , unique id colum in table ???? 

Do know you what is the unique id and unique id column ???

Thank you for your help.

Activity icon

Started a new Conversation Question About The Connection For A User

I have for my table 'Student' 5 fields id, name, firstname, email, phone.

My question: I would like the user to connect by putting his name what should I change?

    public function index(Request $request)
        {   
            $user = $request->user();
            $students= Student::query()
            ->when($user->hasRole('admin') !== true, function (Builder $query) use ($user) {
                $query->where('email', $user->email);
            })
            ->when($request->has('search'), function (Builder $query) use ($request) {
                $query->where('name', 'like', '%'.$request->input('search').'%');
            })
            ->paginate(5);
    
            
    
        return view('admin.students.index', compact('students'))
            ->with('display_search', $user->hasRole('admin'));
        }

Here:

    $query->where('email', $user->email);

I have to put this?

      $query->where('name', $user->name);

Thank you for your help.

Sep
22
1 month ago
Activity icon

Started a new Conversation Planning Between 2 Models

I yet have a problem with my planning. My frist model is Revision with as informations following:

The date_revision_start on 12/09/2019 to 14/09/2019 then hour_start & hour_end from 07:00 to 09:00 and the bike 000001.

Below, I have no problem...

Now, in my model Training if I want to enter a training on 14/09/2019 from 10:00 to 12:00 for the bike 000001.

I have an error message ?? Normally, the recording is correct...

Do you have an idea for better compare my hour_start & hour_end?

    $date_seance = $request->get('date_seance'); 
    $hour_start = $request->get('hour_start'); 
    $hour_end = $request->get('hour_end'); 
    $fk_motorbike = $request->get('fk_motorbike');
    $fk_student = $request->get('fk_student');
    $fk_former = $request->get('fk_former');
    $fk_typeseance = $request->get('fk_typeseance');
    
    $conflictTraining = Training::where('fk_motorbike', $request->get('fk_motorbike'))  
            ->whereDate('date_seance', "=" , $date_seance)  
            ->where('hour_start', "<=" , $request->get('hour_start')) 
            ->where('hour_end', ">=" , $request->get('hour_end'))
            ->where('fk_former', $request->get('fk_former'))
            ->first();  
            
    $conflictRevision = Revision::where('fk_motorbike', $fk_motorbike)
                ->whereDate('date_revision_start', "<=" , $date_seance)
                ->whereDate('date_revision_end', ">=", $date_seance)
                ->first();
        
    $conflictRevision1 = Revision::where('fk_motorbike', $fk_motorbike)
                ->whereDate('date_revision_start', "<=" , $date_seance)
                ->where('hour_start', "<=" , $request->get('hour_start'))  
                ->where('hour_end', ">=" , $request->get('hour_end'))
                ->first();
        
    $conflictRevision2 = Revision::where('fk_motorbike', $fk_motorbike)
                ->whereDate('date_revision_end', "<=" , $date_seance)
                ->where('hour_start', "<=" , $request->get('hour_start'))  
                ->where('hour_end', ">=" , $request->get('hour_end'))
                ->first();
        
    $conflictFormer = Training::where('fk_former', $fk_former)  
                ->whereDate('date_seance', "=" , $date_seance)  
                ->where('hour_start', "<=" , $request->get('hour_start')) 
                ->where('hour_end', ">=" , $request->get('hour_end'))
                ->first();  
        
    $conflictMotorbike = Training::where('fk_motorbike', $fk_motorbike)  
                ->whereDate('date_seance', "=" , $date_seance)  
                ->where('hour_start', "<=" , $request->get('hour_start')) 
                ->where('hour_end', ">=" , $request->get('hour_end'))
                ->first();  

Thank you for your help and your time.

Activity icon

Replied to Validation And Duplicate Update() In Laravel

@mabdullahsari : Thank you for your help, I have an error message Undefined variable: voiture ? Where I have to find this variable ?

Activity icon

Started a new Conversation Validation And Duplicate Update() In Laravel

In my form Voiture, I want to do a validation system for the fields immatriculation and num_vehicule

Here i an overview:

If I edit the first recording ie the value of the field num_vehicule 000001 per 0000032and that I validate, I have an error message because the value of the field immatriculation already exists.

I don't understand the problem... Do you have an idea please?

'immatriculation' => 'required|string|max:15|min:6|unique:voitures,immatriculation',
'num_vehicule' => 'required|string|max:6|min:6|unique:voitures,num_vehicule',
'fk_modele' => 'required'

Thank you

Sep
20
1 month ago
Activity icon

Replied to Calculate Hours

In my model Training I have this ?

$start = Carbon::parse($request->get('hour_start'));
$end= Carbon::parse($request->get('hour_end'));

$mins = $end->diffInMinutes($start, true);
$hoursTraining = $mins/60;

Then, I calcule the total always in my model Training ?

$total = $typeTraining->price * $hoursTraining; 

I have an error message Undefined variable: typeTraining

Sep
18
1 month ago
Activity icon

Started a new Conversation Calculate Hours

I have some hesitations about 3 tables which are type_training , training & payment.

In the table type_training, I have a field named price with 4 amounts: for example:

1 hour 00 = 100 euros

1 hour 30 = 150 euros

2 hour 00 = 200 euros

2 hour 30 = 250 euros

In my page Training , I encode 2 recordings for the same student.

The student Dujardin has booked 3 hours for 300 euros.

In my form Payment, is it possible to retrieve the amount of 300 ?

So, in my Model Payment? I must to calculate the difference between the hour start and the hour end?

I don't know how to do ?

Then, after having retrieved the difference of hours in my example we have 3 hours. How to I sum my 2 recordings in my field Total ? I have tried this?

    $typetraining = Typetraining::find($request->fk_typetraining);
    $data = $request->all(); 
    $data['total'] = $typetraining->price + $request->????;
    Payment::create($data);

In summary:

  1. How to retrieve the difference between hour start & hour end,

  2. How to calculate the amounts via the duration of my training?

For information, here is my architecture.

I thank you for your help and your explanations.

Sep
14
1 month ago
Activity icon

Replied to Check The Dates Before Planning

Contact the dead ??? i don't understand...

The former is a trainer in fact.

Activity icon

Replied to Check The Dates Before Planning

it's an exercise for the school... I must to make an application for a motorbike school

Activity icon

Replied to Check The Dates Before Planning

@snapey : Ah yes, lol I have edited my first message. I don't understand, how can I compare precisely dates between Revision et Training?

Activity icon

Started a new Conversation Check The Dates Before Planning

I planned a training date on 10/09/2019

My problem is that when I planned a revision for example on 09/09/2019 to 11/09/2019. I can add one recording , I would like to make one blocking... Is it possible?

Controller Training


  public function store(Request $request)
    {
        $request->validate([
                'date_seance' => 'required',
                'hour_start' => 'required',
                'hour_end' => 'required',
                'fk_motorbike' => 'required',
                'fk_former' => 'required',
                'fk_student' => '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)  
        ->whereDate('date_seance', "=" , $date_start)  
        ->where('hour_start', "<=" , $request->get('hour_start')) 
        ->where('hour_end', ">=" , $request->get('hour_end'))
        ->where('fk_former', $request->get('fk_former'))
        ->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();
        

        $conflictFormer = Training::where('fk_former', $fk_former)  
        ->whereDate('date_seance', "=" , $date_start)  
        ->where('hour_start', "<=" , $request->get('hour_start')) 
        ->where('hour_end', ">=" , $request->get('hour_end'))
        ->first();  

        $conflictMotorbike = Training::where('fk_motorbike', $fk_motorbike)  
        ->whereDate('date_seance', "=" , $date_start)  
        ->where('hour_start', "<=" , $request->get('hour_start')) 
        ->where('hour_end', ">=" , $request->get('hour_end'))
        ->first();  


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

        if(isset($conflictRevision)){
            return redirect()->route('trainings.index')
            ->with('error', 'The motorbike is in revision! ');
        }
      

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

        if(isset($conflictMotorbike)){
            return redirect()->route('trainings.index')
            ->with('error', 'Duplicate motorbik ! ');
        }
        
        
        else{
            Training::create($request->all());
                return redirect()->route('trainings.index')
                    ->with('success', 'Add');
        }

       

    }

Activity icon

Replied to Invalid Argument Supplied For Foreach() (View:

@snapey :

the user table represents the user, we have two roles, either an administrator or a candidate.

The candidate connects to see his remarks and his sessions. The administrator adds the candidates, the seances, and the remarks

Activity icon

Replied to My Architecture Is Correct?

Yes, one remark per seance...

Activity icon

Replied to My Architecture Is Correct?

@snapey : I indicated the cardinalities?

Activity icon

Replied to Invalid Argument Supplied For Foreach() (View:

@snapey no, I have to create a relationship between the two?

Activity icon

Replied to Invalid Argument Supplied For Foreach() (View:

@nakov , @mikenewbuild

I think my relationships are not good in my models? I created a post with my architecture, here => https://laracasts.com/discuss/channels/general-discussion/my-architecture-is-correct

I think it's important to have the right basics.

Activity icon

Started a new Conversation My Architecture Is Correct?

My goal is for each user to log in and have their remarks after each seance. I have two roles, an administrator and a candidate.

My tables are :

Candidates with 3 fields (id, name, email)

Seances with 3 fields (id, date_seance, fk_candidate)

Remarks with 4 fields (id, instruction, description, fk_seance)

Users with 3 fields (id, email, password)

My frist question, is it my relationship are ok according you ???

Model User

public function candidates()
    {
        return $this->hasOne('App\Candidate', 'user_id', 'id');
    }

    public function remarks()
    {
        return $this->hasOne('App\Remark', 'user_id', 'id');
    }

Model Candidate

public function user(){
        return $this->belongsTo('App\User', 'id', 'user_id');
    }

    public function seances(){

        return $this->hasMany('App\Seance', 'fk_candidate');
    }

Model Seance

public function candidates(){

        return $this->belongsTo('App\Candidate', 'fk_candidate');
    }

    public function remarks(){

        return $this->hasMany('App\Remark', 'fk_seance');
    }

Model Remark

public function user(){
        return $this->belongsTo('App\User', 'id', 'user_id');
    }
    
    public function seances(){

        return $this->belongsTo('App\Seance', 'fk_seance');
    }

My second question, please is it I must to add a user_id on the table Remarks ???

Remarks

Schema::create('remarks', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned()->nullable();
            $table->foreign('user_id')->references('id')->on('users');
            $table->string('instruction', 30);
            $table->text('description', 80);
            $table->integer('fk_seance')->unsigned();
            $table->foreign('fk_seance')->references('id')->on('seances');
            $table->timestamps();
        });

Candidates

Schema::create('candidates', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned()->nullable();
            $table->foreign('user_id')->references('id')->on('users');
            $table->string('name');
            $table->string('email');
            $table->timestamps();
        });

Seances

Schema::create('seances', function (Blueprint $table) {
            $table->increments('id');
            $table->date('date_seance');
            $table->integer('fk_candidate')->unsigned();
            $table->foreign('fk_candidate')->references('id')->on('candidates');
            $table->timestamps();
        });

Thank you a lot for your help.

Activity icon

Replied to Invalid Argument Supplied For Foreach() (View:

@nakov

it's written null

@mikenewbuild

Yes, I am connected with the role "candidate"

@snapey

It's for the role "candidate" the user has a remark

Activity icon

Replied to Invalid Argument Supplied For Foreach() (View:

Hello,

Thank you for your help... I always have the same error message -> " Invalid argument supplied for foreach() " :-(

I have added the get()

public function index(Request $request)
    {   
    if(\Auth::user()->hasRole('admin')){
         if($request->has('search'))
              $remarks = Remark::orderBy('instruction', 'asc')->where('instruction','like','%'.$request->input('search').'%')->get();
         else
             $remarks = Remark::all();
    }else{
         \Auth::user()->load('remarks');
         $remarks = \Auth::user()->remarks;
    }

    return view('admin.remarks.index', compact('remarks'));
    }

I also have deleted the first() (for now)

 <td> {{$remark->instruction}}</td>
<td> {{$remark->description}}</td>
 <td> {{$remark->seances->date_seance}}</td>

I don't understand why the problem... :-(

Activity icon

Started a new Conversation Invalid Argument Supplied For Foreach() (View:

Hello,

I have like error message : Invalid argument supplied for foreach() (View:

For my method index() I have this:

public function index(Request $request)
    {   
    if(\Auth::user()->hasRole('admin')){
         if($request->has('search'))
              $remarks = Remark::orderBy('instruction', 'asc')->where('instruction','like','%'.$request->input('search').'%');
         else
             $remarks = Remark::all();
    }else{
         \Auth::user()->load('remarks');
         $remarks = \Auth::user()->remarks;
    }

    return view('admin.remarks.index', compact('remarks'));
    }

Concerning my index.blade.php I have my loop "for" which is like this:

<th>Instruction</th>
                  <th>Description</th>
                  <th>Date seance</th>
                  <th>Name Candidate</th>
                  <th>Email</th>
                </tr>
                </thead>
               @foreach($remarks as $remark)
                <tr>
                   <td> {{$remark->instruction}}</td>
                   <td> {{$remark->description}}</td>
                   <td> {{$remark->seances->date_seance}}</td>
                   <td> {{$remark->seances()->first()->candidates->name}}</td>
                   <td> {{$remark->seances()->first()->candidates->email}}</td>
                   <td>

Do you have an idea of my problem please? I don't understand ??

Sep
13
1 month ago
Activity icon

Started a new Conversation Retrieve A Feedback After Connection Of An User

Hello,

When the user is connected and wishes to consult the feedback section, the user see each feedbacks for eachs users. I would like to know if it's possible to limit this?

For example, if the user is [email protected], Jeremy can see only his feedback.

Here is an idea of my code, I thank you in advance for your help.

public function index(Request $request)
    {   
    $user = $request->user();

    $feedbacks = Feedback::query()
    ->when($user->hasRole('admin') !== true, function (Builder $query) use ($user) {
        \Auth::user()->load('feedbacks');
        $feedbacksForThisUser = \Auth::user()->feedbacks;
    })
    ->when($request->has('search'), function (Builder $query) use ($request) {
     $query->join('eleves', 'feedbacks.fk_eleve', '=', 'eleves.id')->orderBy('eleves.nom', 'asc')->where('eleves.nom','like','%'.$request->input('search').'%');
     })
    ->paginate(5);

    return view('admin.feedbacks.index', compact('feedbacks'))
        ->with('display_search', $user->hasRole('admin'));
}
Sep
09
2 months ago
Activity icon

Started a new Conversation Condition On A Foreign Key

I have to make 2 conditions:

  1. My first condition: I have to test that if I don't have a payment, I don't can encode a training.

  2. Then, my second condition (very difficult for me), the number of seance must be equal to the number of reservation. For example: 1 seance = 1 training. For now, my bookings are unlimited... :-(

public function store(Request $request)
    {
        $request->validate([
               'date_sitting' => 'required',
                'fk_payment' => 'required',
                'fk_student' => 'required'
        ]);


       $exists = Training::where('date_sitting', $request->get('date_sitting'))->where('fk_payment', $request->get('fk_payment'))->where('fk_student', $request->get('fk_student'))->count();

       if (!$exists){


        $payment = Payment::where('fk_student', $request->get('fk_student'))->first();


        if(!isset($payment)){ 
            return redirect()->route('trainings.index')
                    ->with('error', 'No Payment, no training for you!');
        }
        else{
            Training::create($request->all());
            return redirect()->route('trainings.index')
                    ->with('success', 'new data created successfully');
        }
    }


    }

My tables are:

Training = date_sitting, fk_payment, fk_student

Payment = date_payment, number_seance , price, total, fk_student