JordanDalton

JordanDalton

Member Since 5 Years Ago

Temple, TX

Experience Points 9,715
Experience Level 2

285 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 151
Lessons
Completed
Best Reply Awards 3
Best Reply
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.

03 Mar
1 month ago

JordanDalton left a reply on Code Review Needed - Saving Inbound Emails And Attachments To Server

You're welcome. Feel free to put NewEmail in any namespace you like.

JordanDalton left a reply on Code Review Needed - Saving Inbound Emails And Attachments To Server

The model needs to be only concerned with handling the the data and relationships of the model. The NewEmail class is a workflow of handling the attachments, which leads to Email records.

This should bring it together.

Mailbox::to('{token}@myapp.com', NewEmail::class);

JordanDalton left a reply on Code Review Needed - Saving Inbound Emails And Attachments To Server

We'll need to make some updates.

<?php

use App\Email;
use App\Stream;

class NewEmail {
    
    /**
     * Handle the incoming email.
     */
    public function __invoke(Email $email, $token)
    {
        //Get the correct stream.
        $stream = Stream::where('token', $token)->firstOrFail();

        //If any attachments, persist them to the database.
        $this->storeAttachments($stream, $email->saveStream($stream));

    }
    
    /**
     * Stores the attachments on the server.
     * @return array
     */
    public function storeAttachments(Stream $stream, Email $email)
    {
        $attachments = [];

        foreach ($email->attachments() as $attachment) {
            $attachments[] = $stream->addDocuments($this->attach($stream, $attachment));
        }

        return $attachments;
    }

    /**
     * Stores the attachments on the server
     * @return array ['name', 'path']
     */
    public function attach(Stream $stream, $attachment)
    {
        $filename = $this->getFileName($attachment);

        $this->storeFileOnServer($stream, $filename, $attachment);

        return [
            'name' => $filename,
            'path' => $stream->token . '/' . $filename
        ];
    }

    /**
     * Generates a filename for our attachment.
     * @return string (filename.ext)
     */
    public function getFileName($attachment)
    {
        return uniqid() . '.' . File::extension($attachment->getFilename());
    }

    /**
     * Stores the actual file: streamtoken/filename.ext
     * @return boolean
     */
    public function storeFileOnServer(Stream $stream, $filename, $attachment)
    {
        return Storage::put($stream->token . '/' . $filename, $attachment->getContent());
    }

}
<?php

namespace App;

use App\Stream;
use BeyondCode\Mailbox\InboundEmail;

class Email extends InboundEmail
{
    protected $table = 'emails';

    protected $fillable = [
        'message',
        'stream_id'
    ];

    /**
     * Save the stream_id to the Email object.
     */
    public function saveStream(Stream $stream)
    {
        return tap($this)->updateOrCreate(['stream_id' => $stream->id]);
    }

    /**
     * An email belongs to a Stream.
     */
    public function stream()
    {
        return $this->belongsTo(Stream::class);
    }
}

JordanDalton left a reply on Code Review Needed - Saving Inbound Emails And Attachments To Server

Show me a copy of your InboundEmail model.

JordanDalton left a reply on Code Review Needed - Saving Inbound Emails And Attachments To Server

@OLIVERBUSK - Laravel's tap feature (https://laravel.com/docs/5.8/helpers#method-tap) is really neat. It Essentially lets you work within an object but return the object in the end. Think of if it like a playground.

tap($object)->playAroundWithIt()

Here's what's going on behind the scenes.

function tap($object){

    $object->playAroundWithIt();

    return $object
}

One of the beauties of tap() is that you can chain as many methods to it as you like.

tab($object)->doThis()->doThat()->theSkyIsTheLimit()

In our case we want to save the stream_id to the InboundEmail object. By leveraging tap we can save the stream_id but we can still have access to the InboundEmail object in the end. Each time your __invoke() is being called the stream_id is getting saved.

public function saveStream(Stream $stream)
{
    return tap($this)->update(['stream_id' => $stream->id]);
}

