Buy your loved one the ultimate gift. Lifetime gift certificates are $100 off.

nscherneck

Experience

29,160

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 274 Lessons Completed
  • 2 Favorites

6th December, 2017

nscherneck left a reply on Filter By Intermediate Column On Pivot Table With Query Builder • 1 week ago

I overcame my lack of experience with query builder raw expressions and found that this was pretty simple, actually...

    protected function components($components)
    {
        natsort($components);
        $components = array_values($components);
        return $this->builder->select('systems.*', DB::raw('SUM(components_systems.quantity) as component_quantity'))
            ->join('components_systems', 'systems.id', '=', 'components_systems.system_id')
            ->groupBy('components_systems.system_id')
            ->havingRaw('SUM(components_systems.quantity) BETWEEN ' . $components[0] . ' AND ' . $components[1])
            ->get();
    }

nscherneck started a new conversation Filter By Intermediate Column On Pivot Table With Query Builder • 1 week ago

I have two models, systems and components. Systems and components are a many-to-many relationship, therefore I have a pivot table called components_systems which has an additional column for quantity.

I’m building filtering for systems where I’d like the user to be able to filter by a range of component quantities.

Is it possible to use a whereBetween on an additional column on a pivot table?

2nd October, 2017

nscherneck started a new conversation Sami For API Documentation • 2 months ago

Hey all,

I'm in the process of implementing Sami for the first time. Laravel's API documentation uses it and clicking around from method to method is really helpful. What I'm unsure about is when implementing it for a Laravel built application, which directories should I typically include and exclude? Seems like it would be helpful to include the Illuminate namespace so that, as an example, when I go to my Site.php model, which has class Site extends Model, it has a usable link for Model and other framework code.

20th September, 2017

nscherneck started a new conversation Best Practices For @link Type In Docblocks • 2 months ago

I'm learning more about docblocks and the various API documentation tools available in the PHP community. I'm curious about best practices for using the @link type within a docblock. I have a Laravel based app and was thinking it would be convenient to add links to relevant sections of the Laravel documentation within my code base. For instance, in my models, where I define relationships, it would be handy to link to the Laravel docs for that specific type of relationship. Just curious if this is a misuse of the @link type.

From the PHPDocumentor reference:

The @link tag indicates a custom relation between associated Structural Elements and a website, which is identified by an absolute URI.

18th September, 2017

nscherneck left a reply on Documentation Template • 2 months ago

As far as I know, the Laravel documentation is generated with Sami.

28th August, 2017

nscherneck left a reply on Eager Load Sum On Pivot Table • 3 months ago

$system->components->sum('pivot.quantity');

This is just what I needed...Thanks so much!

24th August, 2017

nscherneck left a reply on Eager Load Sum On Pivot Table • 3 months ago

@andonovn Thanks for your reply. My apologies for being a little vague in my question. What I'm doing is iterating over the systems on an index page, and therefore I want to prevent an additional query. Ideally, I'd eager load the sum of components with each system.

The way you're summing the components does get rid of the sumComponents() method I'd created in my System model, so thank you!

23rd August, 2017

nscherneck started a new conversation Eager Load Sum On Pivot Table • 3 months ago

I have a many-to-many relationship with a pivot table of components_systems which an extra ttribute of quantity. I'd like to eager load the quantity of components on the system. Is this possible?

2nd August, 2017

nscherneck started a new conversation App Architecture / Separation Of Concerns Question • 4 months ago

I'm implementing a feature in my app and I think it's a good opportunity to improve my understanding of SOLID principles.

My app has customer sites app/Site.php which includes fields for site coordinates. Same for branch offices app/BranchOffice.php. On my sites.show view I want a table showing travel distance and times from each branch office to that site.

So right now I'm making a cURL call to GoogleMaps API directly in my app/Site.php and I feel like this violates single responsibility. Would you maybe create a maps service class for this, and if so where would it go? Would you create an app/Services/ directory?

