tfevens

tfevens

Member Since 5 Years Ago

Experience Points
26,495
Total
Experience

3,505 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
374
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.

Level 6
26,495 XP
10 Oct
1 year ago

tfevens left a reply on Trouble Hooking Onto "created" For Model

Not gonna lie, I thought the same thing.

What I had done originally to accomplish this, was create an Observer. In the Observer class, I added a method for the event that I want to listen for, in this case created(). Once I register the Observer in AppServiceProvider.php Laravel did the rest for me.

I didn't have to add any other properties or Event/Listeners, just registering the Observer did the trick.

I can see how more complex requirements would have use in creating specific Events & Listeners, but where you're working with Model events, for one model (for now at least) I think that the Observer class is adequate for your needs.

tfevens left a reply on Trouble Hooking Onto "created" For Model

Your code works... This is in 5.5, but I can't imagine it wouldn't work in 5.4 as well.

Model:

    public static function boot()
    {
        parent::boot();
    
        self::created(function ($model) {
            dd('So this worked...');
        });
    }

Create and save the model:

Route::get('test',function() {
    $deal = new Deals([
    ...
    ]);

    $deal->save();
});

And I get this in the browser: '"So this worked..."'

So - what you're doing should be working, but the code inside your created method doesn't seem to be getting executed as you would think it should.

tfevens left a reply on Trouble Hooking Onto "created" For Model

It's legacy code, which occasionally works in newer versions... I'll try to play around with your existing code and see if I can manage to come up with anything.

tfevens left a reply on Trouble Hooking Onto "created" For Model

It looks like you'll need at least one more class in order to do this.

I was able to accomplish this by creating an Observer class (App/Observers) and registering it in AppServiceProvider.

So... I've added nothing to the model, on the boot method of AppServiceProvider.php added User::observe(UserObserver::class); (with appropriate use statements) and then in the new App\Observers, the UserObserver class, with a 'created' class:

public function created()
    {
        dd('Yup!');
    }

Creating a new User Model will fire the created event and it is picked up by the Observer, and the output is shown.

tfevens left a reply on Trouble Hooking Onto "created" For Model

What version of Laravel? In Laravel 5.5 you need to add $dispatchesEvents on your model.

Take a look at https://laravel.com/docs/5.5/eloquent#events

12 Sep
2 years ago

tfevens left a reply on Possible To Use Multiple Keys When Querying A Relationship?

@Snapey Sorry - Thought the image link would work from Slack! Here's the image at imgur - https://imgur.com/a/nD2Jp.

I guess the question is the relationships, and what will be needed for each.

In my original thinking, I didn't create a relationship between Items and Retailers as I thought I could link them by using Pricing or Item_Retailer_Links (the latter to work as kind of a many-to-many relationship).

Again, I'm willing to rework my DB and the relationships involved, so if that's the best way to go about this, then so be it.

11 Sep
2 years ago

tfevens started a new conversation Possible To Use Multiple Keys When Querying A Relationship?

Background DB tables: https://files.slack.com/files-tmb/T03860VUN-F725DSB70-7480b7789b/tables_480.jpg

What I'm looking for is a way to specify relationships such that I'm able to do something like

Item::where('slug',$slug)
      ->with(
        'retailers',
        'retailers.link',
    'retailers.price'
      )
      ->first();

End result is that I can loop through the retailers, providing the price for the product and a link with which to buy at each retailer. My trial and error has been unsuccessful, as everything I've tried only allows one foreign key to be used in the search, so multiple results are returned for each retailer. For example, if I have 5 retailers for a product, there will be 5 prices and 5 links, however it pulls 5 prices and 5 links, for EACH of the 5 retailers. If I could query based on the retailer_id AND the item_id, I think that the proper results would be returned.

Is it even possible to do? Or, is my schema faulty and needs to work? Any advice is welcome!

22 Jun
3 years ago

tfevens started a new conversation Sentinel And Redirect()->with() Doesn't Display Flash Data

The issue is that after logout(), I'm redirecting back to the login page, and setting a "loggedout" message in the flash data. Here's the relevant code:

routes.php

<?php 
use Illuminate\Http\Request;

Route::get('/', function()
{
    return View::make('welcome');
});

// Authentication Routes
Route::get('login', ['uses' => '[email protected]', 'as' => 'login']);
Route::post('login', ['uses' => '[email protected]']);
Route::get('logout', ['uses' => '[email protected]', 'as' => 'logout']);

AuthController.php

<?php namespace App\Http\Controllers;

use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
use Illuminate\Http\Request;

class AuthController extends Controller
{

