johnnw

johnnw

Member Since 10 Months Ago

Experience Points 2,720
Experience
Level
Lessons Completed 8
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

30 Mar
8 months ago

johnnw left a reply on Update Password Is Not Working And How To Verify If The Actual Password Is Correct?

Thanks, but like that, without "confirmed" rule, there is no validation to check if the introduced actual password is equal to the actual password.

johnnw left a reply on Update Password Is Not Working And How To Verify If The Actual Password Is Correct?

Thanks, I added the "confirmed" like:

$this->validate($request, [
            'actual_password' => 'required|string|min:6|confirmed',
            'new_password' => 'required|string|min:6',
            'new_password_confirm' => 'required|string|min:6|same:new_password',
        ]);

But it appears always the validation error "The actual password confirmation does not match." even when the actual password introduced is correct. Do you know why?

johnnw started a new conversation Update Password Is Not Working And How To Verify If The Actual Password Is Correct?

I have a form for the user update his password. To update his password he needs to insert the actual password, the new password and confirm the new password. The actual password should be the actual password of the user and the new password and confirm password should be equal.

Then I have a UserController with the updatePassword method to update the user password.

But when the update buttons are clicked the update is not working. Do you know why?

And also do you know how to verify if the actual password introduced by the user is correct?

     public function updatePassword(Request $request){
    
            $this->validate($request, [
                'actual_password' => 'required|password',
                'new_password' => 'required|password',
                'new_password_confirm' => 'required|password|same:new_password',
            ]);
    
            $user = Auth::user();
            $user->password = bcrypt($request->new_password);
            $user->save();
    
            Session::flash('success', 'Password updated.');
    
            return redirect()->back();
        }

Form to edit the password:

    <form method="post" action="{{route('user.updatePassword')}}" class="clearfix">
         {{csrf_field()}}
           <div class="form-group col-md-6 px-0">
                <label for="new_password">New Password</label>
                <input type="password" class="form-control" name="actual_password" id="actual_password" placeholder="">
            </div>
            <div class="form-group col-md-6 px-0">
                <label for="new_password">New Password</label>
                <input type="password" class="form-control" name="new_password" id="new_password" placeholder="">
            </div>
            <div class="form-group col-md-6 px-0">
                <label for="new_password_confirm">Confirm password</label>
                <input type="password" name="new_password_confirm" class="form-control" id="new_password_confirm" placeholder="">
            </div>
            <div class="form-group">
                <input type="submit" value="Update password"/>
            </div>
        </form>

25 Mar
8 months ago

johnnw left a reply on How To Pass Data From One View To Another Using Session?

Thanks, but I don't have a next form. When the user clicks "Next" button he goes to another page, to the registration page, where appears the summary above and also some fields for the user to fill in. Its possible to pass the info from the conference details page to the registration page to show the summary with the correct dynamic values after the user click in "Next" without store that info anywhere? I'm not understanding how that works.

johnnw left a reply on How To Pass Data From One View To Another Using Session?

Thanks, you are saying to store the quantity of each registration type selected by the user in the conference details page into the database when "Next" button is clicked?

But for example if the user selects that we want 2 tickets of the registration types "rt1" and 1 of the registration type "rt2" maybe don't make sense to store that information on database even because the user may end up not finishing the registration after click in "Next" to go to the registration page.

johnnw started a new conversation How To Pass Data From One View To Another Using Session?

I have a conference details page and a page to register in the conference.

In the conference details page, the user can select through a select menu how many registrations want from each registration type available for the conference and then click in the "Next" button to go to the registration page.

My doubt is how to pass data (quantity of each registration type selected) from conference details page to the registration page? Because in the registration page is necessary to show a summary of the quantity of registration selected by the user in the conference details page.

Because in the registration page I want to show a summary of the registration types selected by the user, a summary like:

registration_types       quantity             price          subtotal
rt01                        2                                       5.00$           10.00$    
rt02                        1                                        10.00$          10.00$                 
TOTAL                                                                                   20.00$

For what Im understanding is necessary to use sessions for this context, but I dont find any example of using sessions to pass data from another page like this context. Do you know how this can be achieved?

The structure I have is:

FrontEndController that has a show method to show the conference details page:

public function show($id, $slug){
        $conf = Conference::where('id', $id)->first();
        $registrationTypes = RegistrationType::where('conf_id', $conf->id)->get();
        return view('confs.show')->with('conf',$conf)->with('registration_types', $registrationTypes);
    }

The route for this method above:

Route::get('/conference/{id}/{slug?}', [
    'uses' => '[email protected]',
    'as'   =>'confeerences.show'
]);

In the conference details page I have select menus so the user can select how many tickets want from each registration type:

<div>
    <div>
        <span>Registration</span>
        <span>Quantity</span>
        <span>Price</span>
    </div>
    <div>
        <ul>
            @foreach($registration_types as $rtype)
                <li>
                    <div>
                        <span>{{$rtype->name}}</span>
                    </div>
                    <form>
                        <select
                                 id="rtype_{{ $rtype->id }}" data-price="{{ $rtype->price }}" name={{ $rtype->name }}>
                            <option selected></option>
                                <option>1</option>
                                <option>2</option>
                                <option>3</option>
                               <option>4</option>
                        </select>
                </form>
                <span>X {{$rtype->price}}€</span>
                </li>
            @endforeach
            <li>
                <div>
                    <span>TOTAL</span>
                </div>
                <span>0.00€</span>
            </li>
        </ul>
    </div>
    <div>
        <a  href="{{route('conferences.registration', ['id' => $conf->id, 'slug' => $conf->slug])}}">Next</a>
    </div>