Seems like I should arrange it so I can easily swap out to MapQuest of OpenStreetMaps APIs if need be.

27th July, 2017

nscherneck started a new conversation PHPUnit Error • 4 months ago

I'm trying to resolve this error I get when using the alias for PHPUnit. I have PHPUnit installed globally and am using Valet. If I run ./vendor/bin/phpunit my tests run fine. But if I try the alias phpunit, I get this error...

Uncaught Error: Call to undefined method SebastianBergmann\Environment\Runtime::discardsComments() in /Users/Nathan/.composer/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:332

If I run an echo $PATH I get this...

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/Nathan/bin:/usr/local/bin:/Users/Nathan/.composer/vendor/bin:

Is my path messed up or is this something else?

PHP 7.1.6

13th July, 2017

nscherneck left a reply on Issue Installing Valet • 5 months ago

Got it working. I uninstalled PHP7.1 and dnsmasq via homebrew, removed valet via composer, then reinstalled them all. Works like a charm.

12th July, 2017

nscherneck left a reply on Issue Installing Valet • 5 months ago

An update on this. In realizing that 7.2 is still in testing I reverted back to 7.1 which resolved the DomainException. Don't think the versions were actually a factor, more likely the way 7.2 had been installed. So now I can do a successful valet start but sites still aren't being served. Anything else I can try to troubleshoot?

11th July, 2017

nscherneck started a new conversation Issue Installing Valet • 5 months ago

Hey all,

Setting up my first Mac. I've installed Valet, but sites are not being served. If I run valet start I get the following error...

[DomainException]
  Unable to determine linked PHP.

I searched around for that and found this thread. I tried the steps in the answer, but I get the same error as before. When I run ls -la /usr/local/bin | grep bin/php$ I get lrwxr-xr-x 1 Nathan admin 37 Jul 11 18:28 php -> ../Cellar/php72/7.2.0alpha2_1/bin/php.

21st June, 2017

nscherneck left a reply on 500 Error On Any Use Of Eloquent • 5 months ago

@tisuchi...good catch, but it was just a typo because I'd retyped in my original post. That wasn't in my actual code.

@Snapey, that was it. I'd eager loaded a relationship from the parent and the child models. Thank you!

20th June, 2017

nscherneck left a reply on 500 Error On Any Use Of Eloquent • 5 months ago

@Snapey that gives the following error.

>>> $customers = App\Customer::all();
PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 102400 bytes) in /home/vagrant/Code/ssi-web/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php on line 91
PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 65536 bytes) in /home/vagrant/Code/ssi-web/vendor/composer/ClassLoader.php on line 444

nscherneck left a reply on 500 Error On Any Use Of Eloquent • 5 months ago

Oops, should have mentioned...nothing is added to the log file and I don't get an error page.

nscherneck started a new conversation 500 Error On Any Use Of Eloquent • 5 months ago

I have an existing app that has thrown me a curve ball. It's been about a week since I worked on it, and now when I go to my development environment (Ubuntu host running Vagrant/Homestead) I get a 500 error on all pages. After some troubleshooting, I've determined I'm getting the error any time I use eloquent to return any of my models. For instance, in a controller, I can...

$customers = DB:table('customers')->get();
dd($customers);

Works just fine and I get a 200. But if I do this...

use App\Customer;

$customers = Customer::all();
dd($customers);

I get a 500 error.

11th May, 2017

nscherneck left a reply on No Webpack.mix.js • 7 months ago

Noticing a minor bug in the forum...the numbered bullets show as 1. and 2. when I'm composing the post, but both show as 1. in the saved post.

nscherneck started a new conversation No Webpack.mix.js • 7 months ago

