david2000

david2000

Member Since 1 Month Ago

Experience Points 1,770
Experience Level 1

3,230 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.

20 Sep
12 hours ago

david2000 left a reply on 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

18 Sep
2 days ago

david2000 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.

14 Sep
6 days ago

david2000 left a reply on Check The Dates Before Planning

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

The former is a trainer in fact.

david2000 left a reply on Check The Dates Before Planning

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

david2000 left a reply on 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?

david2000 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');
        }

       

    }

david2000 left a reply on 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

david2000 left a reply on My Architecture Is Correct?

Yes, one remark per seance...

david2000 left a reply on My Architecture Is Correct?

@snapey : I indicated the cardinalities?

david2000 left a reply on Invalid Argument Supplied For Foreach() (View:

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

david2000 left a reply on 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.

david2000 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.

david2000 left a reply on 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

david2000 left a reply on 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... :-(

david2000 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 ??

13 Sep
1 week ago

david2000 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'));
}
09 Sep
1 week ago

david2000 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

david2000 left a reply on Your Opinion On My Architecture

Of course.

Training

public function payments(){

      return $this->belongsTo('App\Payment', 'fk_payment');
    }

Payment

public function Trainings(){

        return $this->hasMany('App\Training', 'fk_payment');
    }

david2000 started a new conversation Your Opinion On My Architecture

Hello,

I have a table named Training with like fields (date_seance, hour_start, hour_end, fk_payment)

I have another table named Paiement with the fields ( date_payment, number_seance, total, fk_type_seance, fk_student, method_payment)

My problem is that I want to retrieve the number seance from my table Payment via my table Training. For example: If the Student David pays 2 number seances (form Payment) And that when, I add several trainings for the student David, I can add only 2 trainings because, the student David has pays 2 seances.

You think it's possible to make this?

08 Sep
1 week ago

david2000 left a reply on The Number Of Training Is Equal To The Reservation

In my model I have this:

Training

public function payments(){

      return $this->belongsTo('App\Payment', 'fk_payment');
    }

Payment

public function Trainings(){

        return $this->hasMany('App\Training', 'fk_payment');
    }

My relationship is correct?

david2000 left a reply on The Number Of Training Is Equal To The Reservation

@nakov: my code is not correct visibly, would you have a little idea of how I could check my seances? I am stuck...

david2000 started a new conversation The Number Of Training Is Equal To The Reservation

I am stuck since several days concernng the checking betwen the number of training and the reservation.

For example: you pay 1 training (1 seance), you have 1 booking. we can not encode 2 bookings an error message appears. It's my but...

in my table Training, here is my fields (hour_start, hour_end, fk_motorbike, fk_former, fk_student, fk_payment)

and In my table Payment I have this (date_payment, number_seance, total, fk_student, method_payment)

In my screenshot, I have 1 payment for 1 seance

Here, the problem is that I can add several trainings, it's not limit to 1 seance.

do you have any idea how I could do that? I tried this but without success

$seance = Payment::find($request->fk_payment);

        if($request->seance >= $request->number_seance){ 
             return redirect()->route('trainings.index')
            ->with('error', 'Limit! ');
        }

david2000 started a new conversation Hide A Foreign Key For The Creation Of A Record

I have 2 table: Training and Payment, my fk_foreign key is fk_payment it's the date_payment

Here is an example, the date_payment is on 09/09/2019.

Now, I want to add a recording in my table Training, I retrieve the date_payment.

My problem is that when I add a recording in my form Training, I have the field fk_payment to enter...

I have a dropdownlist with some dates, is it possible to hide my fk_payment when I create a recording?

Thank you for your help.

06 Sep
2 weeks ago

david2000 started a new conversation Function Update()

I have a problem in my function update(), in fact I have a recording but when I want to change the hour, I get an error message: duplicate

for information, my fields are: date_seance, hour_start, hour_end, fk_former, fk_bike

Here is an idea of my first recording:

07/09/2019 08:00 13:00 Gofette Alain 000001

When I want to change the value 08:00 I have a duplicate, I don't understand, I only have a recording.

public function update(trainingRequest $request, $id)
    {   
       $date_start = $request->get('date_seance'); 
       $hour_start = $request->get('hour_start'); 
       $hour_end = $request->get('hour_end'); 
       $fk_bike = $request->get('fk_bike');
       $fk_former = $request->get('fk_former');
 
           
        $conflictTraining = Training::where('fk_bike', $fk_bike)  
        ->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();  
        
        if( (isset($conflictTraining) && $conflictTraining->id !== intval($id))
        || isset($conflictTraining) ){
            return redirect()->route('trainings.index')
            ->with('error', 'Duplicate! ');
        }
        
    }

Do have you an idea of my problem please?

05 Sep
2 weeks ago

david2000 left a reply on Check A Duplicate For A Foreign Key

Thank you, @successdav I have found the solution:

$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'))
        ->where('fk_former', $request->get('fk_former'))
        ->first();  

david2000 started a new conversation Check A Duplicate For A Foreign Key

I am creating a small project which is a driving school for motorbike. I have 4 tables:

In my form training, I see a thing illogical that I have to solve.

When, I encode the name of a former (trainer), I can put 2 times the same trainer the same hours.

I have tried this but without success:

       $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'))
        ->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();

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

My error message is the following:

SQLSTATE[42S22]: Column not found: 1054 Champ 'fk_former' inconnu dans where clause (SQL: select * from formers where fk_former = 1 and name is null limit 1)

Thank you for your help.

04 Sep
2 weeks ago

david2000 left a reply on Duplicate Hour_start & Hour_end

I have an error message Call to a member function replicate() on null ???

Thanks

david2000 started a new conversation Duplicate Hour_start & Hour_end

My duplicate system has a problem , it doesn't works correctly...

In fact, I have a form with 4 fields (date_seance, hour_start, hour_end,number_motorbike, fk_former).

For example, I add the informations following: 10/09/2019 08:00 10:00 000001 Alain

It works !

Now, if I want to add the informations following: 10/09/2019 14:00 16:00 000001 Alain

My recording is blocked ! I have an error message -> duplicate.

I have tried this:


function store()


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

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

Do you have an idea please?

david2000 left a reply on Duplicate System On Two Forms

You need some sort of "flag" set. Such as a checkbox perhaps. Or a query that checks between dates for availability.

For exemple, when my motorbike (number) 000001 is under revision on08/09/2019 to 09/09/2019 and that then I have to organize a seance on 08/09 / 2019 always with the motobike 000001, I must to have a checking system that checks whether the motorbike is available or not ... Here, for example, the bike must be unavailable

03 Sep
2 weeks ago

david2000 started a new conversation Duplicate System On Two Forms

My project is to create a small driving school for motorbike.

I have 4 tables: Former, Training, Revision, Motorbike

My functions create() and store() work for my 4 forms.

However, I have a big problem ... If, my motorbike is in revision on03/09/2019 to 05/09/2019 for the motorbike000001

and that I encode in my form training a booking on 03/09/2019 with as motorbike number 000001; Normally the motorbike is unavailable, how can I handle that?

Is it possible to create a duplicate system for the forms revision ->training or the inverse training ->revision

In my Controller Revision I have this:

public function index()
    {
        $revisions = Revision::oldest()->paginate(5);
        return view('admin.revisions.index', compact('revisions'))
          ->with('i', (request()->input('page',1) -1)*5);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()            
    {
        
        $motorbikes = Motorbike::all();
        return view('admin.revisions.create', compact('motorbikes','revisions'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        
        $date_revision_start = $request->get('date_revision_start');
        $date_revision_end = $request->get('date_revision_end');
        $hour_start = $request->get('hour_start');
        $hour_end = $request->get('hour_end');
        $garage = $request->get('garage');
        $fk_motorbike = $request->get('fk_motorbike');

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

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

      
    
        if(isset($conflict2) || isset($conflict)){
            return redirect()->route('revisions.index')
             ->with('error', 'duplicate');
        }

       else{
        Revision::create($request->all());
            return redirect()->route('revisions.index')
                ->with('success', 'new data created successfully');
        }
       
    }

And for the Controller Training

public function index()
    {
        $trainings = Training::oldest()->paginate(5);
        return view('admin.trainings.index', compact('trainings'));
                with('i', (request()->input('page', 1) -1) *5);
    }

 

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {   
        $motorbikes = Motorbike::all();
        $formers = Former::all();
        return view('admin.trainings.create', compact('motorbikes','formers','trainings'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $request->validate([
                'date_seance' => 'required',
                'hour_start' => 'required',
                'hour_end' => 'required',
                'fk_motorbike' => 'required',
                'fk_former' => 'required'
                
                
        ]);


       $exists = Training::where('date_seance', $request->get('date_seance'))->where('hour_start', $request->get('hour_start'))->where('hour_end', $request->get('hour_end'))->where('fk_motorbike', $request->get('fk_motorbike'))->count();

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

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

        } 
       

    }

Could you help me please, because I'm still a beginner in Laravel and I want to solve this problem.

Thanks in advance

david2000 started a new conversation Training & Appointment

I have a table named "Training" with 4 fields (date_seance, hour_start, hour_end, fk_bike).

My first problem is that I can not plan dates in advance.

For example, if I reserve a date on 01/09/2019 for the bike 000001. It works but if, I must to book another booking on 02/09/2019 with the same bike. So, 000001 I don't see the bike 000001 in my dropdownlist.

Do you have an idea ? Please...

public function index()
{
    $trainings = Training::oldest()->paginate(5);
    return view('admin.trainings.index', compact('trainings'))
      ->with('i', (request()->input('page',1) -1)*5);
}
public function store(Request $request)
    {   

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

        Training::create($request->all());

        return redirect()->route('trainings.index')
                ->with('success', 'new data created successfully');
    }

I thank you for your help and your time.

david2000 left a reply on Book A Seance In Advance

Sorry, I edited my first message...

02 Sep
2 weeks ago

david2000 started a new conversation Book A Seance In Advance

I am stuck on two problems:

1)- I have a table named "Course" with 4 fields (date_seance, hour_start, hour_end, fk_bike).

My first problem is that I can not plan dates in advance.

For example, if I reserve a date on 01/09/2019 for the bike 000001.

I must be able to book another booking on 02/09/2019 with the same bike. So, 000001.

public function store(courseRequest $request)
    {
        
        
        $exists = Course::where('date_seance', $request->get('date_seance'))->where('hour_start', $request->get('hour_start'))->where('hour_end', $request->get('hour_end'))->where('fk_bike', $request->get('fk_bike'))->count();

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

        $conflict = Course::where('fk_bike', $request->get('fk_bike'))->whereDate('date_seance', "<=" , $date_seance)
            ->whereDate('date_seance ', ">=", $date_seance)
            ->first();

        $conflict2 = Course::where('fk_bike', $request->get('fk_bike'))->whereDate('date_seance', "<=" , $ date_seance)->whereDate('date_seance', ">=", $date_seance)->first();


        if(isset($conflict2) || isset($conflict)){
            return redirect()->route('courses.index')
             ->with('error', 'Duplicate ');
        }

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

2)- Second question, if I add a fk_former, do you have an idea of the synthax?

david2000 started a new conversation Retrieve Recording Of A User After Login

I have a table named Student with several fields :

'id', 'user_id', 'name', 'firstname', 'date_birth', 'sex', 'address', 'fk_city', 'phone', 'email', 'status', 'fk_license', 'date_registration'.

I have another table named Feedback with several fields also:

'id', 'user_id','instruction', 'description', 'fk_student'.

I also have 2 roles which are Admin and Member.

The administrator creates 2 recordings in the table Student, see below:

And the administrator creates 1 recording in the table Feedback for the Student Menier Jeremy.

When, I login with the address email [email protected] (Menier Jeremy) I see my 2 rubrics: (Student profil and feedback)

I can consult my information in my profil

Well!

Now, my problem is that when I click on my Feedback to consult the Feedback; it's empty ?

I don't understand why I retrieve the information for the rubric Student and no for the rubric Feedback?

Here is an idea of my code, is it a problem with my model?

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

    $feedbacks = Feedback::query()
    ->when($user->hasRole('admin') !== true, function (Builder $query) use ($user) {
        $query->whereHas('user', function ($query) use ($user) {
            $query->where('email', $user->email);
    });
    })
    ->when($request->has('search'), function (Builder $query) use ($request) {
     $query->join('students', 'feedbacks.fk_student', '=', 'students.id')->orderBy('students.name', 'asc')->where('students.name','like','%'.$request->input('search').'%');
     })
    ->paginate(5);

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

Thank you for your help.

01 Sep
2 weeks ago

david2000 left a reply on Duplicate - Function Update

Hello @bobbybouwmann ,

Thank you for your help, I have tried but I always have the same problem.

david2000 started a new conversation Duplicate - Function Update

I am trying to create a duplicate system, I have a form revision with a recording.

For example, I have to change the value of my field hour_start => 18:00

I want to replace by the value => 08:00

When, I validate the form I have an error message:

The value of my field hour start is always the same

In fact, my duplicate system must work for dates, but if I change a value of my field hour_start, it must pass...

public function update(revisionRequest $request, $id)
    {
        
        $exists = Revision::where('date_revision_start', $request->get('date_revision_start'))->where('date_revision_end', $request->get('date_revision_end'))->where('hour_start', $request->get('hour_start'))->where('hour_end', $request->get('hour_end'))->where('fk_motorbike', $request->get('fk_motorbike'))->where('fk_garage', $request->get('fk_garage'))->count();

        $date_revision_start = $request->get('date_revision_start');
        $date_revision_end = $request->get('date_revision_end');

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

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

        if(isset($conflict2) || isset($conflict)){
            return redirect()->route('revisions.index')
             ->with('error', 'Duplicate date! ');
        }
        

        else{
            $revisions = Revision::find($id);
            $revisions->date_revision_start = $request->get('date_revision_start');
            $revisions->date_revision_end = $request->get('date_revision_end');
            $revisions->hour_start = $request->get('hour_start');
            $revisions->hour_end = $request->get('hour_end');
            $revisions->fk_garage = $request->get('fk_garage');
            $revisions->fk_motorbike = $request->get('fk_motorbike');
            $revisions->save();
            return redirect()->route('revisions.index')
                    ->with('success', 'ok')->withInput();
        }
       
    } 

Thank you for your help.

31 Aug
2 weeks ago

david2000 left a reply on Impossible To Add, A Recording

Thank you a lot, my problem concerning this topic is solved.

david2000 started a new conversation Impossible To Add, A Recording

I'm trying to add a recording in my form Revision, but it misses a few things? I can add a recording via phpmyadmin but not on my form.

create.revision

index.revision

Here is, below my function store()

public function store(revisionRequest $request)
    {
        
        $date_revision_start = $request->get('date_revision_start');
        $date_revision_end = $request->get('date_revision_end');
        $garage = $request->get('garage');
        $fk_motorbike = $request->get('fk_motorbike');


        
        $conflict = Revision::whereDate('fk_motorbike', $request->get('fk_motorbike'))->whereDate('date_revision_start', "<=" , $date_revision_start);

        $conflict2 = Revision::whereDate('fk_motorbike', $request->get('fk_motorbike'))->whereDate('date_revision_start', "<=" , $date_revision_end)->whereDate('date_revision_end', ">=", $date_revision_end)->first();
        dd($conflict);
    
        if(isset($conflict2) || isset($conflict)){
            return redirect()->route('revisions.index')
             ->with('error', 'duplicate');
        }


       else{
        Revision::create($request->all());
            return redirect()->route('revisions.index')
                ->with('success', 'new data created successfully');
        }
       
    }

I don't unserstand the error ???

I thank in advance for your help.

30 Aug
3 weeks ago

david2000 started a new conversation Call To A Member Function Where Date() On String

Hello,

I have like error message: "Call to a member function whereDate() on string".

I need to convert the date?

In my form revision.index I have tested this now:

@foreach($revisions as $revision)
<tr>
<td>{{ Carbon\Carbon::parse($revision->date_revision_start->format('d/m/Y') }}</td>
<td>{{ Carbon\Carbon::parse($revision->date_revision_end->format('d/m/Y') }}</td>
<td>{{ $revision->garage }}</td>
 <td>{{ $revision->motorbikes->number_motorbike }}</td>
  <td>

The error message is **syntax error, unexpected ';', expecting ',' or ')' (View: **

My model Revision

protected $fillable = ['date_revision_start', 'date_revision_end', 'garage', 'fk_motorbike'];

protected $dates = ['date_revision_start', 'date_revision_end'];

My table Revisions

public function up()
    {
        Schema::create('revisions', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->date('date_revision_start');
            $table->date('date_revision_end');
            $table->string('garage');
            $table->integer('fk_motorbike')->unsigned();
            $table->foreign('fk_motorbike')->references('id')->on('motorbikes');
            $table->timestamps();
        });
    }

I forgot a step?

Thank you for your help

david2000 left a reply on The Dates And Checking For A Planning

@pciranda : Thank you for your help, how I integrate your code on my function store()??? I am stuck...

public function store(revisionRequest $request)
    {
        
        $exists = Revision::where('date_revision_start', $request->get('date_revision_start'))->where('date_revision_end', $request->get('date_revision_end'))->where('garage', $request->get('garage'))->where('fk_motorbike', $request->get('fk_motorbike'))->count();

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

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

        }  
    }

david2000 left a reply on The Dates And Checking For A Planning

@nakov : Thank for your help.

For now no, I edited my first message by giving even more information.

I tested this for the moment, I have an error message: Data missing ??? "d/m/Y" null

public function store(revisionRequest $request)
    {
        
        $exists = Revision::where('date_revision_start', $request->get('date_revision_start'))->where('date_revision_end', $request->get('date_revision_end'))->where('garage', $request->get('garage'))->where('fk_motorbike', $request->get('fk_motorbike'))->count();

        $from = Carbon::createFromFormat('d/m/Y', request('revision_start'));
        $to = Carbon::createFromFormat('d/m/Y', request('revision_end'));

        Revision::where('fk_motorbike', $motorbikeNumber)
             ->whereBetween('date_revision_start', [$from, $to])
             ->orWhereBetween('date_revision_end', [$from, $to])
             ->exists();

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

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

        }   
    }

david2000 started a new conversation The Dates And Checking For A Planning

I have a problem concerning the checking of my dates.

Example, my motorbike number 000001 is in revision from 30/08/2019 to 03/09/2019. The recording is good. (no problem)

However, if I add a revision on 02/09/2019 to 03/09/2019, I would like to add an error message explaining that the motorbike is already in revision.

My function index() is like this: (Revision)

public function index()
{
    $revisions = Revision::oldest()->paginate(5);
    return view('admin.revisions.index', compact('revisions'))
      ->with('i', (request()->input('page',1) -1)*5);
}

I think my problem is in my function store()???

$exists = Revision::where('date_revision_start', $request->get('date_revision_start'))->where('date_revision_end', $request->get('date_revision_end'))->where('garage', $request->get('garage'))->where('fk_motorbike', $request->get('fk_motorbike'))->count();

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

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

        }  

Class Motorbike

class Motorbike extends Model
{
    //
    protected $fillable = ['matriculation', 'number_motorbike', 'status'];
    etc...

Class Revision

class Revision extends Model
{
    //
    protected $fillable = ['date_revision_start', 'date_revision_end', 'garage', 'fk_motorbike'];

View Revision

<tr>
  <th>Date revision start</th>
  <th>Date revision end</th>
  <th>Garage</th>
  <th>Number motorbike</th>
  <th>Action</th>
</tr>
 </head>

  <body>

  @foreach($revisions as $revision)
 <tr>
  <td>{{ $revision->date_revision_start->format('d/m/Y') }}</td>
  <td>{{ $revision->date_revision_end->format('d/m/Y') }}</td>
  <td>{{ $revision->garage }}</td>
 <td>{{ $revision->motorbikes->number_motorbike }}</td>
<td>

Thank you for your help

29 Aug
3 weeks ago

david2000 started a new conversation Question Concerning A Planning

Hello,

I have a table named "Motorbike" with as fields (matriculation', 'number_motorbike', 'status').

I have another table named "Revision" with as fields ('date_revision_start', 'date_revision_end', 'garage', 'fk_motorbike').

The goal is that if the motorbike is under revision, it must be unavailable (automatically)...

it works almost ! So, the modificaiton of the status for the motorbike changes automatically only for the date "today"

But, for the date from 02/08/2019 to 06/08/2019 I have a problem. When, we will be, on 02/08/2019 or 06/08/2019 the status of the motorbike is always available... Normally, it must be unavailable.

Can you help me solve this problem?

$motorbikes = Motorbike::oldest()->paginate(5);
        
        $revisionId = Revision::where('date_revision_start', "<=" , Carbon::now())->where('date_revision_end', ">=", Carbon::now())->pluck('fk_motorbike')->toArray();

Thank you for your help.

28 Aug
3 weeks ago

david2000 started a new conversation Hour Start And Hour End For An Appointment

I am looking a way to create a form for an appointment, I have 2 fields so far, in format "string", is it correct according you?

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

I think the validation will be complicated?

Thank you for your help.

24 Aug
3 weeks ago

david2000 started a new conversation No Display

Hello,

For to be simple, I have 2 tables Students and Feedbacks.I also have 2 roles which are Admin and Member . There is only the administrator which can create several recordings. The member can just to connect and see his profil and his feedback.

Here is, the differents fields:

Class Student = 'user_id', 'name', 'firstname', 'date_birth', 'sex', 'address', 'fk_city', 'phone', 'email', 'status', 'fk_license', 'date_registration'

Class Feedback = 'user_id','instruction', 'description', 'fk_student'

Well !

The administrator creates 2 students, see below:

And a feedback here:

When, I login with the address email [email protected] I see my 2 rubrics: (Student profil and feedback)

I can consult my information in my profil

However, no display on my rubric Feedback. I don't know why ???

I think my problem must be in my function index() of my Controller Feedback.

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

    $feedbacks = Feedback::query()
    ->when($user->hasRole('admin') !== true, function (Builder $query) use ($user) {
        $query->whereHas('user', function ($query) use ($user) {
            $query->where('email', $user->email);
    });
    })
    ->when($request->has('search'), function (Builder $query) use ($request) {
     $query->join('students', 'feedbacks.fk_student', '=', 'students.id')->orderBy('students.name', 'asc')->where('students.name','like','%'.$request->input('search').'%');
     })
    ->paginate(5);

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

Thank you for your help.

23 Aug
4 weeks ago

david2000 left a reply on Column Not Found: 1054 Field (Field 'email' Unknown In Where)

@ftiersch : Almost.... I don't have of error message, (thank you a lot) my problem now is that my recording is not displayed.

22 Aug
4 weeks ago

david2000 left a reply on Column Not Found: 1054 Field (Field 'email' Unknown In Where)

Hello @ftiersch ,

I have tested but I always have an error message:

SQLSTATE [42S22]: Column not found: 1054 Unknown 'users.user_id' field in the where clause (SQL: select count (*) as aggregate from returns where exists

My problem is perhaps my relationships?

User.php

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

Feedback.php

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

Feedback Controller

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

    $feedbacks = Feedback::query()
    ->when($user->hasRole('admin') !== true, function (Builder $query) use ($user) {
        $query->whereHas('user', function ($query) use ($user) {
            $query->where('email', $user->email);
    });
    })
    ->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'));
}

Thank you for your help.

21 Aug
4 weeks ago

david2000 started a new conversation Recordings That Are Not Associated With The Logged In User

I have a table named 'Feedbacks' with 5 fields:

('id', 'user_id', 'instruction', 'description', 'fk_eleve')

The admin can create several recordings, here is a screenshot.(Rubric Feedback)

Here, I have a recording which is Menier Jeremy, it's the student (Rubric Student)

Here, Menier Jeremy has like email address [email protected].

Menier Jeremy wants to connect...

There are 2 rubrics for now: - Student Profil and Feedback

the user Menier Jeremy can see his profil

However, when the user wants to see his 'feedback'

I see all the records of my users, is it possible to keep only the user that is connected and hide other users?

Thank you for your help.

Here is an idea of my code...

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'));
}