</div>

After the user selects the number of registrations for each registration type that he wants he can click "Next" to go to the registration page.

So I created this route:


Route::get('/conference/{id}/{slug?}/registration', [
    'uses' => '[email protected]',
    'as'   =>'conferences.registration'
]);

And in FrontEndController I have the method:

public function registration(){
        return view('conferences.registration');
    }

Registrtion page summary, that is static for now in the registration.blade.php file:

 <div>
    <div>
        <span>Summary</span>
    </div>
    <div>
        <ul>
            <li>
                <span>Registration Type</span>
                <span>Quantity</span>
                <span>Price</span>
                <span>Subtotal</span>
            </li>
            <li>
                <span>rt01</span>
                <span>2</span>
                <span>5.00$</span>
                <span>10.00$</span>
            </li>
            <li>
                <span>rt02</span>
                <span>1</span>
                <span>10.00$</span>
                <span>10.00$</span>
            </li>
            <li>
                <span>TOTAL</span>
                <span>20.00€</span>
            </li>
        </ul>
    </div>
</div>

16 Mar
8 months ago

johnnw left a reply on Trying To Get Property Of Non-object Sending Data To The View

Thanks but it appears the same issue with get() instead of first().

johnnw left a reply on Trying To Get Property Of Non-object Sending Data To The View

The error appears to be on "Illuminate/View/Compilers/Concerns/CompilesLoops.php" in " $iteratee = trim($matches[1]);"

johnnw left a reply on Trying To Get Property Of Non-object Sending Data To The View

It shows:

Conf {#232 ▼ #fillable: array:19 [▶] #dates: array:2 [▶] #connection: "mysql" #table: null #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: false #attributes: array:24 [▶] #original: array:24 [▶] #changes: [] #casts: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: [] #touches: [] +timestamps: true #hidden: [] #visible: [] #guarded: array:1 [▶] }

johnnw left a reply on Trying To Get Property Of Non-object Sending Data To The View

In the view I use for example: "{!! $conf->description !!}",{!! $conf->name !!}, etc.

johnnw left a reply on Trying To Get Property Of Non-object Sending Data To The View

Sorry, it is like this that is appearing "Undefined offset: 1":

public function single($slug){
        $conf = Conf::where('slug', $slug)->first();

        return view('confs.show')->with('conf',$conf);
    }

johnnw left a reply on Trying To Get Property Of Non-object Sending Data To The View

Thanks but it appear "Undefined offset: 1".

johnnw left a reply on Trying To Get Property Of Non-object Sending Data To The View

With:

  public function show($slug){
        $conf = Conf::find($slug);
        return view('confs.show')->with('conf', $conf);
    }

It appears "Undefined offset: 1".

johnnw started a new conversation Trying To Get Property Of Non-object Sending Data To The View

I have this single method that returns a view with conference information.

I want to pass to the view the conference info but also the registration types that exist for that conference. But its not working for the registration types, Im getting "Trying to get property of non-object". Do you know how to fix the issue?

 public function single($slug){
        $conf = Conf::find($slug);
        $registrationTypes = RegistrationType::where('conf_id', $conf->id)->get();
        return view('conf.single')->with('conf', $conf)->with('registration_types', $registrationTypes);
    }
14 Mar
9 months ago

johnnw started a new conversation How To Get Each Registration_type_id Of The Selected Checkboxes And The Question_id So Its Possible To Insert Them Into The Pivot Table?

I have a page that allows editing the registration form for a registration in a conference.

In this form, there is a table. Each row corresponds to a question that exists for that conference and then the user can associate each question with registration types trough checkboxes. Like:https://ibb.co/kftnPc

After select the checkboxes, he can click on the update button to update the registration form.

So I have the Question controller with the update method. I don't have any model for this "registration_type_question" table.

Do you know how this logic can be in the update method? Insert in the pivot table "registration_type_question" the "registration_type_id" of the selected checkboxes and "question_id" of each question in the table?

QuestionController:

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

        $values = $request->get('rtypes');
        $mandatories = $request->get('mandatories');

       // ??
       
}

Relevant relationships for the question:

1 to many between RegistrationType and RegistrationTypeQuestions 1 to may between Question and RegistrationTypeQuestions 1 to many between Conference and Question

Full Form:

<form id="edit_registration_types" method="post" class="clearfix" action="{{route('rtypes.update', ['conf_id' => $conf->id])}}">
    
        {{csrf_field()}}
    
        <div class="form-row">
            <div class="form-group col">
                <div class="row">
                    <div class="col">
                        <table class="table table-striped table-responsive-sm">
                            <thead>
                            <tr>
                                <th scope="col">Info</th>
                                <th scope="col">Include in registration type</th>
                                <th scope="col">Mandatory Field</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                                <td>Name</td>
                                <td>
                                    <i class='fa fa-check font-size-lg text-primary ml-4'></i>
                                </td>
                                <td>
                                    <i class='fa fa-check font-size-lg text-primary ml-4'></i>
                                </td>
                            </tr>
                            <tr>
                                <td>Surname</td>
                                <td>
                                    <i class='fa fa-check font-size-lg text-primary ml-4'></i>
                                </td>
                                <td>
                                    <i class='fa fa-check font-size-lg text-primary ml-4'></i>
                                </td>
                            </tr>
    
                            @foreach($question as $q)
                                <tr>
                                    <td>{{$q->question}}</td>
                                    <td>
                                        @foreach($registration_type as $rtype)
                                            <div class="form-check">
                                                <input name="rypes[]" autocomplete="off" class="form-check-input" type="checkbox" value="{{ $rtype->id }}" id="{{$rtype->id}}">
                                                <label class="form-check-label" for="exampleRadios1">
                                                    {{$rtype->name}}
                                                </label>
                                            </div>
                                        @endforeach
                                    </td>
                                    <td>
                                        @foreach($registration_type as $rtype)
                                            <div class="form-check">
                                                <input name="mandatories[]" autocomplete="off" class="form-check-input" type="checkbox" value="{{ $rtype->id }}" id="{{$rtype->id}}">
                                                <label class="form-check-label" for="exampleRadios1">
                                                    for the registration type "{{$rtype->name}}"
                                                </label>
                                            </div>
                                        @endforeach
                                    </td>
                                </tr>
                            @endforeach
    
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <input type="submit" class="btn btn-primary float-right mt-3" value="Update"/>
    </form>
