tundeogunde

tundeogunde

Member Since 2 Years Ago

Experience Points 360
Experience Level 1

4,640 experience to go until the next level!

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

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

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

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

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

05 Jan
1 year ago

tundeogunde left a reply on Why Do I Get This Error - Trying To Get Property Of Non-object

Thanks a lot @Snapey and @kobear.

@Snapey, you're right about coding defensively; I tried your example, though it gave me an error about an unexpected '?'. However the approach of @kobear worked perfect.

The lesson learnt is to code defensively. I do appreciate your help and suggestions.

12 Dec
1 year ago

tundeogunde left a reply on Why Do I Get This Error - Trying To Get Property Of Non-object

Hi JackJones,

Please could you make your comment clearer? I'm probably using the wrong word "object". But what I mean is

  • in my view if I exclude {{$enrolment->event->title}} I still get an error.
  • in my view if exclude {{$enrolment->enrollee->surname}} I don't get any error anymore
  • if I change the {{$enrolment->enrollee->surname}} to {{$enrolment->enrollee->id}} I don't get an error but displays just the enrollee id

I'm a bit new to this, I'd appreciate a bit more clarity ; thanks.

tundeogunde started a new conversation Why Do I Get This Error - Trying To Get Property Of Non-object

I use Laravel 5.4

While displaying a particular view I keep getting the Error – “Trying to get property of non-object (View: C:\xampp\htdocs\enrolpad-lar\resources\views\enrolment\test.blade.php)”

Here’s a snippet of my view

@extends('layout.organizer_title_master')
@section('body')
    <div id="main-content">
        <div class="box-outer container">
            <div class="row">
                    <div id="messageAlert" class="col-md-12 alert alert-success text-center" role="alert" style="display: none;"></div>
                    <div class="col-md-4 page-container animate-box">
                        
                   </div>
                                    
                   <div class="col-md-8 page-container animate-box">
                        
                        <div class="white-container contact-box">
                            
                            @foreach ($enrolments as $enrolment)
                                <div class="row">                                   
                                    {{$enrolment->enrollee->surname}}<br>{{$enrolment->event->title}}
                                </div><hr>
                            @endforeach
                        </div>                      
                   </div>
            </div>
        </div>
    </div>    
@endsection

Here’s my Enrolment Model which is related to Enrollee and Event Models

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;


class Enrolment extends Model
{
    //
    use SoftDeletes;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'reference', 'enrollee_id', 'event_id', 'payment_id','status',
    ];

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['deleted_at'];    

    /**
        Check if Enrollee has previously enrolled for this event 
    */
    public static function if_previuosly_enrolled($enrollee_id, $event_id) 
    {
        $matchThese = ['enrollee_id' => $enrollee_id, 'event_id' => $event_id];
        
        if ($enrolment = Enrolment::where($matchThese)->count()) {
            return $enrolment >= 0;
        } else {
            return false;
        }
    }

    public function event()
    {
        return $this->belongsTo(Event::class);
    }

    public function enrollee()
    {
        return $this->belongsTo(Enrollee::class);
    }

    public function payment()
    {
        return $this->belongsTo(Payment::class)->withDefault();
    }
  

    public static function saveEnrolment($enrolmentdetail)
    {
        $reference = str_random(12);
        $status = '1';
        $enrolment = enrolment::create([
            'reference' => $reference,
            'enrollee_id' => $enrolmentdetail['enrollee_id'],
            'event_id' => $enrolmentdetail['event_id'], 
            'payment_id' => $enrolmentdetail['payment_id'], 
            'status' => $status,
        ]); 
        return $enrolment;
    }    
}

Here’s my Enrollee Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Enrollee extends Model
{
    use SoftDeletes;

    //
    protected $fillable = ['firstname', 'othernames', 'surname', 'email', 'mobile', 'country_id', 'event_updates', 'refer_points'];

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['deleted_at']; 
    

    /**
        Define the Many-To-Many Relationship with Interests
    */
    public function interests()
    {
        // 
        return $this->belongsToMany(Interest::class);
    }


    /**
     * Define the One-To-Many inverse relationship with Country. Get the country to which Enrollee belongs.
     */
    public function country()
    {
        return $this->belongsTo(Country::class);
    }

    public function enrolments()
    {
        return $this->hasMany(Enrolment::class);
    }

    /**
     * Get all of the enrollee's payments.
     */
    public function payments()
    {
        return $this->morphMany('App\Payment', 'payertable');
    }

    /*** Mutator functions to ensure that the name fields of the Enrollee are Capitalized */
    public function setFirstnameAttribute($value)
    {
        return $this->attributes['firstname'] = strtoupper($value);
    }

    public function setOthernamesAttribute($value)
    {
        return $this->attributes['othernames'] = strtoupper($value);
    }

    public function setSurnameAttribute($value)
    {
        return $this->attributes['surname'] = strtoupper($value);
    }
    /*** End Capitalize Enrollee names */

    
}