    public function index()
    {
        if (Sentinel::check()) {
            return redirect('/');
        }
        else {
            return view('auth.login');
        }
    }

    public function login(Request $request)
    {
        $creds = [
            'email' => $request->input('login'),
            'password' => $request->input('password')
        ];
        if ($user = Sentinel::authenticate($creds)){
            if (Sentinel::inRole('admin')) {
                return redirect('admin');
            }
            return redirect('authtest');
        }
        else {
            return redirect('login')->with("error","Username or Password incorrect.")->withInput($request->except('password'));
        }
    }

    public function logout()
    {
        if (Sentinel::check()) {
            if (Sentinel::logout()) {
                return redirect('login')->with("loggedout", "You have been logged out!");
            }
        }
        return redirect('login');
    }
}

login.blade.php

@if (session('loggedout'))
    <div class="alert alert-success">
        {{ session('loggedout') }}
    </div>
@endif

Does anyone see anything that would cause the flash data to be displayed?

20 May
3 years ago

tfevens left a reply on String Literals Vs Consts Overuse?

@martinbean I'm particularly interested in your implementation here. I'm trying to do something similar, but I'm trying to use the constant in my view:

@if($attribute->gameAttributeType_id == GameAttributeType::ESRB)
        // ...
@endif

which is failing with Use of undefined constant GameAttributeType - assumed 'GameAttributeType'.

How were you using the constants, and any advice on using these in a view?

20 Feb
4 years ago

tfevens left a reply on Pagination & Collections

Yeah, that was basically what I came up with too:

$pagination = Article::with('feed')
                ->orderBy('created_at','desc')
                ->paginate(17);

$articles = $pagination->getCollection();

Thanks!

tfevens left a reply on Pagination & Collections

@JarekTkaczyk, thanks for the response. I had missed that method completely.

However, it doesn't seem to be working.

$articles = Article::with('feed')
                ->orderBy('created_at','desc')
                ->paginate(10);
    echo $articles->count();
    $articles->getCollection()->shift();
    echo $articles->count();

is returning 10 on both occasions.

I can work around this by creating a new variable and assigning it the value of $articles->getCollection(), but that seems a little 'hacky'. Is there any reason why the method isn't chainable, or am I doing something totally off?

tfevens started a new conversation Pagination & Collections

In my app I'm currently displaying a list of articles, returned as an instance of Illuminate\Database\Eloquent\Collection. I can use $articles->shift() to grab the first article, and remove that from the Collection (displaying 2 articles, then an info box, and then looping through the remaining articles) without running into any issues.

However, now that I want to add pagination to the app, I'm being handed back an instance of Illuminate\Pagination\Paginator. This isn't allowing me to use $articles->shift() to pull the first 2 articles out. I'm not getting an error, but the same article is displayed three times.

Has anyone else ever come across this? If so, how did you go about working around it?

I have found out that if I modify Illuminate\Pagination\Paginator to extend Collection that everything works as I want, but this isn't really a viable option without it being added to the core Laravel files.

Any advice would be welcome!

02 Jan
4 years ago

tfevens left a reply on Socialite With 4.2.* Apps

illuminate/contracts is Laravel 5 only, so you would have to do a lot of 'hacking' to get it to work with 4.2.

11 Dec
4 years ago

tfevens left a reply on File Lists And Regex

Here's the entire class at this point:

<?php

Class Files {

 public $ignoredFiles = [
     '.',
     '..',
     "error_log",
     "index.php",
     "Thumbs.db",
     '([0-9]){4}_([0-9]){2}_([0-9]){2}.txt'
     ];

 public function getFilesAsArray($dir)
 {
  if ($handle = opendir($dir)) {
   $array = [];
   while (false !== ($entry = readdir($handle))) {
    foreach ($this->ignoredFiles as $file) {
     if (!preg_match('/^'.$file.'/u', $entry, $match)) {
      $array[] .= $entry
      break;
     }
    }   
   }
  }
  closedir($handle);
  return $array;
 }

 public function getFilesAsList()
 {
  // Code here
 }

}

tfevens left a reply on File Lists And Regex

Which is great, but wouldn't work for preg_match().

tfevens started a new conversation File Lists And Regex

Hey guys

I inherited some really old and awful code for displaying files (filename and filesize in specific) for a directory. I'm attempting a re-write to try and clean things up, and make the code much re-usable.

As far as getting a file listing goes, I'm pretty good with

if ($handle = opendir($direcotry)) {
    while (false !== ($entry = readdir($handle))) {
        echo "$entry<br>\n";
    }
    closedir($handle);
}