I recently upgraded a 5.3 application to 5.4 and am now getting around to transfer parts of the app to Vue components. A few questions...

  1. I followed the 5.3 to 5.4 upgrade guide, but I didn't see anything about changing package.json. Here's what I had...
{
  "private": true,
  "scripts": {
    "prod": "gulp --production",
    "dev": "gulp watch"
  },
  "devDependencies": {
    "bootstrap-sass": "^3.3.7",
    "gulp": "^3.9.1",
    "jquery": "^3.1.0",
    "laravel-elixir": "^6.0.0-9",
    "laravel-elixir-vue": "^0.1.4",
    "laravel-elixir-webpack-official": "^1.0.2",
    "lodash": "^4.14.0",
    "vue": "^1.0.26",
    "vue-resource": "^0.9.3"
  }
}

Looks like some out of date stuff in there (vue-resource). Curious if I was supposed to update this manually (I went ahead and did that), or if it was supposed to be updated during the composer update?

  1. I've gone ahead and copied the package.json file from 5.4 and run npm install, which installed Laravel Mix, however, there's no webpack.mix.js. Was this supposed to generate during the npm install or do I just manually create it?

28th April, 2017

nscherneck started a new conversation Add Table In Dev Environment, Production Server Has A Lot Of Live Data • 7 months ago

I need to add a new table to an existing Laravel app. I want to add it in my dev environment, with a migration, and build up the associated tests. This app was not originally created with migrations, the migrations were added later with migrations-generator. I've searched threads for info on how to run the migrations in production without overwriting the live data, but I haven't found a solution. Am I missing something obvious in the Laravel docs? Perhaps I have to manually create the table and then create the migration (for testing) using the migrations-generator?

23rd April, 2017

nscherneck left a reply on Laravel Debug-bar • 7 months ago

Thank you @Snapey. This lead to learning more about the composer option --no-dev and forced some changes in my workflow. Finally feel confident that my dev packages are only being installed in my local environment.

nscherneck started a new conversation Laravel Debug-bar • 7 months ago

Because the documentation states that the debug-bar will slow down your application, I want to get some clarification on what it means to use it in development only. I've got a local environment, staging server, and production server. So if I've got APP_DEBUG set accordingly in my respective .env files, is this what's meant by development only? Or should it be in the require-dev section of the composer.json file, or both?

2nd April, 2017

nscherneck left a reply on Task Scheduler Problem • 8 months ago

@Snapey adding the user to the www-data group resolved the problem. Thank you!

1st April, 2017

nscherneck left a reply on Task Scheduler Problem • 8 months ago

Hmm I think you're right about that. I waited a while and retried php artisan schedule:run but got this...

Running scheduled command: Closure

[ErrorException]
  file_put_contents(/var/www/ssiweb/storage/framework/views/a269d7f9a5471b42ed5fb91632f3506411b46821.php): failed to open stream: Permission denied

Permissions on all the view files in that directory are at 644.

By the way, I do have the cron job setup per the Laravel documentation. Don't think there's any issue with that.

nscherneck started a new conversation Task Scheduler Problem • 8 months ago

Hey all,

I just setup Task Scheduler for the first time on a Laravel 5.3 app I have running on a live server. I set it up per the documentation and had it working just fine, sending an email every five minutes. Well, I broke it during my refactoring. Since breaking it, I've broken it down to it's simplest implementation but it still won't send an email. Here's what I have...