06 Mar
9 months ago

johnnw started a new conversation URL Blocked: This Redirect Failed Because The Redirect URI Is Not Whitelisted

I have a facebook login button with this route:

<a href="{{route('social.auth',['provider' => 'facebook'])}}"  style="background-color: #3b5998; color:white;"> <i class="fa fa-facebook" aria-hidden="true"></i> Login</a>

URL Blocked: This redirect failed because the redirect URI is not whitelisted in the app’s Client OAuth Settings. Make sure Client and Web OAuth Login are on and add all your app domains as Valid OAuth Redirect URIs.

Do you know where can be the error?

// Routes:

    Auth::routes();
    
    Route::get('{provider}/auth/callback', [
        'uses' => '[email protected]',
        'as'   => 'social.auth'
    ]);
    
    Route::get('auth/{provider}/callback', '[email protected]');

OAuthcontroller:

    class OauthController extends Controller
    
    {
        public function redirectToProvider($provider)
        {
            return Socialite::driver($provider)->redirect();
    
        }
        public function handleProviderCallback()
        {
            $user = Socialite::driver('facebook')->user();
    
            return $user->getEmail();
    
            // $user->token;
        }
    }

In the App domains I have:


    proj.test

In the site url:


    http://proj.test/facebook/auth/callback

// Redirect uri

    redirect_uri=http://proj.test/auth/facebook/callback

johnnw left a reply on How To Model This Context In Terms Of Models Relationships So Its Possible To Create Custom Questions And Collect Answers?

Thanks, I don't know the model I was read about it but it seems that it should be used just in very specific cases and I don't know if this is the case in this context. The custom questions are related to a conference and to a registration type.

But, a conference can have a question "Whats your phone number" and another conference can have the question "Phone number" or even exactly the same "Whats your phone number" but they are two different questions because the first "Whats your phone number" can be related to a specific conference like the conference with id 2 and can be related to one or more registration types, but the second "Whats your phone number" is related to the conference width id 1 and can be related to one or more registration types.

05 Mar
9 months ago

johnnw started a new conversation How To Model This Context In Terms Of Models Relationships So Its Possible To Create Custom Questions?

When a user (conference creator) creates a conference he can create custom questions for that conference and later he can also associate custom questions to a specific registration type(s).

For example, he can create a custom question "Whats your phone number?" and after can associate this question to the registration type "General" for example or to any other all registration types that exist for a specific conference.

Then when a user does a registration in a conference he needs to fill a form with the custom fields created by the conference creator for the registration type(s) in which the user is registering.

So basically:

    A conference has many RegistrationTypes.
    
    A conference has many RegistrationQuestions.
    
    A registration type has many RegistrationQuestions.

So, when the conference creator accesses "http://proj.test/conference/edit/1/questions/create" he has access to a form to create new custom questions for the conference with id 1.

In this form, the user (conference creator) needs to select the title for the question (Ex: Phone number) and the type of question (Ex: text) and then click on "Store Question". Later when a user does a registration in the conference he needs to answer these custom questions that the conference creator has created.

The type of question field is a select menu with 5 options (text, long text, radio button, select menu and checkbox). If the user selects the type of question as a radio button, select menu or checkbox it appears some text inputs so the user can insert the values for each option.

I'm with some doubts about how to organize this context in terms of model relationships so that is possible to store custom questions. I have all the relevant code below to show how the context is organized for now. But I don't know if the context is properly modeled because in the QuestionController to store the question I'm not understanding how the question could be stored with the code structure below. I'm also in doubt in which model to store the answer that is introduced later by the user that does a registration in a specific registration type(s) of the conference. Do you know how this context can be properly organized so its possible to create custom questions?

// Conference Model

    class Conference extends Model
    {

         // A conference has many registration types
         public function registrationTypes(){
            return $this->hasMany('App\RegistrationType', 'conference_id');
         }
        // A conference can have  many questions
        public function questions(){
            return $this->hasMany('App\Question', 'conference');
        }
    }

RegistrationType model:

    class RegistrationType extends Model
    {
        public function conference(){
            return $this->belongsTo('App\Conference');
        }
    
        // A registration type has many questions
        public function questions(){
            return $this->hasMany('App\Question', 'registration_type_id');
        }
    }

// Question Model

    class Question extends Model
    {
        public function conference(){
            return $this->belongsTo('App\Conference');
        }
        public function registration_type(){
          return $this->belongsTo('App\RegistrationType');
        }

    }

// Question migration

    class CreateQuestionsTable extends Migration
    {
        public function up()
        {
            Schema::create('questions', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('conference_id');
                $table->integer('registration_type_id');
                $table->json('fields');
                $table->timestamps();
            });
        }
    }