And my Event Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\SoftDeletes;

class Event extends Model
{
    use SoftDeletes;

    /**
     * Define the One-To-Many inverse relationships
     */
    public function organizer()
    {
        return $this->belongsTo(Organizer::class);
    }

    public function country()
    {
        return $this->belongsTo(Country::class);
    }

    public function interest()
    {
        return $this->belongsTo(Interest::class);
    }

    public function enrolments()
    {
        return $this->hasMany(Enrolment::class);
    }

    public function payouts()
    {
        return $this->hasMany(Payout::class);
    }

    /**
     * Get all of the event's payments.
     */
    public function payments()
    {
        return $this->morphMany('App\Payment', 'paymenttable');
    }

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'title', 'description', 'event_date', 'end_date','duration', 'organizer_id', 'venue', 'country_id', 'allowed_enrollees', 'status', 'fee','interest_id',  'poster','online_payment','private_event', 'private_key',
    ];

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['deleted_at'];
}

The Snippet from the enrolmentController that calls the view

public function showenrolments($event_id)
    {
        //
        $user = Auth::user();
        $event = Event::find($event_id);

        if ($user->id == $event->organizer_id) {            
            $enrolments = Enrolment::where('event_id', '=', $event_id)->get(); // Get all Enrolments for the event_id          
 
            return view('enrolment.test', compact('enrolments','event'));
        } else {
            Session::flash('danger-status','You do not have access to this event.');
            return redirect('organizer/myevents');
        }
    }

Here’s what I’ve tried

  • For each enrolment in the view, if I exclude the Event object, I still get an error.
  • For each enrolment in the view, if I delete the Enrollee object and leave the Event object, I get the expected output without errors.
  • If I replace the enrollee object in the view with $enrolment->enrollee->id I get the ids of each enrollee displayed without errors.
  • If I use $enrolment->enrollee I get the only one full record of the enrollee
  • If I dd() the $enrolments in my enrolmentController, it outputs all enrolment records including the enrollee_id for each record.
  • I realize that I can view a page that shows the details of each enrolment including the details of the enrollee ….. meaning the relationship is well defined. I also displayed {{$enrolment->enrollee->surname}} to get this and it worked fine.

What could be the problem? What have I done wrong? Why am I getting this error? I’d appreciate your help.

19 Oct
1 year ago

tundeogunde started a new conversation How Do I Implement Authorization And Roles For Application Admin

I use Laravel 5.4.

My application serves users that I call organizers; organizers have to login to use the application; Auth for organizers have been implemented and working.

I wish to implement Auth for Administrators and with this I also have to define roles and access levels for different administrators. How do I do this please. Is there any resource, link or tutorial that explains this?

16 Oct
1 year ago

tundeogunde left a reply on How Do I Give Public Access To Part Of A Controller Function

Thank you Snapey.

You are right about your comment - "You have to think that the callback is a totally standalone session. It is not part of the transactions you are having with the user, its a completely independent request.".

I took this approach and it worked for me. Thanks a lot for opening my eyes to this. I do appreciate.

15 Oct
1 year ago

tundeogunde started a new conversation How Do I Give Public Access To Part Of A Controller Function

I am using Laravel 5.4.

For my payment Controller file, I need to create a function to handle the payment Gateway Callback. The same payment Gateway Callback will handle Callback for payments made by Authorized users for subscription and by public users for other services.

My PaymentController contains the follwing:

public function __construct()
    {
        $this->middleware('auth:user');
    }

public function handleGatewayCallback()
{
    if($payer == 'user') {
       $user = Auth::user(); // Get the user's details
        $organizer = Organizer::find($user->id);
        ....procedure-1
    } else if($payer == 'public') {
        ....procedure-2
    }
}

The problem I encounter is that the code above will not execute the "else if" block if the payer is a public user; but it will execute the "if" block perfectly.

If I change the construct to

public function __construct()
    {
        $this->middleware('auth:user', ['except' => ['handleGatewayCallback']]);
    }

the "if" block will display the exception error "Trying to get property of non-object" while executing; while the "else if" block will execute perfectly.

How can I get both the "if" and the "else if" blocks to work when their conditions are true?

17 Aug
2 years ago

tundeogunde left a reply on How Do I Send Email To Multiple Recipients From A Single Email Form?

Thanks a lot Gator. It worked. I do appreciate.

Regards

16 Aug
2 years ago

tundeogunde started a new conversation How Do I Send Email To Multiple Recipients From A Single Email Form?

I am using Laravel 5.4. I have a contact form displayed in a Bootstrap Modal. Using JavaScript, the email recipients input box is populated and separated with commas. When I click the send button, no email is sent. However, if the input box has just one recipient the email is sent and works perfectly.

