adamjhn

Experience

14,000

0 Best Reply Awards

  • Member Since 5 Months Ago
  • 9 Lessons Completed
  • 0 Favorites

9th September, 2018

adamjhn started a new conversation Undefined Property: Illuminate\Http\RedirectResponse::$organizer_id • 1 week ago

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

6th September, 2018

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

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? • 2 weeks ago

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 left a reply on Do You Know What Is Necessary To Replace {{user}} With The Content Of The Variable $participant->name? • 2 weeks ago

For example if in the text area the user introduces Hi {{user}} in the certificates table the content is introduced like:

<p>Hi {{user}}.</p>

Then do you know how to change {{user}} with the $participant->name in the getCertificateInfo()?

adamjhn started a new conversation Do You Know What Is Necessary To Replace {{user}} With Another Text? • 2 weeks ago

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 is like this:

// 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? • 2 weeks ago

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

5th September, 2018

adamjhn left a reply on Query To Get The Last Registrations Is Not Working Properly • 2 weeks ago

Relevants tables structure:

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

adamjhn left a reply on Query To Get The Last Registrations In A Specific Conference Is Not Working • 2 weeks ago

Then the code to show the last registrations in the conference management page:

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

adamjhn started a new conversation Query To Get The Last Registrations In A Specific Conference Is Not Working • 2 weeks ago

I have this query because I want to show in the conference management page the last 3 registrations in that specific conference:

    // redirect to conference management area
    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'))
                    ->groupBy('users.name', 'registrations.id')->limit(3)->orderBy('created_at', 'desc')->get();
    }

But its not working properly. For all created conferences the dd($registrations) shows always "3". Without "->limit(3)" shows alwys "16" that are total number of entries in the registrations table.

Do you know where is the issue? Why is returning all registrations in all conferences instead of returning only the last 3 registrations of a specific conference?

4th September, 2018

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

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

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

Yes, the questions table has the column "type".

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

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?

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

Thanks but it seems that is not working. The $request->all() shows:

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

But the code dont show the 'test':

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,
        ]);
    }
   
    if ($request->hasFile('answer')) {
        dd('test');
    }
}

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

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?

3rd September, 2018

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

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

2nd September, 2018

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

Thanks, the foreaach is only in the updateEqual() that is called when the button:

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

is clicked.

But if the button clicked is:

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

it should only update for the selected registration type (for the selected radio button).

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

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 • 2 weeks ago

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 • 2 weeks ago

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.

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

The code to associate the certificate with the selected registrtation 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 left a reply on Missing Required Parameters For [Route: Certificates.updateEqual] • 2 weeks ago

And the form is like:

<form id="edit_certificates" method="post" action="{{route('certificates.update', ['conference_id' => $conference->id])}}" enctype="multipart/form-data">
    {{csrf_field()}}
    ...
    <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>

adamjhn started a new conversation Missing Required Parameters For [Route: Certificates.updateEqual] • 3 weeks ago

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.

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 it shows:

Missing required parameters for [Route: certificates.updateEqual] [URI: conference/{id}/certificates/updateEqual] in the index.blade.php file. Do you know why?

So, I have a route to associate a certificate content with a registration type:


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

But I create other route for the button "Associate certificate with all selected registrtation types":
        Route::post('conference/{id}/certificates/updateEqual',
        ['uses' => '[email protected]', 'as' => 'certificates.updateEqual']);

And the form is like:

<form id="edit_certificates" method="post" action="{{route('certificates.update', ['conference_id' => $conference->id])}}" 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>

28th August, 2018

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? • 3 weeks ago

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

    }

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

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 • 3 weeks ago

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 • 3 weeks ago

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 • 3 weeks ago

I want to show "Free" if the max price (price.max) or min price (price.min) is "0". 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'+

27th August, 2018

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? • 3 weeks ago

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

26th August, 2018

adamjhn left a reply on InvalidArgumentException The Values Under Comparison Must Be Of The Same Type • 3 weeks ago

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 • 3 weeks ago

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" class="text-heading h6 font-weight-semi-bold">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" class="text-heading h6 font-weight-semi-bold">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();
}

25th August, 2018

adamjhn started a new conversation Why The Conference Img Dont Appear? • 4 weeks ago

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

23rd August, 2018

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

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.

22nd August, 2018

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

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

21st August, 2018

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? • 1 month ago

Thanks, the issue is that if the same user do another registration in the conference he should have 2 tickets (2 pdfs with the registration details )and each ticket should have the info of that specific registration. Each registration should have only the info of that registration, the info of the participants associated with that specific registration.

For example when the user does a second registration in the same conference only with 1 participant the ticket with the registration details should only have the info of that participant because its what that registration have (only 1 participant). However, because the user already has a previous registration with 2 participants all tickets shows the same info and all have the registration details with 3 participants.

But one ticket (one pdf) should have only 1 participant and the other should have 2 participants.

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? • 1 month ago

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:

List 1:

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

List 2:

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

So its working fine, shows the correct results.

Issue: However if the 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 lists above, shows 3 lists repeating the list 1 twice, like:

List 1:

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

List 2:

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

List3:

Conference name: conference 1
Participant: John K
Registration type: plus
Do you know what can be the issue? Why is repeating the list 1 twice? If in this registration there are only 2 participants 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

18th August, 2018

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

The $request['answer'] shows:

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

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

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

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

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

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

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? • 1 month ago

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 left a reply on How To Properly Get The Info From The Array? • 1 month ago