app/Console/Kernel.php

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function() {
            Mail::to('[email protected]')->send(new WeeklyUpdate);
        })->everyFiveMinutes();
    }

    /**
     * Register the Closure based commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        require base_path('routes/console.php');
    }
}

app/Mail/WeeklyUpdate.php

class WeeklyUpdate extends Mailable
{
    use Queueable, SerializesModels;


    public function __construct()
    {

    }

    public function build()
    {
        $address = '[email protected]';
        $name = 'App Name';
        $subject = 'Weekly Update from the App';
    
        return $this->view('email.weeklyupdate')    
            ->from($address, $name)    
            ->subject($subject);
    }

}

resources/views/email/weeklyupdate.blade.php

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Weekly Update from SSI-Extranet</title>
  </head>
  <body>

    <h1>TEST</h1>

  </body>
</html>
<br>

If I navigate to my app directory on the live server and run php artisan schedule:run I get No scheduled commands are ready to run. I found some threads related to this and tried php artisan up and tried initiating the scheduled tasks again with no change. My framework permissions are at 777. I also tried php artisan down, but got an error file_put_contents(/var/www/ssiweb/storage/framework/down): failed to open stream: Permission denied.

Any ideas? Thanks in advance.

29th March, 2017

nscherneck left a reply on Letsencrypt • 8 months ago

Hey, just came across this thread. This seems a lot easier than the tutorials I've been reading. Is this for Apache only or are these steps the same for nginx?

23rd March, 2017

nscherneck left a reply on App With Multiple Models, Timestamp Issue • 8 months ago

@vipin93 thanks for this. Though I haven't yet found where, looks like the Photo model is being set to local timezone somewhere.

21st March, 2017

nscherneck left a reply on App With Multiple Models, Timestamp Issue • 8 months ago

To clarify, I want them all to save at UTC time. Not sure why this one model is saving at local time (America/Los_Angeles).

nscherneck started a new conversation App With Multiple Models, Timestamp Issue • 8 months ago

I have an app with about 12 models, all of which save to my database (MySQL) at UTC, which is what I have my config set to...

config/app.php 'timezone' => 'UTC',

All but one are saving at UTC time, but I have one that saves at local time. It's a Photo model, which has a method that saves photos to AWS-S3. Here's the store method on the associated controller...

PhotosController.php

public function storeSystemPhoto(Request $request, System $system)
    {

      $this->validate($request, [
        'image' => 'required|mimes:jpg,jpeg,png,bmp'
      ]);

      // set the name of the file
      $this->setFileName($system);

      $photo = new Photo([
                  'path'            => $this->destinationFolder,
                  'file_name'       => $this->imageName,
                  'ext'             => $request->file('image')->getClientOriginalExtension(),
                  'caption'         => $request->caption,
                  'photoable_type'  => 'App\System',
                  'photoable_id'    => $system->id,
                  'added_by'        => Auth::id()
              ]);

      // save model
      $photo->save();

      // get instance of file
      $file = $this->getUploadedFile();

      // pass in the file and the model
      $this->saveImageFiles($file, $photo);

      flash('Success!', 'Photo added.');
      return redirect()->route('system_show', ['id' => $system->id]);
    }

I've verified all settings on my server (VPS on Digitalocean) are correct (UTC). I'm not sure where else I'd look to troubleshoot this. Any ideas?

16th February, 2017

nscherneck left a reply on Multiple Nested One-to-many Relationship, With Constraint • 9 months ago

@awoyele hmmm, it would need further constraint, i.e...

      $customers = Customer::find($request->customer_id)->systems()->with(['tests' => function ($query) {
          $query->whereBetween('test_date', [$request->start_date, $request->end_date]);
      }])->get();

But of course that doesn't work.

nscherneck left a reply on Multiple Nested One-to-many Relationship, With Constraint • 9 months ago

@Snapey, I think I'd need to combine these two things. I understand the dynamic scope for the tests, but I'm not sure how to go about hasManyThrough when I've got four tables involved. Customer->Site->System->Test

3rd February, 2017

nscherneck started a new conversation Multiple Tested One-to-many Relationship, With Constraint • 10 months ago

I've got an application where Customer hasMany Sites, Site hasMany Systems, and System hasMany Tests. I'm trying to add at the ability to search for all tests for a chosen customer. I've been searching the docs for how to accomplish this, but I'm still confused. My understanding is I have two many nests for hasManyThrough. So I have this...

    public function search(Request $request)
    {

      $tests = Test::orderBy('test_date', 'desc')
        ->whereBetween('test_date', [$request->start_date, $request->end_date])
        ->get();

      return view('tests.search_results', compact('tests'));
    }

Which gives all tests within the range, but for all customers. How would I add the customer_id constraint?

1st February, 2017

nscherneck left a reply on Carbon "overflow" Dates • 10 months ago

That did it. Thank you!

nscherneck started a new conversation Carbon "overflow" Dates • 10 months ago

I'm using Carbon to create a date range for a query using Eloquent..

$start_now = Carbon::now('America/Los_Angeles');
$end_now = Carbon::now('America/Los_Angeles');

$start_date = $start_now->subMonths($b)->startOfMonth()->toDateString();

          if($b === 0)
          {
            $end_date = $end_now->endOfMonth()->toDateString();
          } else {
            $end_date = $end_now->subMonths($b)->endOfMonth()->toDateString();
          }

$testCount = Test::orderBy('test_date', 'desc')
        ->whereBetween('test_date', [$start_date, $end_date])
        ->count();

Problem is, when the day of the month is an "overflow" day (i.e. the 31st), Carbon returns strange results. For instance, from today (1/31)...

0 START: 2017-01-01 END: 2017-01-31
1 START: 2016-12-01 END: 2016-12-31
2 START: 2016-12-01 END: 2016-12-31
3 START: 2016-10-01 END: 2016-10-31
4 START: 2016-10-01 END: 2016-10-31
5 START: 2016-08-01 END: 2016-08-31
6 START: 2016-07-01 END: 2016-07-31
7 START: 2016-07-01 END: 2016-07-31
8 START: 2016-05-01 END: 2016-05-31
9 START: 2016-05-01 END: 2016-05-31
10 START: 2016-03-01 END: 2016-03-31
11 START: 2016-03-01 END: 2016-03-31

I found that this issue had been posted to Carbon, and a solution had been merged, but I haven't been able to implement it.

https://github.com/briannesbitt/Carbon/pull/710

Has anyone run into this and used useMonthsOverflow? There's nothing in the Carbon docs, at least that I could find.

13th January, 2017

nscherneck left a reply on File Response From S3? • 11 months ago

@otepas Indeed. I tested it on a couple other browsers and mobile, and yes it appears to depend on the browser. Thanks so much for your help!

12th January, 2017

nscherneck left a reply on File Response From S3? • 11 months ago

Cleared up the key error with a change to the path I had stored in my database. So now it works, but still downloads, rather than opening inline within the browser.

nscherneck left a reply on File Response From S3? • 11 months ago

Hmm, I like the idea of this, but I'm getting an S3 Error (The specified key does not exist.). The key needs to be the file name alone, or the full path within the bucket? I've tried both and get that same error.

nscherneck started a new conversation File Response From S3? • 11 months ago

I'm trying to open a PDF doc inline in the browser from an S3 bucket using a File Response like so...

public function showReport(Document $document)
{
    return response()->file("https://s3-us-west-2.amazonaws.com/" . $document->path . '/' . $document->file_name . '.' . $document->ext);
}

But I'm getting this error...

does not exist in /var/www/ssiweb/vendor/symfony/http-foundation/File/File.php:37

But I can access the document if I just drop it into a browser. Can you not pass a URL into the file method?

31st December, 2016

nscherneck left a reply on Timezone Conversions • 11 months ago

@jekinney, I hadn't changed the timezone in php.ini. Changed it, restarted php and nginx but no change.

nscherneck started a new conversation Timezone Conversions • 11 months ago

Pretty sure this is a noob question, but I've got a bit of a bug I'm trying to work out. My understanding is that it's best to save dates in UTC and convert to a user's timezone where necessary.

In development (Homestead running locally) my models are saving to my database in UTC time (created_at), but in production (Digital Ocean) they're saving at local time (America/Los_Angeles).

config/app.php...

    'timezone' => 'UTC',

I also ran dpkg-reconfigure tzdata and set to local timezone and again to go back to UTC with, but no change. Is there somewhere else I should be looking?

FYI, my VPS is running Ubuntu 16.04, nginx, PHP-7.0.8, mysql

16th December, 2016

nscherneck started a new conversation Homestead Version Clarification • 11 months ago

I realize this is sort of an irrelevant tidbit of info, but I'm curious to know why the Vagrant box for Homestead is currently at version 1.0.1 but the release version of Homestead is 4.0.1? Is it just a matter of different versioning systems?

For reference...

Homestead on GitHub: https://github.com/laravel/homestead/releases

the Vagrant box for Homestead: https://atlas.hashicorp.com/laravel/boxes/homestead/

15th December, 2016

nscherneck left a reply on Detach On Many-to-many Relationship • 1 year ago

@SaeedPrez I went with the Query Builder version to avoid creating a model for this one use. Thank you!

nscherneck started a new conversation Detach On Many-to-many Relationship • 1 year ago

I'm a bit confused as to how to detach for my application. The example given in the docs is for a user and roles. A user can have many roles, but a user wouldn't have multiple instances of the same role. My application has systems which can have many components. On the pivot table components_systems there are additional columns quantity and description. In theory, the same component could be added with a different description. So how do I go about detaching them individually? Right now I have...

  public function detach(System $system, Component $component)
  {
    $system->components()->detach($component->id);

    flash('Component detached', 'Success');
    return redirect()->route('system_show', ['id' => $system->id]);
  }

Problem is this will detach all instances containing that particular component->id. I need to detach by the id on the pivot table, just not sure how to go about that.

24th November, 2016

nscherneck left a reply on Retrieving A Relationship After A Join • 1 year ago

@jekinney Thanks for your reply. Correct, I don't need columns from the systems model. I'm querying for components that exist in the system and then iterating information about the component. dd() shows me just what I expect, all columns on the components table (for this particular system), and the three columns from the components_systems table.

Your explanation makes sense. Are you saying in order to access the manufacturer columns I need to re-write using Eloquent syntax rather than DB query builder?

To clarify, here are my database tables...

components

id
manufacturer_id
component_category_id
model
description
discontinued

components_systems

id
component_id
system_id
quantity
name

manufacturers

id
name

nscherneck started a new conversation Retrieving A Relationship After A Join • 1 year ago

Hi all,

I'm trying to wrap my head around joins. I have a model called components which has a many-to-many relationship with 'systems' and therefore a pivot table components_systems. components also has a many-to-one relationship with manufacturers. So I'm able to pull the joined data by using the following...

    $comp_panel = DB::table('components')
      ->join('components_systems', 'components.id', '=', 'components_systems.component_id')
      ->where('system_id', '=', $system->id)
      ->where('component_category_id', '=', 1)
      ->select('components.*', 'components_systems.system_id', 'components_systems.quantity', 'components_systems.name')
      ->get();

The problem I'm having is I can't get the manufacturers name using the standard Laravel convention of...

@foreach($comp_panel as $panel)
    {{ $panel->manufacturer->name }}
@endforeach 

Does this convention go away when I've joined another table's data?

15th November, 2016

nscherneck left a reply on Gulp/NPM/Elixir Error On Windows • 1 year ago

I'd love to see a resolution to this as well. My understanding is that it's an issue with Windows not supporting symlinks within the VM. I've read over a dozen threads and tried a lot of supposed solutions, but with no luck. It's got me at a stand still.

31st October, 2016

nscherneck left a reply on Can't Get Elixir Installed • 1 year ago

Eesh, disregard. Hadn't moved to my project folder prior to running the install command.

nscherneck started a new conversation Can't Get Elixir Installed • 1 year ago

Hey all,

I've got a fresh install of Homestead-7 and Laravel. Host machine is Windows 10 x64. I'm going through the steps to use Elixir, but when I run npm install --no-bin-links I get the following...

npm WARN vagrant No description
npm WARN vagrant No repository field.
npm WARN vagrant No README data
npm WARN vagrant No license field.

Any ideas?

17th October, 2016

nscherneck left a reply on ToJson Gives No Key • 1 year ago

Great, that did it. I'll just filter out columns in the model . Thank you!

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.