Now for the other snippet of code:

$this->storeAttachments($stream, $email->saveStream($stream));

$stream is being provided from __invoke. $email->saveStream($stream) is returning the InboundEmail object vie our call to tap()

JordanDalton left a reply on Code Review Needed - Saving Inbound Emails And Attachments To Server

The majority of what you have is great. Here are some areas where it could be impoved.

__invoke

In this section you can save a few lines by pushing the code to save the stream id into the InboundEmail

public function __invoke(InboundEmail $email, $token)
{
    //Get the correct stream.
    $stream = Stream::where('token', $token)->firstOrFail();

    //If any attachments, persist them to the database.
    $this->storeAttachments($stream, $email->saveStream($stream));

}

InboundEmail

Utilizing tap() will let you still have access to the email record instead of just having a boolean returned.

public function saveStream(Stream $stream)
{
    return tap($this)->update(['stream_id' => $stream->id]);
}

Storing Attachments

In my eyes the storeAttachments() has a little too much going on. You'll see from my updates that we're pushing responsibilities to different methods. While this does add more lines to the class you're also getting the benefit of having testable code.

public function storeAttachments(Stream $stream, InboundEmail $email)
{
    $attachments = [];

    foreach ($email->attachments() as $attachment) {

        attachments[] = $stream->addDocuments($this->attach($stream, $attachment));
    }
    
    return $attachments;
}

public function attach(Stream $stream, $attachment)
{
    $filename = $this->getFileName($attachment);
    
    $this->storeFileOnServer($stream, $filename, $attachment)

    return [
        'name' => $attachment->getFilename(),
        'path' => $stream->token . '/' . $filename
    ];
}

public function getFileName($attachment)
{
    return uniqid() . '.' . File::extension($attachment->getFilename());    
 }

public function storeFileOnServer(Stream $stream, $filename, $attachment)
{
    return Storage::put($stream->token . '/' . $filename, $attachment->getContent()); 
}

20 Feb
1 month ago

JordanDalton left a reply on Eager Loading Specific Columns

Replace book_id with what column you're using to attach the author.

JordanDalton left a reply on Eager Loading Specific Columns

Book::where('public', 1)
    ->with([''author' => function($query){
            $query->select(['id', 'name']);
        }])
    ->take(10)
      ->get(['id', 'user_id', 'name', 'author'])->toJson();
16 Jun
10 months ago

JordanDalton left a reply on Not Getting Expected MassAssignmentException

Ad 'po' to your fillable.

10 Feb
1 year ago

JordanDalton left a reply on Laravel Insert Data Twice When Timeout Occurs

YourModel::firstOrCreate($attributes);

JordanDalton left a reply on Most Stable Version Of Laravel?

5.6 is stable. The only issue you may run into is packages not being updated to support it yet.

24 Jan
1 year ago

JordanDalton left a reply on Get Users That Doesn't Relate To This Workplace So I Can Atach Them Later