Form:

    <form method="post" action="{{route('questions.store', ['conference_id' => $conference->id])}}">
      {{csrf_field()}}
      <div class="form-group">
        <label for="question_title">Question Title</label>
        <input type="text" class="form-control" name="question_title" id="question_title">
      </div>
      <div class="form-group">
        <label for="question_type">Field type</label>
        <select class="form-control" name="question_type" id="customQuestionType">
          <option value="">text</option>
          <option value="">Long text</option>
          <option value="optionQuestion">checkbox</option>
          <option value="optionQuestion">radio button</option>
          <option value="optionQuestion">select menu</option>
        </select>
      </div>
    
      <div class="form-group" id="availableOptions">
        <label for="inputName">Available options</label>
        <div class="option">
          <input type="text" class="form-control">
        </div>
        <div class="option">
          <input type="text" class="form-control">
        </div>
      </div>
      <div class="form-group">
        <input type="button" class="btn btn-outline-primary" id="addNewOption" value="Add new option"/>
      </div>
    
      <input type="submit" class="btn btn-primary float-right mt-3" value="Store Question"/>
    
    </form>

QuestionController:

     class QuestionController extends Controller
    {
        // returns the view with the form to create a new question    
        public function create($id){
            $conference = Conference::find($id);
            return view('questions.create')->with('conference', $conference);
        }
        // store the question
        public function store(Request $request, $id){
            $this->validate($request, [
                'question_title' => 'required|string',
                'question_type' => 'required|integer',
            ]);
            $conference = Conference::find($id);
            Question::create([
                'fields' => //???
                'conference' => $conference->id
            ]);
    
            return redirect()->back();
        }
    }
27 Feb
9 months ago

johnnw left a reply on Why It Appears This Error: "Route [rtypes.update] Not Defined"?

It seems that with the redirect works, thanks!!

johnnw left a reply on Why It Appears This Error: "Route [rtypes.update] Not Defined"?

// update method

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

        $this->validate($request, [
            'registration_type_name' => 'required|string',
            ...
        ]);

        $registrationTypeToUpdate = RegistrationType::find($request->radiobutton);

        $registrationTypeToUpdate->name = $request->registration_type_name;
        ...

        $registrationTypeToUpdate->save();


        return redirect()->back();
    }
// Store method
    public function store(Request $request, $id){

        $this->validate($request, [
            'registration_type_name' => 'required|string',
            ...
        ]);

        $conference = Conference::find($id);

        RegistrationType::create([
            'name' => $request->registration_type_name,
            ...
            'conference_id' => $conference->id
        ]);
    }

johnnw left a reply on Why It Appears This Error: "Route [rtypes.update] Not Defined"?

I have a /views/rtypes/edit.blade.php file. In this file I have a form that allows a user edit the registration types of a conference but also create new registration types.

The existing registration types are listed in the form, if the user select the radio button of a specific registration type the form fields are populated with that registration type details and the user can change and update that registration type. This part is working fine, I have a registration type controller with that edit method above that returns the view "/views/rtypes/edit.blade.php" and then the update method that updates the selected registration type.

But there is also a radio button "Create new registration type". When this radio button is clicked the form fields are reseted so the user can insert new values to create a new registration type.

So I need to have a form with two differenct actions based on the selected radio button but this form is on the same edit registration types page.

johnnw left a reply on Why It Appears This Error: "Route [rtypes.update] Not Defined"?

Thanks, but Im not understanding well, for example like that is necessary to repeat a method twice? I already have the edit method like:

public function edit($id)
    {
        $conference = Conference::find($id);
        $registrationType = RegistrationType::where('conference_id', $id)->get();

        return view('rtypes.edit')
            ->with('conference', $conference)
            ->with('registrationType', $registrationType));
        }

Its necessary to repeat all same code like:

public function create($id)
    {
        $conference = Conference::find($id);
        $registrationType = RegistrationType::where('conference_id', $id)->get();

        return view('rtypes.edit')
            ->with('conference', $conference)
            ->with('registrationType', $registrationType));
        }

johnnw left a reply on Why It Appears This Error: "Route [rtypes.update] Not Defined"?

Thanks but like that when the user stores a registration type it goes to a blank page because there is no view associated with a url like: 'conference/store/{id}/rtypes'. There is only a edit view and in this view is possible to both update but also create new registration types based on radio button selection.

johnnw left a reply on Why It Appears This Error: "Route [rtypes.update] Not Defined"?

No, just the rypes.edit and rtypes. store, but dont understand why. In the web.php file the routes are defined.

johnnw started a new conversation Why It Appears This Error: "Route [rtypes.update] Not Defined"?

Hi, I'm trying to change the form action based on radio button selection.

When the radio button "Create Registration Type" is selected I want to store a new registration type otherwise I want to update an existing registration type.

But I'm always getting this error: "Route [rtypes.update] not defined". Do you know why?

I have the code below that seems relevant to the question below.

Form:

   <form method="post" class="clearfix"
              action="{{route('rtypes.update', ['conference_id' => $conference->id])}}" enctype="multipart/form-data">
                          {{csrf_field()}}

     <div class="form-group col col-lg-6">
            <label for="registration_types">Registration types</label>

            @foreach($registrationType as $rtype)
                <div class="form-check">
                    <input class="form-check-input radio" type="radio" name="radiobutton" value="{{ $rtype->id }}" id="{{$rtype->id}}" checked>
                    <label class="form-check-label" for="exampleRadios1">
                        {{$rtype->name}}
                    </label>
                </div>
            @endforeach

            <div class="form-check">
                <input class="form-check-input" type="radio" name="radiobutton" id="create_registration_type"
                       value="option2">
                <label class="form-check-label" for="exampleRadios2">
                    Create Registration Type
                </label>
            </div>

        </div>
