adamjhn

adamjhn

Member Since 1 Year Ago

Experience Points 14,000
Experience Level 3

1,000 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 9
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.

09 Sep
11 months ago

adamjhn started a new conversation Undefined Property: Illuminate\Http\RedirectResponse::$organizer_id

Do you know if the user access an admin conference page like https://proj.test/conference/admin/10 for a conference id that dont exist it appear:

Undefined property: Illuminate\Http\RedirectResponse::$organizer_id

The error seems that is in the "AuthServiceProvider":

class AuthServiceProvider extends ServiceProvider
{
    
    public function boot(GateContract $gate)
    {
        $this->registerPolicies();

        $gate->define('access-management-area', function($user, $conference)
        {

           
            return $user->id == $conference->organizer_id;
        });
    }
}

06 Sep
11 months ago

adamjhn left a reply on Do You Know What Is Necessary To Replace {{user}} With The Content Of The Variable $participant->name?

It seems that str_replace accepts array as argument, but with:


 $participantContent = str_replace(array('{{user}}, {{conference}}'),
                                    array($participant->name, $conferenceName),
                                    $participant->registration_type->certificate->content);

is not working, it appears:

Hi {{user}} ({conference}}.

adamjhn left a reply on Do You Know What Is Necessary To Replace {{user}} With The Content Of The Variable $participant->name?

Do you know how, if the in the content besides {{user)} there is also {{conference}} how to also change the {{conference}} to the variable with the conference name "$conferenceName"?

This part should work

str_replace('{{conference}}', $conferenceName, $participant->registration_type->certificate->content);

But Im not understanding how to integrate that with the $participantContent and $content.

adamjhn started a new conversation Do You Know What Is Necessary To Replace {{user}} With The Content Of The Variable $participant->name?

I have a page where a user can create something like a certificate. First he selects a registration type through a radio button then there is a tinymce textarea. In this text area the user can introduce some content and click "Update" to associate the content of the textarea with the selected registration type. This is working.

Then I have a route for the user download the certificate in pdf:

Route::get('/certificateinfo/{regID}', [
    'uses' => '[email protected]',
    'as' => 'conferences.certificateInfo'
])

It works, when the user clicks in the button he gets the pdf. However, do you know how what is necessary to replace the certificate content {{user}} by the participant name? The participant name is available with "$participant->name".

The method to download the certificate pdf:

// get user certificate
public function getCertificateInfo($regID)
{
    $participants = Participant::where('registration_id', $regID)
        ->whereHas('registration_type', function ($query) {
            $query->where('certificate_available', 'Y');
        })
        ->with('registration_type.certificate')
        ->get();

    $content = '';
    foreach ($participants as $participant) {
        $content .=
            '<div style="page-break-inside: avoid; page-break-after: always;">
                ' . $participant->registration_type->certificate->content . '</div>';
    }

    $pdf = app()->make('dompdf.wrapper');
    $pdf->getDomPDF()->setBasePath(public_path());
    $content = str_replace('../../../', '', $content);
    $pdf->loadHTML($content);

    return $pdf->download('certificates.pdf');
}

adamjhn started a new conversation Do You Know How To Remove The Blank Pdf Page?

I have this code to show in each pdf page some info aobut each participant of a registration. There is the div "" so each participant info appears on a different pdf page. However if the foreach returns 2 participants the pdf has 3 pages instead of 2 and the third page is blank.

Do you know how to solve that issue?

@foreach($registration->conference->registrationTypes as $registrationType)
        @foreach($registrationType->participants as $participant)
            <li style="list-style: none">
                ...
            </li>
            <div class="next"></div>
        @endforeach
    @endforeach

CSS


div.next {
    page-break-inside: avoid;
    page-break-after: always;
}
05 Sep
11 months ago

adamjhn started a new conversation Query To Get The Last Registrations Is Not Working Properly

I have this query because I want to show in the conference management page some info in a table about the last 3 registrations in a specific conference (the name of the user that did the registration, the quantity of selected registration types and the value of the total prices of the selected registration types):


    <table>
        <thead>
        <tr>
            <th scope="col">User that did the registration</th>
            <th scope="col">Quantity</th>
            <th scope="col">Value</th>
        </tr>
        </thead>
        <tbody>
        @foreach($registrations as $registration)
            <tr>
                <td>{{ $registration->userName}}</td>
                <td>{{$registration->participants_count}}</td>
                <td>{{number_format($registration->totalPrice, 2)}}$</td>
            </tr>
        @endforeach
        </tbody>
    </table>

So there is the manage() method that gets some data and redirect the user to the conference management page with that above data:


     public function manage($id) // $id is the id of the conference
       ...
       $registrations = DB::table('registrations')
       ->join('participants', 'registrations.id', '=', 'participants.registration_id')
       ->join('users', 'users.id', '=', 'registrations.main_participant_id')
       ->join('registration_types', 'registration_types.id', '=', 'participants.registration_type_id')
       ->select(DB::raw('count(participants.registration_id) as participants_count, sum(registration_types.price) as totalPrice, users.name as userName, 
                registrations.created_at'))
      ->where('conferences.id',$conference->id)
      ->groupBy('registrations.id')->orderBy('created_at', 'desc')->get();
    
      dd($registrations)
      ....

      return view('conferences.manage')
             ->with('conference', $conference)
             ->with('registrations', $registrations)
             ->with(...);
        }

But its not working properly. When the conference management page is acessed it shows:


    SQLSTATE[42S22]: Column not found: 1054 Unknown column 'conferences.id' in 
    'where clause' (SQL: select count(participants.registration_id) as participants_count, 
    sum(registration_types.price) as totalPrice, 
    users.name as userName, registrations.created_at from `registrations` 
    inner join `participants` on `registrations`.`id` = `participants`.`registration_id`
    inner join `users` on `users`.`id` = `registrations`.`main_participant_id` 
     inner join `registration_types` on `registration_types`.`id` = `participants`.`registration_type_id` 
     where `conferences`.`id` = 1 
     group by `registrations`.`id`
      order by `created_at` desc)

Tables structure:

      Conferences: id, name, user_id, ...
      Registrations: id, conference_id, user_that_did_registration
      Registration_types: id, name, conference_id, price, ...
      Participants: id, name, surname, registration_type_id

04 Sep
11 months ago

adamjhn left a reply on How To Store The File Uploaded For A Dynamic Question Of Type File?

It shows that the question 4 has a file. But also shows that question 5 has a file but the question id 5 has the column type as "text".

adamjhn left a reply on How To Store The File Uploaded For A Dynamic Question Of Type File?

Yes, the questions table has the column "type" and " $request['answer'][$ticket][$nameKey]" is the question_id.

adamjhn left a reply on How To Store The File Uploaded For A Dynamic Question Of Type File?

Thanks, but for example the $request->all() shows:

"answer" => array:1 [▼
    18 => array:1 [▼
      1 => array:1 [▼
        4 => "pdftest.pdf"
      ]
    ]
  ]

The pdftest.pdf is the uploaded file for the dynamic question. What should be passed in the hasFile() method to detect that the answer array has 1 or more files as answers?

adamjhn started a new conversation How To Store The File Uploaded For A Dynamic Question Of Type File?

I have a form that can have dynamic questions of any type (text, checkbox, file, radio button, textarea). To store the answers to these questions there is this code:

    if (isset($request['answer'][$ticket][$nameKey])) {
        foreach ($request['answer'][$ticket][$nameKey] as $question_id => $answer) {
            $answer = Answer::create([
                'question_id' => $question_id,
                'user_id' => $user->id,
                'answer' => $answer,
            ]);
        }
    }

But like this if the dynamic question is of type file, is only storing in the answers table like:

    id      user_id        question_id         answer
    1           5                    1      pdftest.pdf

But the file is not being stored in any folder, is only stored the name in db. Do you know what is necessary to detect if its a question of type file? And if it is store the file in some folder so then is possible to access the file?

03 Sep
11 months ago

adamjhn started a new conversation Do You Know Why It Is Appearing "Trying To Get Property Of Non-object"?

I have a button that when is clicked should send for the email of the user a invoice:

    @if ($registration->status === 'C' && $registration->totalPrice > 0)
        <a href="{{route('conferences.sendInvoiceEmail', [
                'regID'=> $registration->id])}}">Send Invoice </a>
    @endif