$users = User::where('role_id', '=', 3)->Where DoesntHave('workplaces', function($query) use($ignore_id){ $query->whereId($ignore_id);}>get();

20 Jan
1 year ago

JordanDalton left a reply on Best Way To Track Link Clicks

As long as you have a good database server you’ll be fine. Laravel has a router match event that gets fired. You could write a listener that pushes a job to a queue that get processed at a later time.

17 Jan
1 year ago

JordanDalton left a reply on Broadcast Channel Authorization Is Not Being Called

Try changing ".new.message" to "new.message"

15 Jan
1 year ago

JordanDalton left a reply on Insert Into Database

Is mysql showing as installed when you run phpinfo()?

JordanDalton left a reply on Insert Into Database

No. I was just curious.

JordanDalton left a reply on Insert Into Database

Are you using homestead?

JordanDalton left a reply on Insert Into Database

Also share your migration for the messages table.

JordanDalton left a reply on Insert Into Database

Are you actually connected to the database?

03 Feb
2 years ago

JordanDalton left a reply on Cannot Sync Null Value To DB In Laravel 5.4...

Looks like your migration didn't have nullable() added to the children_order field of the items table.

10 Dec
2 years ago

JordanDalton left a reply on There's Any Formal Way To Add Helpers To Laravel?

I prefer to put mine in App/Support so it matches where Laravel places theirs.

09 Dec
2 years ago

JordanDalton left a reply on Laravel Is A Giant Waste Of Time

The community is here to help you. I understand your having a tough time but I'm more than happy to help you out (online or offline). I've been using Laravel since the day Version 3 was release (almost 5 years ago).

25 Oct
2 years ago

JordanDalton left a reply on What I Hate The Most In Laravel, Routing!

You can always break the routes into separate files (like routes_admin.php, routes_api.php). This is what I do to keep things organized.

22 Oct
2 years ago

JordanDalton left a reply on Laravel On AWS Elastic Beanstalk

I recently did a Laravel migration from digital ocean to AWS elastic beanstalk. With regard to your error did you set the software configuration variables in AWS prior to running eb deploy?

05 Sep
2 years ago

JordanDalton left a reply on Refactoring My Event Resource

I would probably do something like this:

<?php

namespace App;

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

class EventModel extends Model {

    public function scopeExcluding($query, $ids = [])
    {
        return $query->whereNotIn('id', $ids);
    }

    // Query scope definition that will only fetch the upcoming events.
    public function scopeUpcoming($query)
    {
        return $query->where('start_date', '>=', Carbon::now())
                     ->IsPrivate(false)
                     ->IsArchived(false)
                     ->IsPublished(true)
                     ->IsCancelled(false);
    }

    // Query scope definition that will only fetch the a particular $user's events
    public function scopeMy($query, User $user)
    {
        $user_events = $user->reservations()->pluck('event_id');

        return $query->whereIn('id', $user_vents)
                     ->where('start_date', '>=', Carbon::today());
    }
}
<?php

class DashboardController extends Controller {

    use EventTrait;
}
<?php

trait EventTrait {

    public function getMyEvents(User $user){
        return EventModel::my($user)->get();
    }

    public function getUpcomingEvents()
    {
        $ids = auth()->user()->reservations->pluck('event_id');

        return EventModel::upcoming($ids)->excluding($ids)->get();
    }
}

JordanDalton left a reply on How To Enable Subdomains

Sounds like a DNS issue. You'll need to add an A record so that imageshare points to your server IP.

25 Jun
3 years ago

JordanDalton left a reply on Pagination Not Working

Try using $request->except('page');

14 Jun
3 years ago

JordanDalton left a reply on Issues With Event Broadcasting Using Pusher

Turned out to be a timezone issue. I fixed it by running the following command in Homestead SSH:

sudo ntpdate ntp.ubuntu.com

Everything now works fine :)

JordanDalton left a reply on Issues With Event Broadcasting Using Pusher

I've done some debugging of the curl request generated. The following came up:

    [body] => Timestamp expired: Given timestamp (2015-06-15T03:30:47Z) not within 600s of server time (2015-06-15T03:41:33Z)

    [status] => 401

Looks like 401 is an authentication issue.

JordanDalton started a new conversation Issues With Event Broadcasting Using Pusher

I'm having issues doing event broadcasting using Pusher. My event are being fired and sent out through the queue. However, it seems that the broadcasts are not actually reaching pusher.

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.1.*",
        "twilio/sdk": "dev-master",
        "pusher/pusher-php-server": "~2.2.1"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-root-package-install": [
            "php -r \"copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}
    // AppServiceProvider...
    public function boot()
    {
        Company::observe(new CompanyObserver);
    }
  // CompanyObserver
    public function created( $model )
    {
        event( new CompanyCreated( $model ) );
    }
<?php

namespace App\Events;