My problem is trying to exclude certain items from being displayed. '.', '..', 'Thumbs.db', and some others should be excluded. A simple if ($entry != "." && $entry != ".." && $entry != "error_log" && $entry != "index.php" && $entry != "Thumbs.db", $entry)) would work for that, but another file I want to avoid is a 'log file' of files uploaded each day (auto-created by the script we use). I've got a regular expression that works, and in theory I could just append that onto the end of the mentioned if statement.

I'm trying to get this working in nice DRY OO code. I've setup an $ignoredFiles array, and added each file I want to hide in the array, including the pattern for the regular expression. Inside the while statement, what is the best way for me to check if the current filename ($entry) matches anything in the $ignoreFiles array?

Thanks!

10 Oct
4 years ago

tfevens left a reply on Consuming RSS With SimplePie And Strip_htmltags

Yeah, I'm thinking SimplePie is just completely broken at this point. I swapped the version to 1.4-dev, and if I attempt to change $this->strip_htmltags at all, it removes basically all of the content, without actually changing what SimplePie::strip_htmltags contains.

For example: Without altering SimplePie::strip_htmltags at all, an article in the RSS feed returns:

["content"]=> string(4337) "

As soon as I set SimplePie::strip_htmltags ($data->strip_htmltags(array('div','ul'));) content get's cut off...

["content"]=> string(13)

... while the value SimplePie::strip_htmltags is still an array(19).

If there's a viable alternative for SimplePie, I'd really like some suggestions.

tfevens left a reply on PhpStorm

Jeff's done an entire series on phpStorm. Take a look at it -> https://laracasts.com/series/how-to-be-awesome-in-phpstorm

09 Oct
4 years ago

tfevens started a new conversation Consuming RSS With SimplePie And Strip_htmltags

First - is there another 'new' actively maintained package that does what SimplePie does? I'm aware of Guzzle, but not sure that it has the built in 'rss' stuff that SimplePie does. If someone can 'convince me' to switch to Guzzle, I'd be willing to change up.

Next, has anyone used/does anyone currently use SimplePie? I'm trying to strip un-necessary html tags from the content using strip_htmltags(), and I'm following the exact same steps as in the demos, but I can't get it to work. I've tried using 1.4-dev and 1.3.1 to no avail. I recall that this was working at some point in the past, and I'm guessing that an update somewhere in the process has broken it.

According to the SimplePie Docs the following code should have ONLY div and span as values.

var_dump($data->strip_htmltags); // Default tags
$data->strip_htmltags(array('div','span')); // Set it to only strip div and span
var_dump($data->strip_htmltags); // Expected to be only div and span

The above it outputting the following:

array(19) { [0]=> string(4) "base" [1]=> string(5) "blink" [2]=> string(4) "body" [3]=> string(7) "doctype" [4]=> string(5) "embed" [5]=> string(4) "font" [6]=> string(4) "form" [7]=> string(5) "frame" [8]=> string(8) "frameset" [9]=> string(4) "html" [10]=> string(6) "iframe" [11]=> string(5) "input" [12]=> string(7) "marquee" [13]=> string(4) "meta" [14]=> string(8) "noscript" [15]=> string(6) "object" [16]=> string(5) "param" [17]=> string(6) "script" [18]=> string(5) "style" }

array(19) { [0]=> string(4) "base" [1]=> string(5) "blink" [2]=> string(4) "body" [3]=> string(7) "doctype" [4]=> string(5) "embed" [5]=> string(4) "font" [6]=> string(4) "form" [7]=> string(5) "frame" [8]=> string(8) "frameset" [9]=> string(4) "html" [10]=> string(6) "iframe" [11]=> string(5) "input" [12]=> string(7) "marquee" [13]=> string(4) "meta" [14]=> string(8) "noscript" [15]=> string(6) "object" [16]=> string(5) "param" [17]=> string(6) "script" [18]=> string(5) "style" }

So, I'm at a loss. Has anyone ran into this? Any suggestions?

Thanks!

08 Oct
4 years ago

tfevens left a reply on Running `composer Update` Or `php Artisan` Return Error

I think there might be some issues running composer with a Laravel 5 install today. Take a look at https://laracasts.com/discuss/channels/general-discussion/life-belt-for-early-l5-adopters-pull-in-specific-composer-commit and see if that works for you.

tfevens left a reply on Consuming RSS Feeds With Guzzle

@shailesh91 - If you figure this out and get it working for you, I'd love to see it!

If I may ask, any reason that you went with Guzzle instead of SimplePie for RSS feeds?