Then the method to send has this part:

     public function sendInvoiceEmail($regID)
        {
            $client = new \GuzzleHttp\Client();
    
            $user = Auth::user();
    
            $registration = Registration::with('invoiceRow')->where("id", $regID)->first();
            $invoice = $registration->invoiceRow->invoice_number;
            ...
        }

But it appears the error "Trying to get property of non-object" in:

    $registration = Registration::with('invoiceRow')->where("id", $regID)->first();
    $invoice = $registration->invoiceRow->invoice_number;

Do you know what can be the issue?

The dd($registration) shows:

    Registration {#351 ▼
      ...
    }

The dd($invoice); shows "Trying to get property of non-object".

02 Sep
11 months ago

adamjhn left a reply on Creating Default Object From Empty Value - Associate The Certificate Content With All Registration Types

Thanks, like that dont appear any error but now even if the user click in the button:

 <button type="submit" formaction="{{route('certificates.update')}}" class="btn btn-primary btn">Update</button>

to update only the certificate associated with the selected registration type (selected radio buttton) all registration types are updated with the textarea certificate content.

adamjhn left a reply on Creating Default Object From Empty Value - Associate The Certificate Content With All Registration Types

Thanks, but is not initialised because is only necessary to update the certificate content with the textarea content, is not necessary to create a new certificate, so its not correct?

adamjhn left a reply on Creating Default Object From Empty Value - Associate The Certificate Content With All Registration Types

That is, if the user click in the button:

 <button type="submit" formaction="{{route('certificates.updateEqual')}}" class="btn-outline-primary btn">Update equal for all registration types</button>

it should update the certificate content equal for all registration types associated with the conference. But dont works, it shows "Creating default object from empty value".

If the user click in the "Update" button it should only update for the selected radio button ( selected registration type). This is working with the update() method.

 <button type="submit" formaction="{{route('certificates.update')}}" class="btn btn-primary btn">Update</button>

adamjhn left a reply on Creating Default Object From Empty Value - Associate The Certificate Content With All Registration Types

The code to associate the certificate with the selected radio button (selected registration type) works:

Route:


     Route::post('conference/{id}/certificates/update',
            ['uses' => '[email protected]', 'as' => 'certificates.update']);

Update method:

    public function update(Request $request){
        $rules = [
            'registrationType' => 'required',
            'certificate_content' => 'required',
        ];
    
        $customMessages = [
            'registrationType.required' => 'The field registration type is required.',
            'certificate_content.required' => 'The content field is required.'
        ];
    
        $this->validate($request, $rules, $customMessages);
    
        $registrationType = RegistrationType::where('id', $request->registrationType)->first();
        $certificate = $registrationType->certificate;
    
        if(!$certificate ) {
            $certificate = new Certificate();
        }
    
        $certificate->content = $request->certificate_content;
        $certificate->save();
    
        $registrationType->certificate_id = $certificate->id;
        $registrationType->save();
    
        $certificateContent = RegistrationType::with('certificate')->where('id', $request->registrationType)->first();
    
        $pdf = app()->make('dompdf.wrapper');
        Session::flash('success','Certificate configured with success for the selected registration type.');
        return redirect()->back();
    }

adamjhn started a new conversation Creating Default Object From Empty Value - Associate The Certificate Content With All Registration Types

I have a page where the user can associate certificates with registration types of a conference. In this page there are some radio buttons (each corresponds to a registration type) and a textarea, the user can select a radio button to select a registration type and then write some content in the textarea and click in "Associate certificate with the selected registrtation type" to associate the contentent in the textarea to the selected registration type. It works.

Doubt: But I also have a button "Associate certificate with all selected registrtation types" so that if the user select a registration type and enter some content on the text area and click in this button the same certificate content will be stored for all registration types associated with the conference. But in this case it appears the error Creating default object from empty value.

Code to associate the same certificate content with all registration types (shows "Creating default object from empty value" error ):

Route:


     Route::post('conference/{id}/certificates/updateEqual',
            ['uses' => '[email protected]', 'as' => 'certificates.updateEqual']);

Method updateEqual():


    public function updateEqual(Request $request){
        $rules = [
            'registrationType' => 'required',
            'certificate_content' => 'required',
        ];
    
        $customMessages = [
            'registrationType.required' => 'The field registration type is required.',
            'certificate_content.required' => 'The content field is required.'
        ];
    
        $this->validate($request, $rules, $customMessages);
        
        $registrationType = RegistrationType::where('event_id', $id)->get();


        foreach($registrationType as $rtype){

            // if no certificate exists for this type, create it
            if(!$rtype->certificate){
                $certificate = new Certificate();
            }
            $certificate->content = $request->certificate_content;
            $certificate->save();

            $rtype->certificate_id = $certificate->id;
            $rtype->save();

        }
         Session::flash('success','Certificate configured with success equal for all the registration type.');
    return redirect()->back();
    }

HTML

    <form id="edit_certificates" method="post" enctype="multipart/form-data">
        {{csrf_field()}}
        <div class="form-row">
            <div class="form-group col">
                <label for="registration_types">Certificate</label>
                <div class="hide-first">
                    @foreach($conference->registrationTypes as $registrationType)
                        <div class="form-check">
                            <input
                                    {{ (old('radiobutton') && old('radiobutton') == $rtype->id) ? 'checked' : '' }}
                                    class="form-check-input radio" type="radio" name="registrationType"
                                    value="{{ $registrationType->id }}" id="{{ $registrationType->id }}">
                            <label class="form-check-label" for="exampleRadios1">
                                Certificate for the registration type "{{ $registrationType->name}}"
                            </label>
                        </div>
                    @endforeach
                </div>
            </div>
        </div>
        <div class="form-group">
            <label for="exampleFormControlTextarea1">Certificate content</label>
            <textarea class="form-control" name="certificate_content" id="certificate_content" rows="3"></textarea>
        </div>
        <div class="float-right">
        <button type="submit" formaction="{{route('certificates.updateEqual')}}" class="btn-outline-primary btn">Update equal for all registration types</button>
        <button type="submit" formaction="{{route('certificates.update')}}" class="btn btn-primary btn">Update</button>
    </div>
    </form>
28 Aug
11 months ago

adamjhn left a reply on Why The Details Of A Registration Appears Incorrectly If The Same User Does More Than 1 Registration In Same Conference?