</form>

JS:

  $("input[name='radiobutton']").click(function() {
    opt = this.value;

    if (opt === 'Create Registration Type') {
        form.attr('action', '{{route('rtypes.update', ['conference_id' => $conference->id])}}');
    } else {
        form.attr('action', '{{route('rtypes.store', ['conference_id' => $conference->id])}}');
    }    
}); 

routes:

// update rtypes

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

// create rtypes

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

johnnw left a reply on Type Error: Too Few Arguments To Function Illuminate\Support\Collection::get()

Thanks, with sortBy it appears: "asort() expects parameter 2 to be integer, string given".

26 Feb
9 months ago

johnnw left a reply on Type Error: Too Few Arguments To Function Illuminate\Support\Collection::get()

Thanks the issue is that in the view the $categories is used twice, and in a div its just necessary to show 6 categories but in another div its necessary to show all categories, that are more than 6.

johnnw left a reply on Type Error: Too Few Arguments To Function Illuminate\Support\Collection::get()

Now appears: "Method orderBy does not exist. "

johnnw left a reply on Type Error: Too Few Arguments To Function Illuminate\Support\Collection::get()

Thanks, but I dont know why with all() appears always the error: Parse error: syntax error, unexpected ';', expecting ',' or ')' . Do you know why?

johnnw started a new conversation Type Error: Too Few Arguments To Function Illuminate\Support\Collection::get()

Im passing all categories stored to the view return view('homepage')->with('categories', Category::get()) Then in the view I have to show just 6 categories:

 @foreach($categories->take(6)->get() as $category)
    <li class="ative">
        <a href="">{{$category->name}}</a>
    </li>
@endforeach 

But appears an error, do you know why?

Error:

Type error: Too few arguments to function Illuminate\Support\Collection::get()

johnnw left a reply on How To Solve This Undefined Variable Error?

Thanks for the answer and for the explanation!

johnnw left a reply on How To Solve This Undefined Variable Error?

Thanks for your answer and explanation. The "dd($request->all());" returns:


Array:10 [▼
  "radiobutton" => "option1"
  "registration_type_name" => "rg 001"
  "registration_type_description" => "description rg 001"
  "registration_type_capacity" => "10"
  ...
]

So I don't get any id or name of the radio button, so how to update the selected radio button?

johnnw left a reply on How To Solve This Undefined Variable Error?

Thanks for the answer. But it appears "Property [id] does not exist in this collection instance." with that. And that is not what is necessary because what is necessary is to update the selected registration type, the id of the selected radio button so the id that should be passed to the update method is the id of the selected registration type.

johnnw started a new conversation How To Solve This Undefined Variable Error?

I have this controller that returns to the view an array with the registration types that exist for a conference:

class RegistrationTypeController extends Controller
{
public function edit($id)
{
    $conference = Conference::find($id);
    $registrationType = RegistrationType::where('conference_id', $id)->get();
    return view('rtypes.edit')->with('conference', $conference)->with('registrationType', $registrationType)
    }
}

Then in the form is possible to edit a specific registration type of a conference. So its necessary to pass to the update method the id of the conference but also the id of the registration type so its possible to update that specific selected registration type.

Do you know how to pass the registration type id of the selected form-check to the view? Like below it appears undefined variable.

<form method="post" class="clearfix" action="{{route('rtypes.update', ['conference_id' => $conference->id, 'rtype_id' => $rtype->id])}}" enctype="multipart/form-data">
{{csrf_field()}}
<div class="form-row">
    <div class="form-group col col-lg-6">
        <label>Registration Types</label>
        @foreach($registrationType as $rtype)
            <div class="form-check">
                <input class="form-check-input radio" type="radio" name="radiobutton" id="{{$rtype->id}}" value="" checked>
                <label class="form-check-label" for="exampleRadios1">
                    {{$rtype->name}}
                </label>
            </div>
        @endforeach
    </div>
</div>
23 Feb
9 months ago

johnnw started a new conversation How To Load The Values In The Form Fields When The Corresponding Radio Button Is Selected?

I have a form that has some radio buttons. Each radio button corresponds to a registration type of a conference. For that I have this code:


 @foreach($registrationType as $rtype)
      <div class="form-check">
        <input class="form-check-input" type="radio" name="radiobutton" id="{{$rtype->id}}" value="option1">
        <label class="form-check-label" for="exampleRadios1">
          {{$rtype->name}}
        </label>
      </div>
  @endforeach

Below the radio buttons, the form has some fields and I want to show in this fields the information of each selected registration type. This part I'm in doubt how to do it.

First I load the values for each registration type and store them in a array:

 $(function() {
    var registrationTypes = {!!  $registrationTypeJson !!}
    alert(registrationTypes) /7 returns "[object Object]""
});

But then how to use jquery to load the values in the form fields when the corresponding radio button is selected? Do you know how to do that?

Full form:

<form method="post" class="clearfix">
      <div class="form-row">
        <div class="form-group col col-lg-6">
          <label for="registration_types">Registration Types</label>

          @foreach($registrationType as $rtype)
          <div class="form-check">
            <input class="form-check-input" type="radio" name="radiobutton" id="{{$rtype->id}}" value="option1">
            <label class="form-check-label" for="exampleRadios1">
              {{$rtype->name}}
            </label>
          </div>
          @endforeach

          <div class="form-check">
            <input class="form-check-input" type="radio" name="radiobutton" id="create_registration_type" checked value="option1">
            <label class="form-check-label" for="exampleRadios1">
              Create new registration type
            </label>
          </div>
        </div>
      </div>

      <div class="form-group">
        <label for="registration_type_name">Registration Type Name</label>
        <input type="text" required class="form-control" value="{{ $rtype->nome }}" name="registration_type_name" id="registration_type_name">
      </div>
      <div class="form-group">
        <label for="registration_type_capacity">Capacity</label>
        <input type="number" min="1"
               required class="form-control" value="{{ $rtype->capacity }}"
             name="registration_type_capacity" id="registration_type_capacity">
      </div>
      <!-- more registration type info fields -->
      </div>
    <input type="submit" class="btn btn-primary" value="Update registration type"/>
    </form>

johnnw left a reply on Translate Carbon Date

Thanks, but even with 'locale' instead of 'LOCALE' on the "AppServiceProvider" boot method don't translates.

johnnw started a new conversation Translate Carbon Date

I'm showing the date using carbon like this:


{{$p->date->toDayDateTimeString()}}

But I would like to show the date text in a different language "de".

So I changed:


    'locale' => 'en'                       to     'locale' => 'de'
     'fallback_locale' => 'en',     to     'fallback_locale' => 'de'

But don't works.

I also try to in the "AppServiceProvider" add in the boot method:


 public function boot()
    {
        Carbon::setLocale(env('LOCALE', 'de'));
    }

But also don't works.

Do you know why?

johnnw left a reply on Image Appears As A Folder Instead A File In The Uploadas Folder

Thanks, but so do you know how to store in database just when a image is selected? Because the image is not required.

Like below is working but it is storing in the database always this "uploads/conferences/" when any image is selected. But if any image is selected in the database the image column should be empty "".

if($request->image){
    $featured = $request->image;
    $featured_new_name = time().$featured->getClientOriginalName();
    $featured->move('uploads/conferences',$featured_new_name);
}
else{
    $featured_new_name = '';
}
$conference = Conference::create([
    'image' =>  'uploads/conferences/'.$featured_new_name,

]);

johnnw started a new conversation Image Appears As A Folder Instead A File In The Uploadas Folder

When a new conference is created is stored and uploaded an image with the code below. But then in the frontend the image doesn't appears. And in the uploads folder instead of appears a jpg file it appears a folder with .jpg extension.

Do you know where is the issue?

if($request->image){
    $featured = $request->image;
    $featured_new_name = 'uploads/conferences/'.time().$featured->getClientOriginalName();
    $featured->move($featured_new_name);
}
else{
    $featured_new_name = '';
}

 $conference = Conference::create([
            'image' =>  $featured_new_name,
        ]);

johnnw left a reply on Update Error - Creating Default Object From Empty Value

Thanks now it not appears any error but the update doesn't work. But I don't understand what is necessary to add, "RegistrationType::where('id', conference->id)->update" it is already updating the registration type where it is "conference->id" or no?

22 Feb
9 months ago

johnnw started a new conversation Update Error - Creating Default Object From Empty Value

I have a view to editing registration types but when the store button is clicked it appears:

"Creating default object from empty value".

Do you know where is the issue?

The user accesses "http://proj.test/conference/edit/3/rtypes" to edit the registration types. Here there is a form:

<form method="post" class="clearfix">
    <div class="form-row">
        <div class="form-group col col-lg-6">
            <label for="registration_types">Registration Types</label>

            @foreach($registrationType as $rtype)
                <div class="form-check">
                    <input class="form-check-input" type="radio" name="radiobutton" id="{{$rtype->id}}" value="option1">
                    <label class="form-check-label" for="exampleRadios1">
                        {{$rtype->name}}
                    </label>
                </div>
            @endforeach
        </div>
    </div>

    <div class="form-group">
        <label for="registration_type_name" class="text-heading h6 font-weight-semi-bold">Registration Type Name</label>
        <input type="text" required class="form-control" value="{{ $rtype->name }}" name="registration_type_name" id="registration_type_name">
    </div>
    <div class="form-group">
        <label for="registration_type_capacity" class="text-heading h6 font-weight-semi-bold">Capacity</label>
        <input type="number" min="1"
               required class="form-control" value="{{ $rtype->capacity }}"
               name="registration_type_price" id="registration_type_capacity">
    </div>
    <!-- more registration type info fields -->
    </div>
    <input type="submit" class="btn btn-primary" value="Store registration type"/>
</form>

RegistrationType controller edit method:

public function edit($id)
    {
        $conference = Conference::find($id);
        $registrationType = RegistrationType::where('conference_id', $id)->get();


        return view('rtypes.edit')->with('conference', $conference)->with('registrationType', $registrationType);
    }
RegistrationType controller update method:
public function update(Request $request, $id){

        $this->validate($request, [
            'registration_type_name' => 'required|string',
            'registration_type_description' => '',
            ....
        ]);

        $conference =Conference::find($id);
        $regType = RegistrationType::find($conference->id);

        $regType->name = $request->registration_type_name;
        $regType->description = $request->registration_type_description;
       ...


        $regType->save();

        return redirect()->back();
    }
RegistrationType controller update method:
public function update(Request $request, $id){

        $this->validate($request, [
            'registration_type_name' => 'required|string',
            'registration_type_description' => '',
            ....
        ]);

        $conference =Conference::find($id);
        $regType = RegistrationType::find($conference->id);

        $regType->name = $request->registration_type_name;
        $regType->description = $request->registration_type_description;
       ...


        $regType->save();

        return redirect()->back();
    }

johnnw started a new conversation Why It Appears "the Page Has Expired Due To Inactivity"?