Below is my Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\enrolment;
use App\enrollee;
use App\event;
use Illuminate\Support\Facades\Mail;
use Auth;
use Session;
use Carbon\Carbon;
use Illuminate\Support\Facades\Validator;
use App\Mail\eventEnrolled;
use App\Mail\emailToEnrollee;
use Illuminate\Support\Facades\DB;

class enrolmentController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth:organizer', ['except' => ['processenrolment', 'storeenrolment']]);
    }
    
    public function emailtoenrollee(Request $request)
    {
        $user = Auth::user();
        $event = Event::find($request->event_id);
        $event->senderEmail = $user->email;
        $event->senderName = $user->name;
        $event->message = $request->message;
        $event->email = $request->email;        
        $event->subject = $request->subject;  
        
        // Send email the mail to the Enrollee 
        Mail::send(new emailToEnrollee($event));
    }
}

When the recipients are more than one, the $request->email contains comma separated email addresses. Here's my Mailable

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class emailToEnrollee extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($event)
    {
        //
        $this->event = $event;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->from($this->event->senderEmail, $this->event->senderName)->subject($this->event->subject)->to($this->event->email)->markdown('emails.emailToEnrollee')->with([
                'message' => $this->event->message,
                'sender' => $this->event->senderName,
                'subject' => $this->event->subject,
            ]);        
    }
}

How do I get my code to send to more than one comma separated email addresses from my form?

Thanks in advance

09 Aug
2 years ago

tundeogunde left a reply on How Do I Send Mail From A Bootstrap Modal Form?

I've found out the problem. I had left out the following in my controller; that explains why email was not sent. My mistake.

use App\Mail\emailToEnrollee;

Thank you.

tundeogunde started a new conversation How Do I Send Mail From A Bootstrap Modal Form?

I am using Laravel 5.4. I have a contact form displayed in a modal. I wish visitors to fill this form, click on the button and the email sent to the receiving email. I have also written javascript code that retrieves data from the form and post to my controller.

Below is my controller code

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\enrolment;
use App\enrollee;
use App\event;
use Illuminate\Support\Facades\Mail;
use Auth;
use Session;
use Carbon\Carbon;
use Illuminate\Support\Facades\Validator;
use App\Mail\eventEnrolled;
use Illuminate\Support\Facades\DB;

class enrolmentController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth:organizer', ['except' => ['processenrolment', 'storeenrolment']]);
    }
    
    public function emailtoenrollee(Request $request)
    {
        $user = Auth::user();
        $event = Event::find($request->event_id);
        $event->senderEmail = $user->email;
        $event->senderName = $user->name;
        $event->message = $request->message;
        $event->email = $request->email;
        $event->subject = $request->subject;      

        return $event;
        
        // Send email the mail to the Enrollee 
        Mail::send(new emailToEnrollee($event));
    }
    
}

When I comment out the Mail function so that the data object will be displayed, I get the desired output in my javascript console. However when I uncomment the Mail function, no email is sent and no output is displayed on the console. Below is the code for my Mailable emailToEnrollee.php

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class emailToEnrollee extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($event)
    {
        //
        $this->event = $event;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->from($this->event->senderEmail, $this->event->senderName)->subject($this->event->subject)->to($this->event->email)->markdown('emails.emailToEnrollee')->with([
                'message' => $this->event->message,
                'sender' => $this->event->senderName,
                'subject' => $this->event->subject,
            ]);        
    }
}

Below is my emailToEnrollee.blade.php markdown

@component('mail::message')
# {{$subject}}

{{$message}}

{{$sender}}<br><br>

{{ config('app.name') }}
@endcomponent

Is there something am doing wrong? Or is there a better way to send email from a form displayed on a Bootstrap Modal?

23 Jul
2 years ago

tundeogunde left a reply on Error While Passing Variable To Where Clause On Join

Thanks a lot tykus; it worked! I never knew I had to pass the $request. New lesson learnt!!!

tundeogunde started a new conversation Error While Passing Variable To Where Clause On Join

I am trying to retrieve records from a simple search form. The search string is to search through a join of 2 tables; enrolments table and enrollees table joined on enrollee_id. The search should search for the string in the name fields of the enrollees table and return details of the enrolments by enrollees who satisfy the search criteria.

public function search_for_enrolment(Request $request, $id) { $enrolments = Enrolment::where('event_id','=',$id)->join('enrollees','enrollees.id','=','enrolments.enrollee_id')->where(function($query) { $query->where('enrollees.firstname','=',$request->searchString)->orWhere('enrollees.othernames','=',$request->searchString)->orWhere('enrollees.surname','=',$request->searchString); })->get();

return view('enrolment.show_event_enrolments', compact('enrolments'));

}

The error I get is "Undefined variable: request"

However, if I test with a defined string; if I replace $request->searchString with 'John' , I get the desired output.

Am I doing something wrong?