Thanks, can you explain how to use the unique() method in the getRegistrationInfo()?

   public function getRegistrationInfo($regID)
    {
        $registration = Registration::with('conference.registrationTypes.participants')
            ->find($regID);

        $pdf = PDF::loadView('pdf.registration', compact('registration'));
        return $pdf->download('invoice.pdf');

    }

Or is necessary to use the unique() in the blade file with PDF content?

@foreach($registration->conference->registrationTypes as $registrationType)
        @foreach($registrationType->participants as $participant)
            <li>
                ....

            </li>
        @endforeach
    @endforeach

adamjhn started a new conversation How To Show In The <td></td> Only Once Each Registration Type Associated With A Registration?

I have this to show the different registration types associated with a specific registration:

  <td> 
       {{ $registration->participants->map(function ($participant)
       { return $participant->registration_type->name; })->implode(', ') }}
   </td>

And it works. For example if the user does a registration in a conference and selected quantity 1 for the registration type "rt1" and 1 for registration type "rt2" it shows "rt1, rt2" in the . However, if the user does a registration in a conference and select quantity 2 for the registration type "rt1" it shows "rt1, rt1" in the . Do you know how to in this case show only once like "rt1"? That is, in the should only appear once each different registration type associated with a registration.

adamjhn started a new conversation Show The Price Range Only If The Conference Has More Than 1 Registration Type Associated

I have this to show the price range of a conference:

                    <span>{{$conference->price_range}}</span>

For example if the price of the conference is between 0 and 10 it appears "0$ - 10$".

For this I have in the Conference model the getPriceRangeAttribute():

    public function getPriceRangeAttribute() {
        return $this->registrationTypes()->get()->min('price') . '$ - ' . $this->registrationTypes()->get()->max('price').'$';
    }

Its working. However if a conference has only one registration type associated, and the the registration type has for example the price "10", the "{{$conference->price_range}}" shows "10$-10$".

Do you know how to, if the conference has only 1 registration type associated instead of show the price range like "10$-10$" show only "10$"?

adamjhn left a reply on Show "Free" If Price.max == 0 Or Price.min == 0

Thanks, but using:

+((price.max == 0 || price.min == 0) ? 'Free' : price.min)+

Also dont works, instead of appear "Free" it appears "".

adamjhn started a new conversation Show "Free" If Price.max == 0 Or Price.min == 0

I want to show "Free" if the max price (price.max) or min price (price.min) is "0". If price.max or price.min is not 0 it should appear the price.min. So I have this code below, but like that is not working properly. Do you know why?

    ' <span> '+(price.max == 0 || price.min == 0) ? 'Free' : price.min+'</span>\n'+

26 Aug
11 months ago

adamjhn left a reply on InvalidArgumentException The Values Under Comparison Must Be Of The Same Type

Thanks, but the error "InvalidArgumentException The values under comparison must be of the same type" still appear.

adamjhn started a new conversation InvalidArgumentException The Values Under Comparison Must Be Of The Same Type

I have a page for the user to update the registration types of a conference. For that the user select a registration type through a radio button, then the form fields are filled with the selected registration type info. Then the user can update the fields and click "Update".

Its working, but there is an issue. If the user selects a registration type (through the radio button) and the egistration_type_minimum and registration_type_maximum fields are empty and the user enters a value only for one of those two fields it appears:

InvalidArgumentException The values under comparison must be of the same type

If the user enters a value for the minimum and maximum the update works, the issue dont appears.

Do you know why?

<div class="form-row">
    <div class="form-group col-md-6">
        <label for="registration_type_minimum">Minimum</label>
        <input type="number" autocomplete="off" name="registration_type_minimum"
               value="{{old('registration_type_minimum')}}" class="form-control"
               id="registration_type_minimum" value="1" placeholder="(Ex: 1)">
    </div>
    <div class="form-group col-md-6">
        <label for="registration_type_maximum">Maximum</label>
        <input type="number" autocomplete="off" min="1" class="form-control"
               name="registration_type_maximum"
               value="{{old('registration_type_maximum')}}" id="registration_type_maximum"
               placeholder="(Ex: 2)">
    </div>
</div>

Update method:

public function update(Request $request, $id)
{
    $rules = [
        'registration_type_name' => 'required',
        'registration_type_capacity' => 'required|integer|min:0',
        'registration_type_price' => 'required|numeric|min:0',
        'registration_type_minimum' => 'required|integer|min:1',
        'registration_type_maximum' => 'gt:registration_type_minimum|required|integer|min:1',
    ];

    $customMessages = [
        ...
    ];

    $this->validate($request, $rules, $customMessages);

    $registrationTypeToUpdate = RegistrationType::find($request->radiobutton);
    $registrationTypeToUpdate->name = $request->registration_type_name;
    $registrationTypeToUpdate->description = $request->registration_type_description;
    $registrationTypeToUpdate->capacity = $request->registration_type_capacity;
    $registrationTypeToUpdate->price = $request->registration_type_price;
    $registrationTypeToUpdate->min_participants = $request->registration_type_minimum;
    $registrationTypeToUpdate->max_participants = $request->registration_type_maximum;

    $registrationTypeToUpdate->save();

    Session::flash('success', 'Registration type updated with success.');

    return redirect()->back();
}
25 Aug
11 months ago

adamjhn started a new conversation Why The Conference Img Dont Appear?

I have a autocomplete search form:

form class="main-search">
    <input type="text" id="search" class="autocomplete dropdown-toggle" placeholder="Conference, City">
</form>

If the user write for example "New" it will appear "Newcastle", if the user click in "Newcastle" it will show on the same page the conferences that have the column "city" as "Newcastle". And its working.

However the image of the conference is not appearing. If there is no image associated with a conference should appear a default image "5.png", if there are a image associated with the conference it should appear the image associated with the conference.

So there is the imageUrl in the jQuery that has :


let imageUrl = ! conference.image ? '/img/5.png' : conference.image;

But it is always appearing the default image "5.png" even when the the conference has a image. Do you know why?

Route:

Route::get('conferences/where/city/{slug?}', '[email protected]')->name('city.conferences');

Method:

public function getConferencesOfCity(Request $request)
{
    $query = Conference::query();
    if ($request->slug) {
        $query->where('city', $request->slug)->take(8)->orderBy('start_date', 'asc')->get();
    } else {
        $query->orderBy('start_date', 'desc')->take(8);
    }
    $conferences = $query->get();
    return response()->json($conferences);
}

jQuery:

$("#search").catcomplete({
    source: "{{ URL::to('autocomplete-search') }}",
    minLength: 2,
    response: function(conference, ui){
        if (!ui.content.length) {
            var noResult = { value:"", label:"No results for your serch." };
            ui.content.push(noResult);

        }
    },
    select: function(conference, ui) {
        if(ui.item.category=="Conferences"){
            window.location.href = ui.item.url;
        }
        else{
            $.get(ui.item.url, function(result) {
        
                var newConferences = '';
                let imageUrl = ! conference.image ? '/img/5.png' : conference.image;
                var placeholder = "{{route('conferences.show', ['id' => '1', 'slug' => 'demo-slug'])}}";

                $.each(result, function(index, conference) {
                    var url = placeholder.replace(1, conference.id).replace('demo-slug', conference.slug);
                    newConferences += '<div class="col-12 col-sm-6 col-lg-4 col-xl-3 mb-4">\n' +
'                        <div class="card box-shaddow">\n' +
'                            <img class="card-img-top" src='+ imageUrl +' alt="Card image cap">\n' +
'                            <div class="card-body">\n' +
'                                <h5>'+conference.name+'</h5>\n' +
'                                <p class="card-text font-size-sm"><i class="fa fa-map-marker" aria-hidden="true"></i> '+conference.place+', '+conference.city+'</p>\n' +
'                            </div>\n' +
'                    </div></div>';
                });
                // add the HTML to the #conferences div
                $('#conferences').html(newConferences);
            }, 'json');
        }
    }
});
23 Aug
11 months ago