I have a view to edit registration types but when the store button is clicked it appears:

"The page has expired due to inactivity. "

Do you know where can be the issue?

RegistrationType controller edit method:

public function edit($id)
    {
        $conference = Conference::find($id);
        $registrationType = RegistrationType::where('conference_id', $id)->get();


        return view('rtypes.edit')->with('conference', $conference)->with('registrationType', $registrationType);
    }

RegistrationType controller update method:

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

        $this->validate($request, [
            'registration_type_name' => 'required|string',
            'registration_type_description' => '',
            ....
        ]);

        $conference =Conference::find($id);
        $regType = RegistrationType::find($conference->id);

        $regType->nome = $request->registration_type_name;
        $regType->descricao = $request->registration_type_description;
       ...


        $regType->save();

        return redirect()->back();
    }

Routes:

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

johnnw started a new conversation How To Show The Info Of Each Registration Type Based On The Radio Buttton Selection?

I have a form that has some radio buttons and below the radio buttons, there are some text and number inputs.

One radio button is static, "Create new registration type", when is clicked the form fields should reset so the user can insert new values in the fields. This part is working fine.

The other radio buttons are dynamic and correspond to the registration types that exist for a specific conference in the database. When each of these radio buttons is checked I want to show in the form fields the information (name, capacity, etc) of that specific checked registration type. This part I don't understand how to do, do you have any idea how this part can be done?

The page needs to be refreshed? Or the registration types can be all loaded at once and then use jquery to show each registration type on each radio button selection? But how to do this part of showing the info of each registration type based on the radio button selection?

JS:

     <script>
            $('#create_registration_type').click(function(){
                $('input[type="text"]').val('');
                $('input[type="number"]').val('');
            });
        </script>

Edit registration type form:


    <form method="post" class="clearfix">
                <div class="form-row">
                    <div class="form-group col col-lg-6">
                        <label for="registration_types">Registration Types</label>
    
                        @foreach($registrationType as $rtype)
                            <div class="form-check">
                                <input class="form-check-input" type="radio" name="radiobutton" id="{{$rtype->id}}" value="option1">
                                <label class="form-check-label" for="exampleRadios1">
                                    {{$rtype->name}}
                                </label>
                            </div>
                        @endforeach
    
                        <div class="form-check">
                            <input class="form-check-input" type="radio" name="radiobutton" id="create_registration_type" checked value="option1">
                            <label class="form-check-label" for="exampleRadios1">
                                Create new registration type
                            </label>
                        </div>
                    </div>
                </div>
    
                <div class="form-group">
                    <label for="registration_type_name" class="text-heading h6 font-weight-semi-bold">Registration Type Name</label>
                    <input type="text" required class="form-control" value="{{ $rtype->nome }}" name="registration_type_name" id="registration_type_name">
                </div>
                <div class="form-group">
                    <label for="registration_type_capacity" class="text-heading h6 font-weight-semi-bold">Capacity</label>
                    <input type="number" min="1"
                           required class="form-control" value="{{ $rtype->capacity }}"
                           name="registration_type_price" id="registration_type_capacity">
                </div>
                <!-- more registration type info fields -->
                </div>
                <input type="submit" class="btn btn-primary" value="Store registration type"/>
            </form>

RegistrationType controller:


    class RegistrationTypeController extends Controller
    {
        public function edit($id)
        {
            $conference = Conference::find($id);
            $registrationType = RegistrationType::where('conference_id', $id)->get();
    
    
            return view('rtypes.edit')->with('conference', $conference)->with('registrationType', $registrationType);
        }
    }

Registration type model*


    class RegistrationType extends Model
    {
        protected $fillable = [
            'name', 'description', 'capacity', 'min_participants', 'max_participants', 'conference_id'
        ];
    
        public function confenrence(){
            return $this->belongsTo('App\Conference');
        }
    }

20 Feb
9 months ago

johnnw started a new conversation "The Date Does Not Match The Format D/m/Y H:i:s."

I'm trying to store a date value but is always appearing the validation error:

"The date does not match the format d/m/Y H:i:s."

Do you know where can be the issue? Validate method:

$this->validate($request, [
      'date1' => 'required|date_format:d/m/Y H:i:s',
      'date2' => 'required|date_format:d/m/Y H:i:s|after_or_equal:date1',
 ]);

To create Im using carbon to format the dates:

 Carbon::createFromFormat('d/m/Y H:i:s', $request->date1)
Carbon::createFromFormat('d/m/Y H:i:s', $request->date2)

The Js code is:

$( ".input-group.date").datetimepicker({
        format: "dd MM yyyy - hh:ii",
        autoclose: true,
        todayBtn: true,
        minuteStep: 5
    });
18 Feb
9 months ago

johnnw left a reply on How To Structure This Context In Terms Of Files And Routes?

Thanks really!

I just have one more doubt relative to issue 1:

I understand that is not appropriate call the view “index”, but call the view “show” I don’t know also if it's appropriate.

Because, for example in a blog example, in a PostController the show method could be to show a view that presents only a form to edit a specific post.

But in the conference example, the show method is to show not only a simple view that has a form to edit the conference details like name, description etc.

What is necessary is, after storing the conference redirect the user to the conference management area of the conference that he has created, more specifically to the index page of the conference management area. And then in this conference management area, there are different links to manage different aspects of the conference.

So the structure that I have in terms of views is:

resources
   myconferences
        index.blade.php (index page of the conference management area)
        myconferencestemplate.blade.php (template for all conf management pages)
   createConference.blade.php (page with a form to create new conference) 
   app.blade.php (template for all frontend pages)
   index.blade.php (index page for the frontend)

