nscherneck

Experience

14,260

0 Best Reply Awards

  • Member Since 7 Months Ago
  • 133 Lessons Completed
  • 2 Favorites

23rd April, 2017

nscherneck left a reply on Laravel Debug-bar • 2 days 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 • 2 days 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 • 3 weeks 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 • 3 weeks 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 • 3 weeks 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 • 3 weeks 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 • 1 month 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 • 1 month 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 • 1 month 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 • 2 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 • 2 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 • 2 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 • 2 months ago

That did it. Thank you!

nscherneck started a new conversation Carbon "overflow" Dates • 2 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? • 3 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? • 3 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? • 3 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? • 3 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 • 3 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 • 3 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 • 4 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 • 4 months 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 • 4 months 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 • 5 months 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 • 5 months 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 • 5 months 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 • 5 months 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 • 5 months 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 • 6 months ago

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

nscherneck left a reply on ToJson Gives No Key • 6 months ago

Quick response..thank you. Tried this and ended up with the same output as before...

{VLF-250: 6, VLF-500: 7, VLC-RO: 8}
VLC-RO
:
8
VLF-250
:
6
VLF-500
:
7

nscherneck started a new conversation ToJson Gives No Key • 6 months ago

Hey all,

I'm trying to create a dynamic select in an HTML form by way of AJAX.

Here's my javascript...

<script>

function fetch_select(val)
{

 $.ajax({
 type: 'post',
 url: '/update_model_select',
 data: {
  manufacturer_id:val
 },
 dataType: "json",
// success: function (data) {
//     console.log(data);
// }
 success: function (data) {
  document.getElementById("model").innerHTML="<option value=\"" + data.id + "\">" + data.model + "</option>";
 }
 });
}

</script>

My route...

Route::post('update_model_select', [email protected]_model_select');

ComponentsController...

  public function update_model_select(Request $request) {
    $manufacturer = Manufacturer::find($request->manufacturer_id);
    $components = $manufacturer->components->pluck('id', 'model');
    return $components->toJson();
  }

Problem is that I'm not getting the JSON format I was expecting. Here's a sample of the data output from the console...

{VLF-250: 6, VLF-500: 7, VLC-RO: 8}
VLC-RO
:
8
VLF-250
:
6
VLF-500
:
7

I'm not sure how to iterate this out without they keys. Is it possible to return the keys as well?

12th October, 2016

nscherneck left a reply on Eager Loading Multiple Nested One To Many (and A Many To Many) Relationships • 6 months ago

I do, it's components_systems. Come to find out, you can't eager load through a many-to-many relationship.

5th October, 2016

nscherneck started a new conversation Eager Loading Multiple Nested One To Many (and A Many To Many) Relationships • 6 months ago

I've read through quite a few threads looking for some guidance on this. I'm working on an app where:

a Customer hasMany sites, a Site hasMany systems, and a System belongsToMany components (n:m). I have two questions.

First, how do I accomplish eager loading for multiple nested relationships? I'm able to accomplish this at the Customer level...

CustomersController.php

    public function show(Customer $customer) {
      $customer->load('sites.systems')->get();
      return view('customers.show', compact('customer'));
    }

at the Site level...

SiteControler.php

  public function show(Site $site) {
    $customer = Customer::with('sites.systems')->find($site->customer_id);
    return view('sites.show', compact('site', 'customer'));
  }

But when I get to the System level where components are involved do I just append to the dot notation?...

SystemsController.php

  public function show(System $system) {
    $site = Site::find($system->site_id);
    $customer = Customer::with('sites.systems.components')->find($site->customer_id);
    return view('systems.show', compact('customer', 'site', 'system', 'component'));
  }

This gives me a PDO Exception... Base table or view not found: 1146 Table 'ssiweb.systems_components' doesn't exist

Here are my relationships...

from Customer.php

    public function sites() {
    return $this->hasMany('App\Site');
  }

from Site.php

  public function customers() {
    return $this->belongsTo('App\Customer');
  }

  public function systems() {
    return $this->hasMany('App\System');
}

from System.php

  public function sites() {
    return $this->belongsTo('App\Site');
  }

  public function components() {
    return $this->belongsToMany('App\Component', 'systems_components', 'system_id', 'component_id');
  }

from Component.php

  public function systems() {
    return $this->belongsToMany('App\System', 'systems_components', 'component_id', 'system_id');
  }

28th September, 2016

nscherneck left a reply on NotFoundHttpException In RouteCollection.php Line 161 • 6 months ago

Slash did the trick! Thanks for the help!

nscherneck started a new conversation NotFoundHttpException In RouteCollection.php Line 161 • 6 months ago

Hey all, I'm learning Laravel and am working with Laravel 5.3 on the current version of Homestead. I've added a form to add a "site" to my database. I'm aware there are more efficient ways to code this, but this should work and I'm unsure why I'm getting the above exception.

From my routes file (web.php)

Route::post('customer/{customer}/sites', [email protected]');

From my CustomersController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use DB;
use App\Http\Requests;
use App\Site;
use App\Customer;

class CustomersController extends Controller
{

    public function index() {
      $customers = Customer::orderBy('name')->get();
      return view('customers.index', compact('customers'));
    }

    public function show(Customer $customer) {
      // $customer = Customer::find($id);
      return view('customers.show', compact('customer'));
    }

    public function addSite(Request $request, Customer $customer) {

      return $customer;

      $site = new Site;
      $site->customer_id = $customer->id;
      $site->name = $request->name;
      $site->address1 = $request->address1;
      $site->address2 = $request->address2;
      $site->city = $request->city;
      $site->state = $request->state;
      $site->zip = $request->zip;
      $site->lat = $request->lat;
      $site->lon = $request->lon;
      $site->phone = $request->phone;
      $site->fax = $request->fax;
      $site->notes = $request->notes;

      $customer->sites()->save($site);

      return back();

    }

}

and the form in my view file (show)...

    <form action="customer/{{ $customer->id }}/sites" method="POST">
      {{ csrf_field() }}
      <div class="form-group">
        Site Name: <input type="text" name="name" value="" class="form-control"><br>
        Address: <input type="text" name="address1" value="" class="form-control"><br>
        Address: <input type="text" name="address2" value="" class="form-control"><br>
        City: <input type="text" name="city" value="" class="form-control"><br>
        State (i.e. OR): <input type="text" name="state" value="" class="form-control"><br>
        Zip Code: <input type="text" name="zip" value="zip" class="form-control"><br>
        Latitude: <input type="text" name="lat" value="" class="form-control"><br>
        Longitude: <input type="text" name="lon" value="" class="form-control"><br>
        Phone: <input type="text" name="phone" value="" class="form-control"><br>
        Fax: <input type="text" name="fax" value="" class="form-control"><br>
        Notes: <textarea name="notes" class="form-control">Site notes</textarea><br>
        <button type="submit" class="btn btn-primary">Add Site</button>
      </div>
    </form>
  </div>
Edit Your Profile
Update

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