WallyJ

Experience

3,230

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 11 Lessons Completed
  • 1 Favorite

24th May, 2018

WallyJ left a reply on Passport Guzzle Response Directs To Login Page • 1 month ago

Sorry to tag along, but I have the same issue. If I go to a URL (For a site I am logged into) directly in Chrome, the page shows fine.

But if I use Guzzle and the command:

$client = new \GuzzleHttp\Client();
        $res = $client->request('GET', $url);
        echo $res->getbody();

I receive the login page, as if I'm not logged in, and also in my case, there are no images on the page.

I'm thinking there is a simple fix for this, but I am new to using Guzzle and DOM functions.

20th May, 2018

WallyJ left a reply on Count Of Records From DB::select • 2 months ago

Thanks Cronix. As you know, sometimes my brain gets stuck wanting to do things one way. This time, I tried the PHP count method before, directly in the SQL query, but couldn't get it to work. Then I realized that I need to be doing things the Laravel way as much as possible (which I am often doing), but couldn't get away from the DB:select to simply declare a variable with a simple count.

This was my solution:

$countofopps = count($homeopps);

and at the end of my return statement, I added:

->with('countofopps', $countofopps);

And simply put this in my view:

{{$countofopps}

Thanks again.

WallyJ left a reply on Count Of Records From DB::select • 2 months ago

I added this line to my controller just before the "return view" line and I received this error:

"Call to a member function count() on array"

WallyJ started a new conversation Count Of Records From DB::select • 2 months ago

I have the following query in a controller:

$opps = DB::select('SELECT mainfield, field2, etc. FROM table LEFT JOIN ( SELECT otherfield FROM othertable Group By fieldname');
return view ('home')
->with ('opps', $opps)

The query works fine. I just want to get a count of the records returned so that I can put this count at the top of the view.

In the view I currently return the results in a:

@foreach($opps as $opp)

But I want to put the count above the foreach.

I tried:

{{$opp->mainfield->count()}}

But of course it errors out saying it doesn't recognize that variable because it hasn't been called yet.

Just want to put a count of records returned at the top of the view. Thanks.

19th May, 2018

WallyJ left a reply on 1366 Incorrect String Value, On CSV Import To MySQL DB • 2 months ago

Update 3 - Solution:

I used the mb_convert_encoding function to specify the collation for the fields that were causing errors. (Ended up being 2 fields)

In the controller, I added a line above the field that was problematic, to force UTF8:

$remarks=mb_convert_encoding($remarks, "UTF-8");
$newdata->remarks=$remarks;

WallyJ left a reply on 1366 Incorrect String Value, On CSV Import To MySQL DB • 2 months ago

Update 2: So, it turns out that the CSV file I have is not encoded UTF-8.

I opened the file in Notepad, and saved as UTF-8 and it imported like a champ.

I may look at those PHP functions to force that field to be encoded as UTF so I don't have to convert the CSV file every time.

WallyJ left a reply on 1366 Incorrect String Value, On CSV Import To MySQL DB • 2 months ago

Update: I took the text directly from the CSV file and inserted it directly into the DB using PHPMyAdmin.

No error, so the DB is able to hold the accented "e".

But I can't figure out what is causing the error.

Any other suggestions? Thanks!

WallyJ left a reply on 1366 Incorrect String Value, On CSV Import To MySQL DB • 2 months ago

@rsvb - Thanks for the suggestion, but I believe this is a collation setting issue, not something that needs an additional PHP function to do something to the string.

I understand if I could use the function to test the string possibly. I was just hoping that someone would have experienced this particular error before and knows where the issue is. Still hoping for a solution. Thanks.

18th May, 2018

WallyJ left a reply on 1366 Incorrect String Value, On CSV Import To MySQL DB • 2 months ago

The error specifically denotes the word with the accented "e", "Incorrect string value: '\xE9cor a...' for column 'Remarks'" and then shows the data with the word showing the accented "e" replaced with that black diamond with the question mark - d�cor

WallyJ left a reply on 1366 Incorrect String Value, On CSV Import To MySQL DB • 2 months ago

varchar(800) utf8_unicode_ci

The query returns this field type and collation

WallyJ left a reply on 1366 Incorrect String Value, On CSV Import To MySQL DB • 2 months ago

When I upload the CSV, which calls the controller, that's where I receive the error. The value never gets into the column in the DB.

I have tried changing the collation, but it didn't keep the error from happening.

What else can I do?

17th May, 2018

WallyJ started a new conversation 1366 Incorrect String Value, On CSV Import To MySQL DB • 2 months ago

I receive this error on a field that contains a word with an accented "e" character. I have Googled to find that the issue seems to be in the collation of the data and the tables. I have changed the collation in the db to utf8_unicode_ci as well as utf8_general_ci, and changed my config/database.php to reflect utf8_general_ci, to no effect. I've also read that using "SET NAMES" to UTF8 as part of your query can help, but I'm using a simple $newdata->save() at the end of my field data, so I'm not sure how to do that. Ideas? Thanks.

21st April, 2018

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

@Sergiu17 , Follow up. Though this line works beautifully and cleanly, I just noticed that I lost my "orderBy('created_at', 'desc'), and can't figure out how to put it back in to order the contactnotes.

$contacts = Contact::with(['contactnotes'->orderBy('created_at', 'desc'), 'deals.tasks'])->find($id);

WallyJ left a reply on How To Properly Add A Package To My Project • 3 months ago

I added the links to the js and the css from the cdnjs and it immediately started working. Thanks.

Unfortunately now I can't get the parameters to work correctly. Will work on that next.

WallyJ left a reply on How To Properly Add A Package To My Project • 3 months ago

I appreciate your explanation, and will look into using mix and npm.

So should the developer give a better explanation in the instructions, or is it my job as the developer to understand the ecosystem enough to translate the instructions into what I really ought to do? #trulytryingtolearn

WallyJ left a reply on How To Properly Add A Package To My Project • 3 months ago

Appreciate the insight, but in an effort to understand, why would this package be available via composer if composer doesn't really "install" it in a way that it will actually work after installation?

20th April, 2018

WallyJ started a new conversation How To Properly Add A Package To My Project • 3 months ago

I found a cool date picker, and according to the instructions on its page at Packagist, I ran the following command in my terminal:

composer require eternicode/bootstrap-datepicker

I feel like I'm supposed to add something else somewhere, but I don't see it in the instructions on this page, or at the docs linked from that page.

https://packagist.org/packages/eternicode/bootstrap-datepicker

Maybe I'm supposed to know.

19th April, 2018

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

Wow... mystery solved...

I had a lingering old field in my contacts table called "contactnotes" when I originally created the table, before I created an entirely different table for "contactnotes". I changed the name of the field, and boom, everything worked as expected.

DD in the controller, then DD in the view, then the view itself.

Thanks guys! #newbmistakes #greatcommunity #thankful

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

Again, the contact notes were working before I tried to add the tasks. It was at that point I wasn't writing the code correctly to also request the tasks. That's when I was encouraged to use this:

$contacts = Contact::with(['contactnotes', 'deals.tasks')->find($id);

Which was your cleaned up version. :)

So I know the relationships were working and the contactnotes were being found.

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

Thanks for the encouragement.

Still quotation marks.

It's something simple. Just can't figure it.

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

Interesting, and depressing...

I get the quotation marks again. Even when I change the case of the "Contactnotes"

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

It's the strangest thing... If I perform: `` dd($contacts);


I get back:

Contact {#585 ▼ #connection: "mysql" #table: null #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: false #attributes: array:26 [▶] #original: array:26 [▶] #changes: [] #casts: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: array:2 [▼ "contactnotes" => Collection {#640 ▶} "deals" => Collection {#744 ▶} ] #touches: [] +timestamps: true #hidden: [] #visible: [] #fillable: [] #guarded: array:1 [▶] }


And I can click through the relations and see the contactnotes collection and the deals collection.

If I perform:

dd($contacts->deals)

I get back:

Collection {#744 ▼ #items: array:2 [▼ 0 => Deal {#682 ▶} 1 => Deal {#683 ▶} ] }


With only the deals collection, as expected.

However, if I perform:

dd($contacts->contactnotes);


I get back this:

""


That's it... a set of quotation marks... I am baffled.

18th April, 2018

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

Returns the Contact Info for the contact.

Also includes a "relations" array with 3 contactnotes and their values.

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

@Sergiu17, You gave me an idea, so I went back to my controller and did a:

dd($contacts->contactnotes);

and it returned the quotation marks. So the view is not the problem.

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

Thanks @JoaoPedroAS51 . That looks cleaner. And I changed the Model as you suggested. No change.

The dump of the $contactnotes still gives ""

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

I think there's something wrong with this line:

$contacts = Contact::with('contactnotes')->with('deals.tasks')->find($id);

Because it works for deals, but not for contactnotes.

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

Contact Model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Contact extends Model
{
    public function User()
    {
        return $this->belongsTo(User::class);
    }
    
    public function Contactnotes()
    {
        return $this->hasMany(Contactnote::class);
    }
    
    public function Deals()
    {
        return $this->hasMany(Deal::class);
    }

    public function addContactnote($contactnotetext)
    {
            $this->contactnotes()->create(compact('contactnotetext'));
    }

}

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

There are definitely notes associated with that contact. That part was working before I added the tasks.

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

Yes. Same array.

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

Yes. It returns an array of 2 items (deals), and under item 0, the #relations has an array of 1 task, and under its attributes it shows the fields. So the data is connected.

There's something in the naming between the controller and the view that is off. I just can't figure out what.

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

That makes sense.

However, when I try to use this code in my view, I receive a "Invalid argument supplied for foreach()"

@foreach($contactnotes as $contactnote)
                                <li class="list-group-item">
                                    <p>{{$contactnote->created_at->diffForHumans()}} - {{$contactnote->contactnotetext}}</p>
                                </li>
                                @endforeach

I did a {{dd($contactnotes)}} in the view to test and it only shows quotation marks - ""

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

All of the information shows, so the relationships are working, but if I remove the dd($contacts);, I receive the error "Undefined variable: contactnotes" on this line:

->with('contactnotes', $contactnotes)

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

Same error.

public function show($id)
    {
        $contacts = Contact::with('contactnotes')->with('deals.tasks')->find($id);
        $contactnotes = Contactnote::orderBy('created_at', 'desc')->where('contact_id', '=', $contacts->id)->get();
        $deals = Deal::where('contact_id', '=', $contacts->id)->get();
        $tasks = Task::where('deal_id', '=', $deals->id)-get();
        // Check for correct user
        if(auth()->user()->id !== $contacts->user_id){
            return redirect('/contacts')->with('error', 'That Is Not Your Contact');
        }
        return view('contacts.show')
        ->with('contact', $contacts)
        ->with('contactnotes', $contactnotes)
        ->with('deals', $deals)
        ->with('tasks', $tasks);
    }

WallyJ left a reply on Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

But wouldn't that get rid of the use of the ID it's pulling from the URL?

WallyJ started a new conversation Referencing A Variable Within A Controller Is Not Recognized • 3 months ago

If I have relationships set up for the following: Contacts have ContactNotes Contacts have Deals Deals have Tasks

public function show($id)
    {
        $contacts = Contact::find($id);
        $contactnotes = Contactnote::orderBy('created_at', 'desc')->where('contact_id', '=', $contacts->id)->get();
        $deals = Deal::where('contact_id', '=', $contacts->id)->get();
        $tasks = Task::where('deal_id', '=', $deals->id);
        // Check for correct user
        if(auth()->user()->id !== $contacts->user_id){
            return redirect('/contacts')->with('error', 'That Is Not Your Contact');
        }
        return view('contacts.show')
        ->with('contact', $contacts)
        ->with('contactnotes', $contactnotes)
        ->with('deals', $deals)
        ->with('tasks', $tasks);
    }

I am getting an error "Property [id] does not exist on this collection instance." because I am obviously doing something wrong in the "$tasks=" line.

I am making things a little difficult here because the contact view (show) pulls in the contact info, the contact notes, and then includes deals.index, which brings in the task info.

I tried to simply reference $tasks in the DealsController, but I'm thinking that since the Contacts view is the primary view being called, all variables have to be defined within that controller function. Am I right about that?

Or can you include a file, and it's part of it's own controller will be called?

16th April, 2018

WallyJ started a new conversation Big Dashboard Page Or Lots Of Separate Includes • 3 months ago

When you create a dashboard style view that is pulling in quite a few different data sets, do you:

A. Put everything you need in dashboard.blade.php...

or

B. Create each section of the dashboard in its own separate blade files, possibly in folders so they all end up as index.blade.php, that you simply include on dashboard.blade.php

And why?

15th April, 2018

WallyJ left a reply on Query Records Within A Foreach Loop In A View • 3 months ago

So, it seems if I set up the one connective relationship, the eager loading will work, based on the premise that the order table has a customer_id field in it, that is a primary key.

New analogy...

I have 2 tables. each set of data is out of my control. I just receive them and update the database accordingly

Table 1: Car Sales for last year Table 2: Current Cars for Sale

Table 1 Fields: Date of Sale - (03/01/2017, 10/13/2017, etc.) Car Model - (S100, S200, S300, etc.) Price - ($10,000, $20,000, etc.) Description - (Nice Car, Super Deal, etc.) Salesperson - (Jim, Suzie, Fred, etc.)

Table 2 Fields: Car Model - (S100, S200, S300, etc.) Price - ($10,000, $20,000, etc.) Description - (Nice Car, Super Deal, etc.)

So the tables are very similar, with no real ID's for the car Models, no primary keys, and no table called "Car Models"

I run a query that lists cars Currently for sale, in a foreach, based on certain criteria, listing car model and price, etc.

I want to hover over the car model and see the past sales from last year, queried from the other table.

Though I understand eager loading, based on this setup, I don't see how Eloquent can connect the two fields via relationship of the "Models" fields since there is no ID, and no primary field on either table (Multiple of the same model sold last year and multiple of the same model currently for sale).

I know it isn't preferred, but this is why I first wanted to run a query in the foreach, with fairly small amount of records, let's say 1,400 in current cars for sale, and 5,000 in the table of sales from last year, I'm not as concerned about the multiple queries, but again, I am trying to do things the "Laravel Way" if at all possible. :)

#tryingtobeagoodstudent

WallyJ left a reply on Query Records Within A Foreach Loop In A View • 3 months ago

Ahh.... gotcha.. I'll give it a try. Thanks!

WallyJ left a reply on Query Records Within A Foreach Loop In A View • 3 months ago

Ok, but don't I have to set up the relationship in the model? I've just never set up a many to many relationship in a model before.

WallyJ left a reply on Query Records Within A Foreach Loop In A View • 3 months ago

Makes sense.

However, what if it wasn't customers and orders, and it was 2 tables that had a many-to-many relationship based on one field.

Or let's say it's one step further with Customers and Orders... The first query brings back customers and orders, and I use the relationship to show the orders.

But now I want the tooltip to be for each Product in the order, and I want to hover over the Product to see a list of other Orders that contain that product.

But realistically it's 2 tables with the many-to-many relationship based on a single field, so the relationship doesn't seem to help, unless that would work in this case as well.

WallyJ started a new conversation Query Records Within A Foreach Loop In A View • 3 months ago

So, pardon me not having complete code yet because this is somewhat hypothetical.

So, if I have a query in my Controller that looks up a list of Customers from the Customers table, with various fields like name, email, etc. and it shows in a view with something like:

@foreach ($customers as $customer)
<div>$customer->name</div>
<div>$customer->email</div>
<div>$customer->phone</div>
<div>$customer->countoforders</div> (from the Orders Table)
@endforeach 

Then, I want to create a Bootstrap tooltip for "countoforders" so that when I hover over the number it pops up a tooltip with a list of the orders for that customer.

I'm not asking for help with coding the tooltip.

I'm asking, what's the best way to query the orders table based on the current record inside the foreach.

I feel like if I do it within the controller, it won't know how to only give the orders for each customer, but I'm sure I'm missing something.

Or is there a way to return a subset of records for the orders and simply call them inside the foreach?

13th April, 2018

WallyJ left a reply on Composer Update JSON Error • 3 months ago

I'm not sure what caused this issue, but I solved it by:

rm -rf vendor/

then

composer install

per the tip found at: https://github.com/composer/composer/issues/3786

WallyJ started a new conversation Composer Update JSON Error • 3 months ago

At the end of my new Laravel project install, I received this error, and if I try to run composer update or composer dump-autoload, I receive the same error. Anyone seen this or know how to fix it?

[Composer\Repository\InvalidRepositoryException]
  Invalid repository data in /home/vagrant/Code/newapp/vendor/composer/installed.json, packages could not be loade
  d: [Seld\JsonLint\ParsingException] "/home/vagrant/Code/newapp/vendor/composer/installed.json" does not contain
  valid JSON
  Parse error on line 1:

  ^
  Expected one of: 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

WallyJ left a reply on Converting MS Access Queries To Laravel Query Builder • 3 months ago

@jlrdw, that's a good idea, to use Access that way. Though, I just tried it with my full query and received an error that doesn't tell me much:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near... with my SQL code...

WallyJ left a reply on Coverting MS Access Queries To Laravel Query Builder • 3 months ago

I appreciate you responding, but I am trying to use Eloquent whenever it is at all possible. Thanks.

WallyJ started a new conversation Coverting MS Access Queries To Laravel Query Builder • 3 months ago

I am converting some queries that contain primarily aggregate fields, all in one query, in a MS Access db.

How would I convert so many aggregate fields into one lookup? Or would I need to break it up and then combine them?

For instance, some of the query fields look like this:

Field: Product Name Table: Products Total: Group By

Field: Product Name Table: Products Total: Count Criteria: >2

Field: Price Table: Products Total: Avg Sort: Descending

Field: Price Table: Products Total: StDev

Which lists all products with their counts of sales and their avg and standard deviation of prices.

How would I do this in Eloquent?

12th April, 2018

WallyJ left a reply on Edit Form - Attempt To Assign Property 'dealtype' Of Non-object • 3 months ago

So... I think this is working now. I added an id to my modal form:

{!! Form::open(['id' => 'editmodalform', 'route' => ['deals.update', '']]) !!}

So the action is technically blank until the script fills it in.

Then I added this line to my script:

$("#editmodalform").attr('action', '/deals/' + dealid)

It replaces the action once the html is created after opening the modal, so it still goes to the controller and works. Still testing to make sure, but I think I've got it working now.

WallyJ left a reply on Edit Form - Attempt To Assign Property 'dealtype' Of Non-object • 3 months ago

Yep. Same thing.

The foreach on deals.index is what changes it from $deals to $deal:

@foreach($deals as $deal)
                        <div class="well">
                            <h3><a href="/deals/{{$deal->id}}">{{$deal->dealtype}}</a></h3>
                            <h4>Price: {{moneyformat($deal->price)}}</h4>
                            <!-- Calculation for Commission dollars from Price and CommissionPercentage -->
                            <h4> Comm: {{moneyformat($deal->price * $deal->commissionpercentage * .01)}} - ({{$deal->commissionpercentage}}%)</h4>
                            <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-contactid="{{$contact->id}}" data-dealid="{{$deal->id}}" data-dealtype="{{$deal->dealtype}}" data-price="{{$deal->price}}" data-commissionpercentage="{{$deal->commissionpercentage}}" data-target="#editDealModal">Edit</button>
                        </div>
@endforeach 

But once I click an Edit button, the modal no longer sees the $deal->anything. It gets its data from the data-stuff within the button. But that modal form needs to send the deal id back to the controller. But I don't know how to set the php variable within the form syntax to be equal to the javascript variable sent from the button. :)

WallyJ left a reply on Edit Form - Attempt To Assign Property 'dealtype' Of Non-object • 3 months ago

I'm using jquery to send the data to the modal form fields. The button code:

<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-contactid="{{$contact->id}}" data-dealid="{{$deal->id}}" data-dealtype="{{$deal->dealtype}}" data-price="{{$deal->price}}" data-commissionpercentage="{{$deal->commissionpercentage}}" data-target="#editDealModal">Edit</button>

The script:

<script>
    $(function(){
        $('#editDealModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget) // Button that triggered the modal
            //var recipient = button.data('whatever') // Extract info from data-* attributes
            var dealid = button.data('dealid')
            var dealtype = button.data('dealtype')
            var price = button.data('price')
            var commissionpercentage = button.data('commissionpercentage')
            var contactid = button.data('contactid')
            // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
            // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
            var modal = $(this)
            modal.find('input[name="dealid"]').val(dealid)
            modal.find('input[name="contactid"]').val(contactid)
            modal.find('select[id="dealtype"]').val(dealtype)
            modal.find('input[id="price"]').val(price)
            modal.find('input[id="commissionpercentage"]').val(commissionpercentage)
            $("#jqValue").html(dealid)
        })
    });
</script>

So that's probably where $deal gets lost. As you can see, I am currently sending the deal id and the contact id through the script, but I really only need the contact id... I think. :) Though that leaves the $deal->id missing.

WallyJ left a reply on Edit Form - Attempt To Assign Property 'dealtype' Of Non-object • 3 months ago

The edit view is technically a modal view whose code is in the "index.blade.php" of deals, which is included

@include('deals.index');

on the Contacts view.

So editing through the modal never goes to the /deals/edit/$id url.

Is that what you mean?

Otherwise, I'm not sure how to pass it to the modal.

Edit Your Profile
Update

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