So I have the “myconferencestemplate.blade.php” template file that is shared by all conference management pages:

<!doctype html>
        <html>
        @include('partials.head')

        <body>

        @include('partials.header')

            <div class="sidebar-container">
                <nav id="sidebar">
                <!-- conference management menu with links -->
                </nav>
            </div>

            <div class="admin_content py-3">
             @yield('content') <!-- content of each accessed management page -->
            </div>
        </div>

        @include('partials.footer')

        </body>

</html>

And then the “index.blade.php” is to show the home page of the conference management area and extends “myconferencestemplate”. So the “index.blade.php” is like:

@extends('myconferencestemplate')
@section('content')
…
@endsection

Can you give an example in terms of names that you consider appropriate for this context?

johnnw left a reply on How To Structure This Context In Terms Of Files And Routes?

Thanks, so "http:\proj.test/myconference/2" could go to the show() method and in this show method() I could return a view that shows the index page of the conference management area right?

So, for what I understand with this approach when the user accesses "http:\proj.test/myconference/2" it has access to that conference management area using the show method like:

public function show($id)
    {
        return view('myconferences.index')->with('myConference'Conference::where('id', $id)->first());
    }

I created the "index.blade.php" file inside the folder "myconferences" and created the folder "myconferences" is inside the resources folder.

And also created this route:

Route::get('myconference/{id}', [
    'uses' => '[email protected]',
    'as'   => 'myconference'
]);

The issue is that for example if the user John created the conference with id "2" he should be allowed to access that conference management area using "http:\proj.test/myconference/2".

But if user John log out, and the user Jake login he should not be allowed to access a conference management area of a conference that was not created by him, so he should not be allowed to access "http:\proj.test/myconference/2" because its a conference created by John and not for him. But with the code below the user Jake can access "http:\proj.test/myconference/2". Do you know what is needed to handle this issue?

johnnw left a reply on How To Structure This Context In Terms Of Files And Routes?

Thanks, but your example is for example in a blog for example a user can create a post, edit, delete etc. So we could have the route:

Route::get('posts/{postId}', '[email protected]');

And then:

public function edit(Post $post)
{
    // here we could probably show a form to edit the post
}

But in the conference example I have doubt because after storing the conference the user is redirected to "http:\proj.test/myconference/2". But this url is not to show a form to edit the conference like in the post example above.

This url should present to the user the index page of the conference management area for that specific conference that he has created. And in this area, he can not only edit the conference itself but other aspects of the conference (list participants, create/edit registration types, etc) that appear on the side left menu.

johnnw left a reply on How To Structure This Context In Terms Of Files And Routes?

Thanks. For example, after storing the conference, the user is redirected to "http:\proj.test/myconference\2" (2 is the id of the conference). In this url should be presented the index page of the conference management area, but I'm not having success in doing this. Do you know how to to do that properly? I have a default blade file for the conference management area and also a blade file for the index page of this conference management area, but how to structure the routes, files to redirect the user to the index page of the conference management after storing the conference?

johnnw started a new conversation How To Structure This Context In Terms Of Files And Routes?

In the frontend of the app there is a link "Manage Conference". When the user clicks on this link he should be redirected to a frontend page that lists all the conference created by the user. This page should be accessed with a url like "http:\proj.test/myconferences".

For each listed conference there is a "Management" link so the user can access the management area specific for each listed conference. For example if the user clicks in a conference with id for example "2247" the url should be something like "http:\proj.test/myconference?eid=2247" or maybe "http:\proj.test/myconference/2247", i don't know which is the best approach.

But when the user accesses this url he should be redirected to a page that has some options to manage that specific conference. This page has always the same layout, a menu at left with the management options and at right is presented the content of each manage page. The menu options are:

- Index (this is the home page of this management area, that show some statistics of the conference like number of participants, etc)
- Edit Conference
    Edit Conference Details
    Edit Conference Creator Details
    Create/Edit Registration Types
- List registered participants
- Certificates
    Create Certificate
    Send Certificate

My doubt is:

How to organize the files and routes properly so that after storing the conference or when user accesses "http:\proj.test/myconference?eid=2247" or something using the frontend link is possible to redirect the user to a proper route so he accesses this management area specific to the conference that he has created.

More specifically, after storing the conference the user should be redirected to the "Index" link of this management area, that is the home page of the conference management area. And then for example, if he clicks on the link "Edit Conference Creator Details" management option, he should be redirected to some link in the management area that allows editing the organizers of that specific conference, and the same for the other links, are always specific to one particular conference that the user has created.

Can you give a help on how to understand how to structure this properly?

Routes that I have for now:

Route::get('/', function () {
        return view('app.index');
    });
    
    Route::group(['prefix' => '', 'middleware' => 'auth'], function(){
        Route::post('/conference/store', [
            'uses' => '[email protected]',
            'as'   => 'conference.store'
        ]);
        Route::get('/createConference', [
            'uses' => '[email protected]',
            'as'   => 'conference.create'
        ]);
    });

ConferenceController Store method:

public function store(Request $request)
            {
                $this->validate($request, [
                    'conference_name' => 'required|max:255|string',
                     ...
                ]);
                $conference = Conference::create([
                    'nome' => $request->conference_name,
                    ...
                ]);
                //return redirect()->route('myconference', ['id' => $conference->id]);
            }

I also have: - a default layout "app.blade.php" that is shared by the frontend pages - a "management.blade.php" that is not being used yet but is the layout shared by the conference management pages. - and a index.blade.php for the management area that should be the first page presented when a user accesses the conference management area for a particular conference that he has created