adamjhn left a reply on Why Appear A Validation Error Saying The Date Format Is Invalid?

Thanks, I change in the server to " 'date' => 'nullable|date_format:"j-m-y - H:i"', " and in jquery to " format: 'dd-mm-yy - hh:ii', " and it works.

22 Aug
11 months ago

adamjhn started a new conversation Why Appear A Validation Error Saying The Date Format Is Invalid?

I have a date field like:

<div class="form-group col-md-6">
    <label for="date">Date</label>
    <div class="input-group date" data-provide="datepicker">
        <input type='text' onkeydown="event.preventDefault()"
               name="date" value="{{ old('date') }}" class="form-control"/>
    </div>
</div>

jQuery:

var date = new Date();
date.setDate(date.getDate());
$(".input-group.date").datetimepicker({
    format: "dd MM yyyy - hh:ii",
    autoclose: true,
    todayBtn: true,
    minuteStep: 5,
    startDate: date,
});

To insert in db first I have this code to valdiate:

     'date' => 'nullable|date_format:"d F Y - H:i"',

Then to insert:

        'date' => (isset(
$request->date)) ? Carbon::createFromFormat('d F Y - H:i', $request->date) : null,

But even if the user introduce a date using the datetime picker it shows always a validation error saying that the format of the date is invalid. Do you know why?

The "dd(date('d F Y - H:i'));" shows "22 July 2018 - 18:37" (shows in en).

The "$request->all()" shows "date" => "22 Juli 2018 - 19:50" (shows in german).

21 Aug
1 year ago

adamjhn left a reply on Why The Details Of A Registration Appears Incorrectly If The Same User Does More Than 1 Registration In Same Conference?

Thanks, the same user can do multiple registrations in a conference. But each button "Download registration details" to download the pdf should download only the details of that specific clicked registration.

So, each registration is a different registration even if the same user does multiple registrations in the same conference, each registration of the user is a different registration and should have its specific details in the pdf when the "Download registration details"is clicked for each list item (for each registration).

adamjhn started a new conversation Why The Details Of A Registration Appears Incorrectly If The Same User Does More Than 1 Registration In Same Conference?

If the user select quantity "1" for the registration type "general" and 1 for "plus" and click "Next" there is a registration form that will ask for the name and surname of both participants being registered. If the user fill the form like:

Name of participant 1:  Jake
Surname of participant1: W

Name of participant 2:  John 
Surname of participant 2: K

And click in "Register" the participant becomes registered in the conference.

Then I have a page with a list of users that did a registration in a conference like:

@foreach($conference->registrations as $registration)
    <tr>
        <td>{{$registration->customer->name}} {{$registration->customer->surname}}</td>
        <td>
            <a href="{{route('conferences.registrationInfo', ['regID'=> $registration->id])}}"
               class="btn">Download registration details <iclass="fa fa-file-pdf-o"></i>
            </a>
        </td>
    </tr>
@endforeach 

And each list item has a link "Download registration details" when this button is clicked it should download a pdf with a summary of that specific clicked registration.

If there is only 1 registration in the conference, with the details above (2 participants, Jake W registered in the registration type general and John K registered in the registration type plus), when the user click in the "Download registration details" is downloaded a pdf that shows 2 lists, each list has the details of each participant registered, so the pdf shows like:

pdf page 1

Conference name: conference 1
Participant: Jake W
Registration type: general

pdf page 2

Conference name: conference 1
Participant: John K
Registration type: plus

So its working fine, shows the correct results.

Issue: However if the same user does anothere registration in the same conference. For example the user select quantity "1" for the registration type "general" and introduce in the registration form like:

Name of participant 1:  Jake
Surname of participant1: W

And click in "Register".

Then, the same "Download registration details" link for the same registration, clicked before, downloads a pdf that instead of show the same two pdf pages above, shows 3 pdf pages repeating the page 1 twice, like:

pdf page 1:

Conference name: conference 1
Participant: Jake W
Registration type: general

pdf page 2:

Conference name: conference 1
Participant: Jake W
Registration type: general

pdf page 3:

Conference name: conference 1
Participant: John K
Registration type: plus


Do you know what can be the issue? Why is repeating the pdf page 1 twice? If in this registration there are only 2 participants registered not 3.

Route:

Route::get('/registrationinfo/{regID}', [
    'uses' => '[email protected]',
    'as' => 'conferences.registrationInfo'
]);

Method:

   public function getRegistrationInfo($regID)
    {
        $registration = Registration::with('conference.registrationTypes.participants')
            ->find($regID);


        $pdf = PDF::loadView('pdf.registration', compact('registration'));

        return $pdf->download('invoice.pdf');

    }

Blade file with pdf content:

@foreach($registration->conference->registrationTypes as $registrationType)
        @foreach($registrationType->participants as $participant)
            <li>
                <div class="wrapper">

                    <div>
                        <strong>Conference</strong>
                        <br> 
                        <span>{{ $registrationType->conference->name}}</span>
                    </div>                      

                    <div>
                        <div>
                            <strong>Registration Type</strong><br>
                            <span>{{$registrationType->name}}</span><br>
                        </div>
                    </div>

                    <div>
                        <strong>Participante</strong><br>
                        <span>{{$participant->name}} {{$participant->surname}}</span><br>

                    </div>

                    <div>
                        <strong>Price of registration type</strong><br>
                        <span>{{number_format($registrationType->price, 2)}}€</span><br>
                    </div>
                </div>

            </li>

            <div class="breakNow"></div>

        @endforeach
    @endforeach
18 Aug
1 year ago

adamjhn left a reply on How To Get The Info From The Array To Store In The Answers Table?

The $request['answer'] shows:

array:1 [▼
  1 => array:1 [▼
    1 => array:2 [▼
      1 => "answer1"
      2 => "answer2"
    ]
  ]
]

The $request['answer'][1] shows:

array:1 [▼
  1 => array:2 [▼
    1 => "answer1"
    2 => "answer2"
  ]
]

The $request['answer'][1][1] shows:

array:2 [▼
  1 => "answer1"
  2 => "answer2"
]

adamjhn left a reply on How To Get The Info From The Array To Store In The Answers Table?