Like this it seems that is possible to store the name and surname of each participant. But how to get the registration_type_id?

foreach ($request->all()['name'] as $key => $name) {
            
            $participant_result = Participant::create([
                'name' => $name[1],
                'surname' => $request['surname'][$key][1],
                'registration_id' => $registration->id,
                'registration_type_id' => how to get this???
            ]);

        }

The registration_tpye_id for the participant Jake is "1" and for John is "4" as it is in the array:

"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"
        ]
      ]

adamjhn started a new conversation How To Properly Get The Info From The Array? • 1 month ago

After a user fill a form to register two participants in the conference and click in "Register", the $request->all() has these arrays:

"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 => "answer1"
            2 => "answer2"
          ]
        ]
      ]

  • The array name stores the name of the participant being registered in the registration type with id 1 (name Jake) and the name of the participant being registered in the registration type with id 4 (name John)

  • The array surname stores the surname of the participant being registered in the registration type with id 1 (surname W) and the name of the participant being registered in the registration type with id 4 (surname K)

  • The answer array: stores the answers associated with the registration type with id 1 which has 2 custom questions associated with it, so the answers array stores the values that the user who is doing the registration, answered to these custom questions in the registration form. The registration type with id 4 doesn't have any custom question associated with it, so it doesn't have an answer array.

Doubt: My doubt is how to get the info from this array structure above in order to store each participant in the participants table.

With the array content above the participants table should stay like:

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

Do you know how to properly achieve that?

I have the code below that first insert the registration in the database:

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

But then do you know how to properly get the necessary info from the above array to store in the participants table? To insert in the participants table it is necessary to use:

$participant_result = Participant::create([
      'name' => how to get the name of each participant from the array?,
      'surname' => how to get the surname of each participant from the array?,
      'registration_id' => $registration->id,
      'registration_type_id' => how to get the registration_type_id from the array?
  ]);

17th August, 2018

adamjhn left a reply on Do You Know Why The Required Validation Rule Is Not Working? • 1 month ago

The HTML of the name and surname fields are like this:

 <div class="form-group">
   <label for="name{{ $k }}_{{ $counter }}">Name</label>
   <input type="text" required id="name{{ $k }}_{{ $counter }}" name="participant[{{$counter}}][name]" class="form-control" value="">
</div>
<div class="form-group">
    <label for="surname{{ $k }}_{{ $counter }}">Surname</label>
    <input type="text" required id="surname{{ $k }}_{{ $counter }}" class="form-control" name="participant[{{$counter}}][surname]" value="">
</div>

The HTML of the custom questions fields is like this:

 <input type='text' name='participant[" . $k . "][][answer]' class='form-control'" . ($required ? " required" : "")>

adamjhn started a new conversation Do You Know Why The Required Validation Rule Is Not Working? • 1 month ago

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

The validation of the participant name and surname is working fine, if the user dont fill the name or surname fields it appear the validation error saying that these fields are required, using the following $rules and $customMessages:

$rules = [
    'participant.*.name' => 'required',
    'participant.*.surname' => 'required',
];
$customMessages = [
    'participant.*.name.required'    => 'The field name is mandatory.',
    'participant.*.surname.required' => 'The field surname is mandatory.'
];

However, to validate the custom questions fields is not working, if the user dont answer to a required custom question the validation error dont appears and the registration info is inserted in DB, but it should not. The code to validate the custom questions:

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

        if ($value) {
            $rule = 'required' . $rule;
        }

        $rules["participant.*.*.answer.{$key}"] = $rule;

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

Do you know why is not validating?

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"
  ]
]

The HTML of the name and surname fields are like this:

 <div class="form-group">
   <label for="name{{ $k }}_{{ $counter }}">Name</label>
   <input type="text" required id="name{{ $k }}_{{ $counter }}" name="participant[{{$counter}}][name]" class="form-control" value="">
</div>
<div class="form-group">
    <label for="surname{{ $k }}_{{ $counter }}">Surname</label>
    <input type="text" required id="surname{{ $k }}_{{ $counter }}" class="form-control" name="participant[{{$counter}}][surname]" value="">
</div>

The HTML of the custom questions fields is like this:

 <input type='text' name='participant[" . $k . "][][answer]' class='form-control'" . ($required ? " required" : "")>

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

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,
                        ]);
                    }
                }
            }
        }

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)) ◀"


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

I have this $participants array with 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"
    ]
  ]
]

And I want to store each participant and answer in the participants and answers table respectiveley. So I have the foreach below 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 Help In Restrucruting An Array So Is Possible To Store Each Answer And Question_id In The Answers Table • 1 month ago

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][regtypes]" 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][regtypes]" value="4"/>

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

adamjhn started a new conversation Help In Restrucruting An Array So Is Possible To Store Each Answer And Question_id In The Answers Table • 1 month ago

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, regtypes is stored properly but the answers are not be stored 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['regtypes']
]);

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


16th August, 2018

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) • 1 month ago

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"
    ]
  ]

Do you know if like that is correct to use in the foreach?

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

    // create the answer (or however you need it)
    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) • 1 month ago

Yes, this is correct, can exist multiple questions for the same participant that is being registered in a registration type with that multiple questions.

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) • 1 month ago

Maybe needs to be with "name='participant[0][][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) • 1 month ago

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:


"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"
    ]
  ]
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.