use App\Company;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class CompanyCreated extends Event implements ShouldBroadcast
{
    use SerializesModels;

    public $company;

    /**
     * Create a new event instance.
     *
     * @param Company $company
     */
    public function __construct( Company $company )
    {
        $this->company = $company;
    }

    /**
     * Get the channels the event should be broadcast on.
     *
     * @return array
     */
    public function broadcastOn()
    {
        return ['test-channel'];
    }
}
    var pusher = new Pusher('{{ config('broadcasting.connections.pusher.key') }}');
    var channel = pusher.subscribe('test-channel');
    channel.bind('App\Events\CompanyCreated', function(data)
    {
        alert(data);
    });

To prove there is socket traffic I trigger an event from Pusher console which generates an alert on my page which is the expected behavior.

// Create the record which fires the event.
Route::get('/event', function () {

    $company = new App\Company;
    $company->name = str_random(5);
    $company->name_slug = str_random(5);
    $company->twilio_friendly_name = str_random(5);
    $company->save();

    return 'done';
});

This creates the following job in the jobs database:

{"job":"Illuminate\\Broadcasting\\BroadcastEvent","data":{"event":"O:25:\"App\\Events\\CompanyCreated\":1:{s:7:\"company\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":2:{s:5:\"class\";s:11:\"App\\Company\";s:2:\"id\";i:97;}}"}}

Fire up the queue listener:

php artisan queue:listen

The following feedback in the terminal:

Processed: Illuminate\Broadcasting\BroadcastEvent

The job gets processed and is removed from the table but nothing ends up arriving at Pusher.

25 Dec
4 years ago

JordanDalton left a reply on Environment Variables Returning Blank.

I wanted to provide you all an update. Forge does not currently map the environment variables to the new environment file format (.env, not .env.php like before). You'll need to manually create/upload your .env file for the time being.

22 Dec
4 years ago

JordanDalton started a new conversation Environment Variables Returning Blank.

I setup a Larave 5 project using Forge tonight. I set multiple environment variables in Forge but when I SSH into the application $_ENV comes back empy. Any ideas?

16 Dec
4 years ago

JordanDalton started a new conversation Laravel 5 Domain Route Annotation

Given that the URL most of the time differs between development and production environment it seems that route annotations specific to domains should allow a list of domains.

So the following

@Controller(domain="{id}.yourdomain.com")

Would allow:

@Controller(domain={"{id}.developmentdomain.com", {id}.productiondomain.com"})

I think many could benefit from this but I wanted to see what others thought about this.

04 Dec
4 years ago

JordanDalton left a reply on How To Connect To DB2

You could use Doctrine.

04 Nov
4 years ago

JordanDalton left a reply on Where Are You All From?

Robinson, TX (just outside of Waco)

11 Sep
4 years ago

JordanDalton left a reply on [5.0] Where To Register Interface Bindings

You should be able to define them in AppServiceProvider (App\Providers\AppServiceProvider.php).

10 Sep
4 years ago

JordanDalton left a reply on Uploaded To Github & Forge But Get This....

No problem. Anytime. I'm glad it worked out.

JordanDalton left a reply on Uploaded To Github & Forge But Get This....

Run the following command and paste the results:

composer --profile -vvv install

JordanDalton left a reply on Uploaded To Github & Forge But Get This....

Is this after bumping up the memory as well as running composer install?

JordanDalton left a reply on Uploaded To Github & Forge But Get This....

You should have at least 1GB of ram.

JordanDalton left a reply on 4.3 Validation Errors

If I'm not mistaken you can't currently do this in 4.3.

JordanDalton left a reply on Uploaded To Github & Forge But Get This....

How much ram is on your machine?

JordanDalton left a reply on Uploaded To Github & Forge But Get This....

Looks like you need to run composer install.

JordanDalton left a reply on Laravel Issue Of The Day For Me

I'm downloading your repo to test. I'll update you shortly.

JordanDalton left a reply on Laravel Issue Of The Day For Me

Sounds like you may have an <?php or blade {{ tag that is not properly closed. Can you share the contents of the contactemail.blade.php file?

The only other thing I could think of if that there's a required dependency that you're missing.