0 Best Reply Awards

  • Member Since 3 Years Ago
  • 132 Lessons Completed
  • 0 Favorites

10th August, 2016

CodePuppet left a reply on Best Practice To Repeat Small Functions • 1 year ago


I would extract your fetching of the countries from the Controller into another class and then inject it into the controller. For example:


class CountryRepository {

     * Get all the countries.
    * @return array
    public function all()
        // Consider using an Eloquent Model here for the country.
        // Then your code would look like: Country::all();
        return DB::table('list_countries')->select('countryid', 'name')->get();

Now in your controller you can inject this class.

    public function list_countries(CountryRepository $countries) 
        $countries = $countries->all();
        return view ('auth.register', compact ('countries'));

5th June, 2016

CodePuppet left a reply on Laravel Valet 403 Forbidden Error • 2 years ago

I was also getting this error... I ran sudo apachectl stop and then valet start. Fixed it for me.

5th March, 2016

CodePuppet left a reply on Adjacency Model And Recursive Function • 2 years ago

  • A Collection is really just a wrapper of an array and allows you to manipulate your list (array) in many ways
  • Regarding your second question, are you trying to add an attribute on each of your items that you're adding to your collection, or the collection itself?

3rd September, 2015

CodePuppet left a reply on Access Parent Model After Eager Load • 2 years ago

@uxweb Thank you for the response. I have that setup, and am in fact accessing it like that. The problem is that it's running an extra query to fetch the folder when accessing $this->folder, when it shouldn't be. It should already have that relation loaded, since the file was loaded eagerly through the folder with $folder->with(['files']).

CodePuppet started a new conversation Access Parent Model After Eager Load • 2 years ago

Hi all,

I have two models, Folder and File. A Folder has many Files and each File belongs to a Folder.

I eager load the files on each folder like so:

$files = $folder->with(['files'])->get()...

However, let's say I want to access the folder's title, from within the file:

public function getTitleAttribute() {
   return $this->folder->title;

The $folder relation isn't initialized so it'll perform a query to fetch the folder, for each of the file models. Shouldn't this relation already be initialized, since I eager loaded these files THROUGH the folder.

I know I can do this to make it work, but I feel like I'm missing something and I shouldn't have to do this:

$folder->with(['files', 'files.folder']);

Please let me know if I need to clarify anything. I appreciate the help!

29th November, 2014

CodePuppet left a reply on Moving Between Filesystems • 3 years ago

All you really need to do is something like:

function sendToCloud(Filesystem $filesystem, Cloud $cloud, $path)
    $contents = $filesystem->get($path);
    $cloud->put($path, $contents);

20th November, 2014

CodePuppet left a reply on Custom Error Messages • 3 years ago

It looks like your validation is happening within your model. Check your User model's save() method to see if Validator::make() is being called there. You can pass custom messages to this method.

Edit Your Profile

Want to change your profile photo? We pull from