Thanks, like that appear "Undefined offset: 4" in

               foreach ($request['answer'][$key][$nameKey] as $answerKey=> $answer) {

adamjhn left a reply on How To Get The Info From The Array To Store In The Answers Table?

In this above array example, the question id of the "answer1" is 1 and the id of the "answer2" is 2.

  "answer" => array:1 [▼
    1 => array:1 [▼
      1 => array:2 [▼
        1 => "answer1"
        2 => "answer2"
      ]
    ]

adamjhn started a new conversation How To Get The Info From The Array To Store In The Answers Table?

If the user is doing a registration in a conference, and is registering 1 participants in the registration type with id "1" (Jake K), and 1 participant in the regitration type with id "4" (John W), the request with the form data has this 3 arrays:

"name" => array:2 [▼
  1 => array:1 [▼
    1 => "Jake"
  ]
  4 => array:1 [▼
    1 => "John"
  ]
]
"surname" => array:2 [▼
  1 => array:1 [▼
    1 => "K"
  ]
  4 => array:1 [▼
    1 => "W"
  ]
]
"answer" => array:1 [▼
  1 => array:1 [▼
    1 => array:2 [▼
      1 => "answer1"
      2 => "answer2"
    ]
  ]
]

The array name that stores the name of the participant being registered in the registration_type_id "1" (Jake) and the name of the participant being registered in the registration_type_id "4" (John).

The same for the surname array, this surname array stores each surname for each registration type.

And the same for the answer array that stores each answer for each registration type. In this case only the registration type with id "1" has custom questions associated, so the answer array stores the answers answered to that custom questions.

To insert the registration info in the database, first is inserted in the registrations table like this and is working fine:


# user object
$user = Auth::user();
# add registration to Database
$registration = Registration::create([
    'conference_id' => $id,
    'user_that_did_registration' => $user->id,
]);

But then is necessary to insert in the participants table and in the answers table. Its inserting correctly in the participants table but for the answers table is not working:


foreach ($request->all()['name'] as $key => $nameArray) {
    foreach ($nameArray as $nameKey => $name) {
        $participant_result = Participant::create([
            'name'                 => $name,
            'surname'              => $request['surname'][$key][$nameKey],
            'registration_id' => $registration->id,
            'registration_type_id' => $key
        ]);

        # save answer to Database if exist
        $answer = Answer::create([
            'question_id' => $request['answer'][$key],
            'participant_id' => $participant_result->id,
            'answer' => $request['answer'][$key][$nameKey],
        ]);
    }
}

The issue is because the question_id and the answer are not showing the correct value with "$request['answer'][$key]" and "$request['answer'][$key][$nameKey]". Do you know how to properly get the question id and answer?

17 Aug
1 year ago

adamjhn started a new conversation Why Appears Always The Required Validation Error Message, Even If The User Fill The Required Field?

I have a registration form for a conference. But there is a issue in the validation of the form.

The user can be doing a registration in a registration type of a conference that have custom questions associated. If the user dont answer to a required custom question in the registration form, and the custom question is required, it should appear a validation error saying "Please answer to all required custom questions." However, the message appears always, even if the user fill all custom questions.

Do you know what can be the issue?

Validation code:

if (isset($request->participant_question_required)) {
    foreach ($request->participant_question_required as $key => $value) {

        $rule = '';
        // if this was required, ie 1, prepend "required|" to the rule
        if ($value) {
            $rule = 'required' . $rule;
        }

        // add the individual rule for this array key to the $rules array
        $rules["participant.{$key}.*.answer"] = $rule;

        $customMessages += [
            'participant.*.*.answer.required' => 'Please answer to all required custom questions.',
        ];
    }
}

The $request->all() of the registration from has the participant array like:

array:8 [▼
  "participant" => array:2 [▼
    1 => array:15 [▼
      "name" => "John"
      "surname" => "W"
      0 => array:1 [▼
        "answer" => "answer to question 1"
      ]
      1 => array:1 [▼
        "question_id" => "1"
      ]
      2 => array:1 [▼
        "answer" => "answer to question 2"
      ]
      3 => array:1 [▼
        "question_id" => "2"
      ]
      "rtypes" => "1"
    ]
    2 => array:3 [▼
      "name" => "Jake"
      "surname" => "K"
      "rtypes" => "4"
    ]
  ]
  "participant_question_required" => array:6 [▼
    0 => "1"
    1 => "1"
  ]
]

adamjhn left a reply on Type Error: Argument 1 Passed To Illuminate\Database\Grammar::parameterize() Must Be Of The Type Array, Integer Given

Thanks, something like:

foreach ($participants['participant'] as $k => $participant) {


            $name = $participant['name'];
            $surname = $participant['surname'];

            $participant_result = Participant::create([
                'name' => $name,
                'surname' => $surname,
                'registration_id' => $registration->id,
                'registration_type_id' => $participant['rtypes']
            ]);


            foreach ($participant['answer'] as $answer) {
                foreach ($participant['question_id'] as $questionID) {

                    # save answer to Database if exist
                    if (isset($participant['question_id'])) {
                        $answer = Answer::create([
                            'question_id' => $questionID,
                            'participant_id' => $participant_result->id,
                            'answer' => $answer,
                        ]);
                    }
                }
            }
        }

? But, it shows:

"SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'answer' at row 1 (SQL: insert into `answers` (`question_id`, `participant_id`, `answer`, `updated_at`, `created_at`) values (3, 14, {"question_id":"2","participant_id":14,"answer":{"question_id":"1","participant_id":14,"answer":"text answer","updated_at":"2018-08-17 15:18:17","created_at":"2018-08-17 15:18:17","id":1},"updated_at":"2018-08-17 15:18:17","created_at":"2018-08-17 15:18:17","id":2}, 2018-08-17 15:18:17, 2018-08-17 15:18:17)) ◀"


Do you know why?

adamjhn started a new conversation Type Error: Argument 1 Passed To Illuminate\Database\Grammar::parameterize() Must Be Of The Type Array, Integer Given

The $participants array has this structure:

array:1 [▼
  "participant" => array:2 [▼
    1 => array:5 [▼
      "name" => "John"
      "surname" => "W"
      "answer" => array:6 [▼
        0 => "text answer"
        1 => "long answer"
        2 => "check1"
        3 => "rb1"
        4 => "selectmenu1"
        5 => "img.jpg"
      ]
      "question_id" => array:6 [▼
        0 => "1"
        1 => "2"
        2 => "3"
        3 => "4"
        4 => "5"
        5 => "6"
      ]
      "rtypes" => "1"
    ]
    2 => array:3 [▼
      "name" => "Jake"
      "surname" => "K"
      "rtypes" => "4"
    ]
  ]
]

The foreach below is to store each participant and answer in the participants and answers table respectiveley. The code to store in the participants table its working fine. But then when the code enters in the part to store the answers in database it shows an error:

Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, integer given

foreach ($participants['participant'] as $k => $participant) {
    $name = $participant['name'];
    $surname = $participant['surname'];

    $participant_result = Participant::create([
        'name' => $name,
        'surname' => $surname,
        'registration_id' => $registration->id,
        'registration_type_id' => $participant['rtypes']
    ]);

    //dd($participant['question_id']);

    # store answer to Database if exist
    if (isset($participant['question_id'])) {
        $answer = Answer::create([
            'question_id' => $participant['question_id'],
            'participant_id' => $participant_result->id,
            'answer' => $participant['answer'],
        ]);
    }
}

The "dd($participant['question_id']);" shows:

array:6 [▼
  0 => "1"
  1 => "2"
  2 => "3"
  3 => "4"
  4 => "5"
  5 => "6"
]

adamjhn left a reply on How To Restructure The Array So Is Possible To Store Each Answer And Question_id In The Answers Table

Registration Form:

<form method="post" action="https://proj.test/conf/1/conf-test/registration/store">
  <h6>Participant - 1 - general</h6>

  <div class="form-group">
    <label for="namegeneral_1">Name</label>
    <input type="text" required id="namegeneral_1" name="participant[1][name]" class="form-control" value="">
  </div>

  <div class="form-group">
    <label for="surnamegeneral_1">Surname</label>
    <input type="text" required id="surnamegeneral_1" class="form-control" name="participant[1][surname]" value="">
  </div>

  <div class="form-group">
    <label for="participant_question">input text custom question</label>
    <input type='text' name='participant[1][][answer]' class='form-control' required>
    <input type="hidden" name="participant_question_required[]" value="1">
    <input type="hidden"  value="1" name="participant[1][][question_id]"/>
  </div>

  <div class="form-group">
    <label for="participant_question">long text custom question</label>
    <textarea name='participant[1][][answer]' class='form-control' rows='3' required></textarea>
    <input type="hidden" name="participant_question_required[]" value="1">
    <input type="hidden" value="2" name="participant[1][][question_id]"/>
  </div>

  <div class="form-group">
    <label for="participant_question">checkbox custom question</label>
    <div class='checkbox-group required'> 
      <div class='form-check'>
        <input type='checkbox' name='participant[1][][answer]' value='select1' class='form-check-input' >
        <label class='form-check-label' for='exampleCheck1'>check1</label>
      </div> 
      <div class='form-check'>
        <input type='checkbox' name='participant[1][][answer]' value='select2' class='form-check-input' >
        <label class='form-check-label' for='exampleCheck1'>check2</label>
      </div>
    </div>
    <input type="hidden" name="participant_question_required[]" value="1">
    <input type="hidden" value="3" name="participant[1][][question_id]"/>
  </div>

  <input type="hidden" name="participant[1][rtypes]" value="1"/>

  <h6>Participant - 2 - plus</h6>

  <div class="form-group">
    <label for="nameplus_2">Name</label>
    <input type="text" required id="nameplus_2" name="participant[2][name]" class="form-control" value="">
  </div>

  <div class="form-group font-size-sm">
    <label for="surnameplus_2">Surname</label>
    <input type="text" required id="surnameplus_2" class="form-control" name="participant[2][surname]" value="">
  </div>

  <input type="hidden" name="participant[2][rtypes]" value="4"/>

  <input type="submit" class="btn btn-primary" value="Register"/>
</form>

adamjhn started a new conversation How To Restructure The Array So Is Possible To Store Each Answer And Question_id In The Answers Table

If the user is doing a registration in a conference and selects quantity “1” for registration type general and “1” for registration type plus and click “Next” and goes to the registration form.

In the form, the user needs to introduce the name and surname for each participant this two fields are always mandatory for each participant being registered. Then, the registration type general has 3 custom questions associated with it, so for the registration type general the user also need to answer to that 3 custom questions. The questions and the answers answered by the user in the registration form were this:

Question                                  Answer
input text custom question                text answer
long text custom question:                long answer
checkbox custom question:                 check1answer

With the registration form below, and with the answers above, the participant array in the $request->all() shows like below. The name, surname, rtypes is stored properly but the answers and question_id are not be stored very properly in the array:

       "participant" => array:2 [▼
        1 => array:15 [▼
          "name" => "John"
          "surname" => "W"
          0 => array:1 [▼
            "answer" => "text answer"
          ]
          1 => array:1 [▼
            "question_id" => "1"
          ]
          2 => array:1 [▼
            "answer" => "long answer"
          ]
          3 => array:1 [▼
            "question_id" => "2"
          ]
          4 => array:1 [▼
            "answer" => "check1answer"
          ]
          5 => array:1 [▼
            "question_id" => "3"
          ]
          "rtypes" => "1"
        ]
        2 => array:3 [▼
          "name" => "Jake"
          "surname" => "K"
          "rtypes" => "4"
        ]
      ]

With the data stored like that using this foreach to insert the participants and the answers in the database shows "Undefined index: answer" in $participant['answer']:

foreach ($participants_list as $participant) {

    $name = $participant['name'];
    $surname = $participant['surname'];

    $participant_result = Participant::create([
         'name' => $name,
         'surname' => $surname,
         'registration_type_id' => $participant['rtypes']
    ]);

    Answer::create([
        'participant_id' => $participant_result->id,
        'answer' => $participant['answer'],
        'question_id' => $participant['question_id']
    ]);
}

Do you know to strucutre the array so solve the issue? So is possible to store correctly the answers of each participant in the answers table?

The $participant[0]['answer'] shows "text answer".
The $participant[1]['answer'] shows "undefined index answer".
The $participant[2]['answer'] shows "long answer".
The $participant[3]['answer'] shows "undefined index answer".
16 Aug
1 year ago

adamjhn left a reply on How To Store The Answers For Each Participant In The Array? (so Is Possible To Introduce Them In The Answers Table)

With "participant[{{$counter}}][][question_id]" for the question_id like:


 <input type="hidden" value="{{ $customQuestion->id }}" name="participant[{{$counter}}][][question_id]"/>

The pariticpant array stays like:

       "participant" => array:2 [▼
        1 => array:15 [▼
          "name" => "John"
          "surname" => "W"
          0 => array:1 [▼
            "answer" => "text answer"
          ]
          1 => array:1 [▼
            "question_id" => "1"
          ]
          2 => array:1 [▼
            "answer" => "long answer"
          ]
          3 => array:1 [▼
            "question_id" => "2"
          ]
          4 => array:1 [▼
            "answer" => "check1"
          ]
          5 => array:1 [▼
            "question_id" => "3"
          ]
          6 => array:1 [▼
            "answer" => "rb1"
          ]
          7 => array:1 [▼
            "question_id" => "4"
          ]
          8 => array:1 [▼
            "answer" => "selectmenu1"
          ]
          9 => array:1 [▼
            "question_id" => "5"
          ]
          10 => array:1 [▼
            "answer" => "img.png"
          ]
          11 => array:1 [▼
            "question_id" => "6"
          ]
          "rtypes" => "1"
        ]
        2 => array:3 [▼
          "name" => "Jake"
          "surname" => "K"
          "rtypes" => "4"
        ]
      ]

But in the foreach appears "undefined index: answer" in $participant['answer']":

    foreach ($participants_list as $participant) {

        $name = $participant['name'];
        $surname = $participant['surname'];

        $participant_result = Participant::create([
             'name' => $name,
             'surname' => $surname,
             'registration_id' => $registration->id,
             'registration_type_id' => $participant['rtypes']
        ]);


        Answer::create([
            'participant_id' => $participant_result->id,
            'answer' => $participant['answer'],
            'question_id' => $participant['question_id']
        ]);
    }

Using $participant[0]['answer'] shows "text answer".
Using $participant[1]['answer'] shows "undefined index answer".
Using $participant[2]['answer'] shows "long answer".
Using $participant[3]['answer'] shows "undefined index answer".

So Im not understanding how to use the foreach and store correctly each answer of each participant. Do you know how to properly achieve that?

adamjhn left a reply on How To Store The Answers For Each Participant In The Array? (so Is Possible To Introduce Them In The Answers Table)

Maybe needs to be with "name='participant[1][][answer]'". Like this the participants array shows like:



"participant" => array:2 [▼
    1 => array:10 [▼
      "name" => "John"
      "surname" => "W"
      0 => array:1 [▼
        "answer" => "text answer"
      ]
      "question_id" => "6"
      1 => array:1 [▼
        "answer" => "long answer"
      ]
      2 => array:1 [▼
        "answer" => "checkbox1"
      ]
      3 => array:1 [▼
        "answer" => "rbutton1"
      ]
      4 => array:1 [▼
        "answer" => "select menu1"
      ]
      5 => array:1 [▼
        "answer" => "img.png"
      ]
      "rtypes" => "1"
    ]
    2 => array:3 [▼
      "name" => "Jake"
      "surname" => "K"
      "rtypes" => "4"
    ]
  ]

But the question_id only appears once, do you know why? Because like that is not possible to insert correctly in the answers table:

Answer::create([
        'participant_id' => $participant_result->id,
        'answer' => $participant['answer'],
        'question_id' => $participant['question_id']
    ]);

adamjhn left a reply on How To Store The Answers For Each Participant In The Array? (so Is Possible To Introduce Them In The Answers Table)

Thanks really, but I change to that, so now the inputs are like:

<div class="form-group">
  <label for="participant_question">input text question </label>

  <input type='text' name='participant[answer][1]' class='form-control' required>
  <input type="hidden"
         name="participant_question_required[]"
         value="1">
  <input type="hidden"
         value="1"
         name="participant[1][question_id]"/>
</div>

But the participants array still is incorrect:


"participant" => array:3 [▼
    1 => array:4 [▼
      "name" => "John"
      "surname" => "W"
      "question_id" => "6"
      "rtypes" => "1"
    ]
    "answer" => array:1 [▼
      1 => "img.png"
    ]
    2 => array:3 [▼
      "name" => "Jake"
      "surname" => "K"
      "rtypes" => "4"
    ]
  ]

Before the array was (as it is in the previous comment):

"participant" => array:3 [▼
    1 => array:5 [▼
      "name" => "John"
      "surname" => "W"
      "answer" => "img.png"
      "question_id" => "6"
      "rtypes" => "1"
    ]
    " 1" => array:1 [▼
      "answer" => "select menu1"
    ]
    2 => array:3 [▼
      "name" => "Jake"
      "surname" => "K"
      "rtypes" => "4"
    ]
  ]


adamjhn left a reply on How To Store The Answers For Each Participant In The Array? (so Is Possible To Introduce Them In The Answers Table)

For example the user selects quantity "1" for registration type "general" and "1" for registration type "plus" and click "Next" and goes to the registration form.

In the form, the user needs to introduce the name and surname for each participant.

Then relative to the custom questions, the registration type "plus" has id 4 in DB and dont have any question associated. So its ok.

The registration type "general" has id 1 in DB and it has 6 custom questions associated with it. The questions and the answers answered by the user in the registration form were:

Question                           Answer
input text question           text answer
long text question:            long answer
select menu question:     select menu 1
checkbox question:          check1
file question:                      img.png
radio question:                  rb1

With the registration form as it is, the participants array in the $request->all() with the data above shows like below. The name, surname, rtypes is stored properly but the answers are not be stored properly in the array. So is not possible to use that approach because the array is not storing the answers properly. My doubt is in this part, how to properly store in the array so that is possible to store in the answers table.

  "participant" => array:3 [▼
    1 => array:5 [▼
      "name" => "John"
      "surname" => "W"
      "answer" => "img.png"
      "question_id" => "6"
      "rtypes" => "1"
    ]
    " 1" => array:1 [▼
      "answer" => "select menu1"
    ]
    2 => array:3 [▼
      "name" => "Jake"
      "surname" => "K"
      "rtypes" => "4"
    ]
  ]

adamjhn left a reply on How To Store The Answers For Each Participant In The Array? (so Is Possible To Introduce Them In The Answers Table)

Thanks, I know that, I use that, in the question I have that to insert each participant details in the participants table:

#add all participants to Database
        foreach ($participants_list as $participant) {

            $name = $participant['name'];
            $surname = $participant['surname'];
            $participant_result = Participant::create([
                'name' => $name,
                'surname' => $surname,
                'registration_id' => $registration->id,
                'registration_type_id' => $participant['rtypes']
            ]);
       ...

My doubt is how to get the answers in the array so that is possible to use that same approach to store the answers in the answers table. But my doubt is how to properly collect the answers that the user answered for each participant.

adamjhn left a reply on How To Store The Answers For Each Participant In The Array? (so Is Possible To Introduce Them In The Answers Table)

Images to explain better the context:

This image shows the registration form, in this case the registration type general has only 1 custom question associated (Phone), so this question will appear twice because it was selected "2" for the registration type "general": https://ibb.co/f3Y3vz

This image shows how the database should stay based on the registration form image above: https://ibb.co/jXgTTK

adamjhn left a reply on How To Store The Answers For Each Participant In The Array? (so Is Possible To Introduce Them In The Answers Table)

Method in the controller to store the registration:

 public function storeRegistration(Request $request, $id, $slug = null)
    {
        # user object
        $user = Auth::user();

        # add registration to Database
        $registration = Registration::create([
            'conference_id' => $id,
            'user_that_did_registration' => $user->id,
        ]);

        # List of all participants
        $participants_list = $request->get('participant');

        #add all participants to Database
        foreach ($participants_list as $participant) {

            $name = $participant['name'];
            $surname = $participant['surname'];
            $participant_result = Participant::create([
                'name' => $name,
                'surname' => $surname,
                'registration_id' => $registration->id,
                'registration_type_id' => $participant['rtypes']
            ]);

            # save answer to Database if exist
            if (isset($participant['question_id'])) {
                $answer = Answer::create([
                    'question_id' => $participant['question_id'],
                    'participant_id' => $participant_result->id,
                    'answer' => $participant['answer'],
                ]);
            }
        }

        
        Session::flash('registration_success', 'You are registered');
        return redirect(route('user.index', ['user' => Auth::id()]) . '#myTickets');
    }

adamjhn left a reply on How To Store Each Participant Info, That Appear In The $request->all() Output, In The Participants Table?

I created some days ago a question in which the structure is more similar like you have https://laracasts.com/discuss/channels/laravel/how-to-store-the-answers-of-custom-questions-for-each-participant-in-the-participants-array. But like that it seems that is not possible to store the answers to the questions so I was looking to structure the info in a different way.

adamjhn left a reply on How To Store Each Participant Info, That Appear In The $request->all() Output, In The Participants Table?

My doubt is how to properly get the name, surname and answers to custom questions for each participant, so is possible to introduce all info in DB.

As it is in the question if the user is doig a registration and select quantity 1 for registration type "general" and 1 for the registration type "plus" and click "Next" goes to the registration page where there is the registration form. Since the registration type "general" has 2 questions associated and the registration type "plus" has 0 questions associated, the form will be like:

  <form method="post"
        action="https://proj.test/conference/1/conference-test/registration/storeRegistration">


    <h6> Participant - 1 - general</h6>


    <div class="form-group">
      <label for="namegeral_1"
             class="text-gray">Name <span class="text-primary">*</span></label>
      <input type="text" required  id="namegeral_1"
             name="rname[1][1]"
             class="form-control" value="">
    </div>
    <div class="form-group">
      <label for="surnamegeral_1"
             class="text-gray">Surname <span class="text-primary">*</span></label>
      <input type="text" required  id="surnamegeral_1"
             class="form-control"
             name=" rsurname[1][1]" value="">
    </div>

    <div class="form-group">
      <label for="participant_question">Question 1 of type text </label>
      <input type='text' name='answer[1][1][1]' class='form-control' required>
      <input type="hidden" name="question_required[1][1]" value="1">
    </div>

    <div class="form-group">
      <label for="participant_question">Question 2 of type long text</label>
      <textarea name='answer[1][1][2]' class='form-control' rows='3' required></textarea>
      <input type="hidden" name="question_required[1][2]" value="1">
    </div>


    <input type="hidden" name="participant[1][rtypes]"value="1"/>



    <h6> Participant - 1 - plus</h6>

    <div class="form-group">
      <label for="nameplus_1"
             class="text-gray">Name</label>
      <input type="text" required  id="nameplus_1"
             name="rname[4][1]"
             class="form-control" value="">
    </div>
    <div class="form-group">
      <label for="surnameplus_1"
             class="text-gray">Surname</label>
      <input type="text" required  id="surnameplus_1"
             class="form-control"
             name=" rsurname[4][1]" value="">
    </div>


    <input type="hidden" name="participant[1][rtypes]"  value="4"/>
    <input type="submit" class="btn btn-primary" value="Register"/>

  </form>


So I structured the form like this, and the $request->all shows like its in the question:

array:12 [▼
  "name" => array:2 [▼
    1 => array:1 [▼
      1 => "Jake"
    ]
    4 => array:1 [▼
      1 => "John"
    ]
  ]
  "surname" => array:2 [▼
    1 => array:1 [▼
      1 => "W"
    ]
    4 => array:1 [▼
      1 => "K"
    ]
  ]
  "answer" => array:1 [▼
    1 => array:1 [▼
      1 => array:6 [▼
        1 => "custom question 1 answer"
        2 => "custom question 2 answer"
      ]
    ]
  ]
  "question_required" => array:1 [▼
    1 => array:6 [▼
      1 => "1"
      2 => "1"
    ]
  ]
]


My doubt is how to properly get the name, surname and answers to custom questions for each participant, so is possible to introduce all info in DB.

I already have the code to store the registration:

 $user = Auth::user();
$registration = Registration::create([
            'conference_id' => $id,
            'user_that_did_registration' => $user->id,
        ]);

But after store the registration is also necessary to insert all participants (name, surname, registration_type_id) being registered in the participants table. Based on the $request->all output above the participants table should stay like (the registration_id comes from the $registration = Registration::create above):

id        name              surname       registration_type_id    registration_id
 1           Jake                   W              1                        1
2            John                 K                4                       1

Then is also necessary to insert in answers table the question_id, participant_id and the answer. Based on the $request->all output above the answers table should stay like

id     participant_id  question_id  answer
1           1                   1    custom question 1 answer
2          1                   2    custom question 2 answe
   

adamjhn left a reply on How To Store Each Participant Info, That Appear In The $request->all() Output, In The Participants Table?

Thanks, the issue is that each registration type can have custom questions associated so is necessary to store the answers to that custom questions.

For example in my question example the registration type "general" has two questionas associated so in the form it appear the 2 custom questions and the user introduce for the first question "custom question 1 answer" and for the second question "custom question 2 answer". With your solution maybe is not possible to store the answers associated with each participant.

"answer" => array:1 [▼
    1 => array:1 [▼
      1 => array:6 [▼
        1 => "custom question 1 answer"
        2 => "custom question 2 answer"
      ]
    ]
  ]

Because is necessary to store the participants name surname and the registration_type_id where each participant is being registered in the participants table. But its also necessary to introduce in the answers table the answers for each participant.

The structure of the anwers table: id, question_id, participant_id and answer.

adamjhn started a new conversation How To Store Each Participant Info, That Appear In The $request->all() Output, In The Participants Table?

If a conference has two registration types "general" and "plus", and the user is doing a registration, and selects the quantity 1 for the registration type "general" and 1 for the registration type "plus" and click "Next" he goes to the registration page.

In the registration page the user needs to fill for the participant being registered in the registration type "general" the name, surname and also the registration type "general" has associated with it 2 custom questions, so the user also needs to answer to this two custom questions.

For the participant being registered in the registration type "plus" the user only needs to introduce the name and surname because the registration type "plus" dont have custom questions associated.

So after the user fill in the form and click "Register" the $request->all() shows like below (1 is the id of the registration type "genera" and 4 is the id of the registration type "plus"):

array:12 [▼
  "name" => array:2 [▼
    1 => array:1 [▼
      1 => "Jake"
    ]
    4 => array:1 [▼
      1 => "John"
    ]
  ]
  "surname" => array:2 [▼
    1 => array:1 [▼
      1 => "W"
    ]
    4 => array:1 [▼
      1 => "K"
    ]
  ]
  "answer" => array:1 [▼
    1 => array:1 [▼
      1 => array:6 [▼
        1 => "custom question 1 answer"
        2 => "custom question 2 answer"
      ]
    ]
  ]
  "question_required" => array:1 [▼
    1 => array:6 [▼
      1 => "1"
      2 => "1"
    ]
  ]
]

The participants table has the structure below:

Participants table columns: id, registration_id, registration_type_id, name, surname

My doubt is how to properly store the participants in the participants table. More specifically, Im not understanding how to get the participant name and surname and also the registration_type_id for each participant. For example in the below part of the $request->all() result the 1 is the the id of the registration type "general" and 4 is the id of the registration type "plus".

"name" => array:2 [▼
    1 => array:1 [▼
      1 => "Jake"
    ]
    4 => array:1 [▼
      1 => "John"
    ]
  ]

So it should be necessary to have a foreach to foreach the array and store each participant like below, but do you know how to get the correct name, surname and registration_type_id of each participant based on the $request->all() result above?

 foreach ($participants as $participant) {
        $name = $participant['name'];
        $surname = $participant['surname'];
        $participant_result = Participant::create([
            'name' => $name,
            'surname' => $surname,
            'registration_id' => $registration->id, // I already have this
            'registration_type_id' => $participant['rtypes']
        ]);
}
15 Aug
1 year ago

adamjhn left a reply on Why It Appears Always 0.00 In The Registration_type_price Form Field?

But the

document.getElementById("show_price").onblur = function () {
    
            var $price = document.getElementById("registration_type_price");
    
            $price.value = this.value;
            this.value = parseFloat(this.value.replace(/,|\€/g, ""))
                .toFixed(2)
                .toString()
                .replace(/\B(?=(\d{3})+(?!\d))/g, ".");
        }

is not in " $("input[name='radiobutton']").click(function () {.... });".

adamjhn left a reply on Why It Appears Always 0.00 In The Registration_type_price Form Field?

Thanks, with code below with "registration_type_price" instead of "show_price" shows 5 instead of 0.00:

<div class="form-group col-md-6">
    <label for="registration_type_price">Price <span
                class="text-primary">*</span></label>
    <input type="hidden" name="registration_type_price"
           id="registration_type_price"/>
    <input type="number"
           onkeydown="javascript: return event.keyCode == 69 ? false : true"
           min="0" step="any"
           class="form-control"
           value="{{ old('registration_type_price', '0.00') }}"
           name="registration_type_price" id="registration_type_price" placeholder="Price (Ex: 15,00)"/>
</div>