WallyJ

WallyJ

Member Since 2 Years Ago

Experience Points
7,170
Total
Experience

2,830 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
12
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 2
7,170 XP
Jan
19
21 hours ago
Activity icon

Started a new Conversation Livewire And Bootstrap Datepicker

I like the Boostrap datepicker and am trying to use it, and it works fine at choosing and showing the date in the field. But I can't get it into the db.

I have seen this discussion: https://forum.laravel-livewire.com/t/using-livewire-with-select2-selectpicker/18 And these docs: https://laravel-livewire.com/docs/third-party-libraries/

But I can't get my code to allow the correct property to receive the correct value in my Livewire component:

Component View:

<div class="col-md-6">
    <div class="row">
        <div class="col-md-9"><h3><a href="/deals/{{$this->deal->id}}">{{$this->deal->dealtype}}</a></h3></div>
        <h1>DealID: {{ $this->deal['id'] }}</h1>
        <div class="col-md-3">
            <a href="link_to_action('[email protected]', $title, $parameters = array(), $attributes = array());">Delete</a>
        </div>
    </div>
    <div class="tasks">
        <h5>Tasks</h5>
        <div class="card-block">
        <div class="form-row">
            <div class="input-group form-group col-md-9">
                <input type="text" name="tasktext" class="form-control" placeholder="New Task" wire:model="tasktext">
            </div>
            <div class="form-group col-md-3" id="datepickerfield">
                <div class="input-group date taskduedatepicker">
                <input type="text" name="taskduedate" class="form-control datepicker" id="taskduedate" placeholder="Due Date" data-provide="datepicker" data-date-autoclose="true" data-date-today-highlight="true" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="form-row">
            <div class="form-group col-md-12">
                <button class="btn btn-primary" wire:click="addTask" type="submit">Add</button>
            </div>
        </div>
        </div>
        <div>
            <ul class="list-group">
                @foreach($this->deal['tasks'] as $task)
                <li class="list-group-item d-flex justify-content-between align-items-center">
                    <div>
                        <input type="checkbox" class="mr-4">
                        {{Carbon\Carbon::parse($task['taskduedate'])->format('m/d/Y')}} - {{$task['tasktext']}}
                    </div>
                    <div>
                        <form class=".mb-0" action="#" method="POST">
                            @csrf
                            <button class="btn btn-sm btn-danger">&times;</button>
                        </form>
                    </div>
                </li>
                @endforeach
            </ul>
        </div>
    </div>
</div>
<script>
('#datepicker').datepicker({
   dateFormat: 'dd-mm-yy',
   onSelect: function(taskduedate) {
       @this.set('taskduedate', taskduedate);
   }
});
</script>

Controller:

public function addTask()
    {
        $this->deal->tasks()->create([
            'tasktext' => $this->tasktext,
            'taskduedate' => $this->taskduedate,
        ]);
    }

It may be that my Javascript is wrong. it probably is, but I'm a JS noob and have no idea what could be wrong.

My understanding is that this JS is supposed to declare the value of the "taskduedate" to Livewire so it receives it in the "$this->taskduedate" value in the controller.

Jan
16
3 days ago
Activity icon

Replied to Blade Syntax To Query All Of 3rd Level Eloquent Relationship

I was able to get the $tasks to list the tasks by date.

But when I try to reference the other relationships I get errors using this line (The task text will show fine but I receive errors when I try to add the related fields:

 <li>{{ $task->tasktext }} - {{ $deal->name }} - {{$contact->fullname}} </li>

UPDATE: I just realized that I have to write the relationship syntax in reverse, and use:

{{ $task->deal->contact->contact1firstname }}

in my blade template.

Is that how you would do it?

Activity icon

Replied to Blade Syntax To Query All Of 3rd Level Eloquent Relationship

Sorry. I wrote my "Makes sense" response looking at the thread before I saw your explanation. It may have looked like I responded without reading your reply. And technically I did. :)

Again, sorry for any confusion. I will work through that. Thanks so much for your help!

Activity icon

Replied to Blade Syntax To Query All Of 3rd Level Eloquent Relationship

Makes sense.

Though, if I run the query in the controller, how do I reference a relationship in reverse?

If I use Task::... How do I reference backwards, in the "where" statement, to limit the tasks to the currently logged-in user? There is no user_id field in the task table. Do I still use with(contacts.deals)? Since I'm starting with the deepest connected relationship?

I've never built queries starting at the far end of the relationship.

Activity icon

Replied to Blade Syntax To Query All Of 3rd Level Eloquent Relationship

That makes sense, but then how would I reference a property in reverse? For instance, with your suggestion I end up with a list of tasks like:

Task1

Task2

Task3

But what if I then wanted to put the type of deal next to each task (Type is a field in the Deal table/object) so it would look something like:

Task1 - Contract

Task2 - Purchase Order

Task3 - Bulk Sale

And if I wanted to go one more rung up the ladder backwards, how would I do that, so it could also show the contact:

Task1 - Contract - Mark Jones

Task2 - Purchase Order - Ben Burns

Task3 - Bulk Sale - Mike McDonald

And to complicate matters, what if I decide to list the tasks by their due date? Using a @foreach will list each task by their due date in order for each deal, within each contact, not overall.

Sounds like I might need to query all of the tasks within the controller with its own variable to order them as as group correctly. I would also still need to reference the reverse relationships.

Activity icon

Started a new Conversation Blade Syntax To Query All Of 3rd Level Eloquent Relationship

If I have set up all of my relationships correctly for Users->Contacts->Deals->Tasks, and I eager load all of a user's contacts into a view with their deals and tasks:

    public function index()
    {
        //Look up contacts associated with the logged in user
        $user_id = auth()->user()->id;
        $contacts = Contact::with(['contactnotes' => function($query) {
            $query->orderBy('updated_at', 'desc');
            }])
            ->with('deals.tasks')
            ->orderBy('contactlastseen', 'desc')
            ->take(10)
            ->where('user_id', '=', $user_id)->get();
        return view('dashboard')
            ->with('contacts', $contacts)
            ->with('tasks', $tasks);
    }

How do I query a list of all tasks within a blade view? Meaning all tasks from all deals for all contacts. Or would I have to define a separate variable for all tasks in the controller? All of them are in the collection I loaded so I should be able to have them already, right?

If I try:

<ul>
     @foreach($contacts->deals->tasks as $task)
           <li>{{ $task->tasktext }}</li>
     @endforeach
</ul>

I receive the error: Property [deals] does not exist on this collection instance.

Activity icon

Replied to Data Not Passing In Livewire Component

Except, I'm not creating a deal. I'm creating a task.

So shouldn't it be:

public function addTask()
    {
        $this->task->create([
            'tasktext' => $this->tasktext,
        ]);
    }

And if so, where will that function retrieve the dealid that goes with the task record?

Jan
15
4 days ago
Activity icon

Replied to Data Not Passing In Livewire Component

That sounds awesome!

I submit the form using the following button in the view (see code above):

<button class="btn btn-primary" wire:click="addTask" type="submit">Add</button>

My understanding is that the wire:click calls the "addTask" function within the Livewire controller.

Activity icon

Replied to Data Not Passing In Livewire Component

Sorry. I didn't understand. The deals component is nested in the contacts component.

The contacts component calls the deals component using the following in its view:

@foreach($this->contacts->deals as $deal)
    @livewire('deals', $deal, key($deal['id']))
@endforeach

Each contact has multiple deals, so I show them on the contact view. I'm hoping that Livewire can handle multiple forms in a single view and still function properly.

I used the above code following the "Keyed Components" section of the docs found on this page: https://laravel-livewire.com/docs/nesting-components/

Activity icon

Replied to Data Not Passing In Livewire Component

The view mentioned above is a Livewire component. So I think the answer is yes.

Activity icon

Replied to Data Not Passing In Livewire Component

It used to be that the data had to be in an array to follow the rule @snapey mentioned, but now Livewire works with collections, Eloquent, etc.

I can try the syntax suggestions you made, but it still doesn't explain why I can dd($tasktext) just above the Task::create and get the data, but it won't pass to the actual create function.

Also, how in the world is the HTML showing the value of the deal_id, but it doesn't show in the actual field to pass to the controller?

Isn't this basic stuff? Use a hidden field to hold an id of some kind to pass back to the controller for the insert query?

Jan
14
5 days ago
Activity icon

Replied to Data Not Passing In Livewire Component

Those actually work fine to display the values on the page.

I have multiple issues. Just trying to deal with them one at a time.

I set the value for the dealid field as you can see in my code, though the value shows up in the HTML, I can't see it on the page. So I am testing by manually typing in the value. Not sure why it doesn't show but I'll deal with that later.

If I type in the values, I can dd($tasktext) and I see the text, and I can dd($deal_id) and I see the id I typed in.

But if I click the "Add Task" button, I receive the error. It is sending over the "tasktext" but not the "dealid".

Not sure why.

And unfortunately, Livewire requires a lot of "$this->" everywhere.

Also, as a side note, originally I had my data in an array, which is why the variable data is coded like that. I am now switching it all back to standard Laravel Blade coding, but it calls the data currently fine... seemingly.

Activity icon

Started a new Conversation Data Not Passing In Livewire Component

I receive this error using the following view and controller:

Illuminate\Database\QueryException SQLSTATE[HY000]: General error: 1364 Field 'deal_id' doesn't have a default value (SQL: insert into tasks (tasktext, updated_at, created_at) values (Upload, 2020-01-14 21:27:15, 2020-01-14 21:27:15))

Controller:

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Task;

class Deals extends Component
{
    public $deal;
    public $dealid;
    public $tasktext;

    public function mount($deal)
    {
        $this->deal = $deal;
    }

    public function render()
    {
        return view('livewire.deals');
    }

    public function addTask()
    {
        Task::create([
            'deal_id' => $this->dealid,
            'tasktext' => $this->tasktext,
            // 'taskduedate' => $this->taskduedate,
        ]);
    }
}

View:

<div class="tasks">
        <h5>Tasks</h5>
        <div class="card-block">
        <div class="form-row">
            <div class="input-group form-group col-md-9">
                <input type="text" name="tasktext" class="form-control" placeholder="New Task" wire:model="tasktext">
            </div>
            <div class="input-group form-group">
                <input type="text" name="dealid" class="form-control" value="{{ $this->deal['id'] }}" wire:model="dealid">
            </div>
        </div>
        <div class="form-row">
            <div class="form-group col-md-12">
                <button class="btn btn-primary" wire:click="addTask" type="submit">Add</button>
            </div>
        </div>
        </div>
        <div>
            <ul class="list-group">
                @foreach($this->deal['tasks'] as $task)
                <li class="list-group-item d-flex justify-content-between align-items-center">
                    <div>
                        <input type="checkbox" class="mr-4">
                        {{Carbon\Carbon::parse($task['taskduedate'])->format('m/d/Y')}} - {{$task['tasktext']}}
                    </div>
                    <div>
                        <form class=".mb-0" action="#" method="POST">
                            @csrf
                            <button class="btn btn-sm btn-danger">&times;</button>
                        </form>
                    </div>
                </li>
                @endforeach
            </ul>
        </div>
    </div>

I believe that I have coded the "dealid" the same as the "tasktext", but it isn't seen as part of the "Task::create" function.

What am I missing?

Activity icon

Replied to Passing Hidden Field Value Back To Livewire Component Is Null

I marked this as answered, but I was incorrect. I had the old variable in the controller, and the value showed up.

As soon as I added the correct variable:

public $deal_id;

The value no longer shows in the field.

Though, If I "inspect" the HTML in Chrome, I see this line:

<input type="text" value="11" wire:model="deal_id">

So it shows the value in the input field. Why can't I see it on the page and why can't it be seen by my Livewire component?

Jan
10
1 week ago
Activity icon

Awarded Best Reply on Passing Hidden Field Value Back To Livewire Component Is Null

I decided to go with nesting another component into the existing one, passing the data through to the nested component, as suggested here for "Keyed Components": https://laravel-livewire.com/docs/nesting-components/

And that worked. Thanks.

Activity icon

Replied to Passing Hidden Field Value Back To Livewire Component Is Null

I decided to go with nesting another component into the existing one, passing the data through to the nested component, as suggested here for "Keyed Components": https://laravel-livewire.com/docs/nesting-components/

And that worked. Thanks.

Jan
09
1 week ago
Activity icon

Replied to Passing Hidden Field Value Back To Livewire Component Is Null

Yes. It is included in the tag. I can get the dd($tasktext) to give me a value of the text I enter, but not the pre-valued dealId.

Activity icon

Replied to Passing Hidden Field Value Back To Livewire Component Is Null

Yes. That's what I meant when I said I edited the public variable to match. I guess I should have said public property. :)

Activity icon

Replied to Passing Hidden Field Value Back To Livewire Component Is Null

Changed

wire:model="deal_id"

to

wire:model="dealId"

No change. same result Value does not show in text input field. (Also edited the public variable to match, again, no change)

Activity icon

Replied to Passing Hidden Field Value Back To Livewire Component Is Null

No. I see how that could be confusing. I have a hidden field with wire:model set to "dealid", and a regular text field a few lines above that with the wire:model set to "deal_id", so in testing I could call either, and use the standard text input to actually see the value I am expecting in the hidden field. Once it worked in the standard text input, I could simply switch it to hidden.

Activity icon

Started a new Conversation Passing Hidden Field Value Back To Livewire Component Is Null

From my old PHP form days, I have a form within a @foreach loop that has a hidden field to capture the deal id, so I can send that on to be used by the controller.

However, if I add

wire:model="deal_id"

to the input field, the deal id no longer shows in the field and the dd($this->deal_id) shows null. I tested this with a text field instead of a hidden field so I could see the value.

How do I get the deal is from each @foreach loop sent back to the component? Because of the @foreach loop I have multiple forms on the page, but the "Add Task" button needs to add the task via the correct deal id.

For reference:

Foreach section in my component view:

@foreach($this->contacts['deals'] as $deal)
<div class="col-md-6">
        <div class="row">
            <div class="col-md-9"><h3><a href="/deals/{{$deal['id']}}">{{$deal['dealtype']}}</a></h3></div>
            <h1>DealID: {{ $deal['id'] }}</h1>
            <div class="col-md-3">
                <a href="link_to_action('[email protected]', $title, $parameters = array(), $attributes = array());">Delete</a>
            </div>
        </div>
        <div class="tasks">
            <h5>Tasks</h5>
            <div class="card-block">
            <div class="form-row">
                <div class="input-group form-group col-md-9">
                    <input type="text" name="tasktext" class="form-control" id="tasktext" placeholder="New Task" wire:model="tasktext">
                </div>
                <div>
                    <input type="text" value="{{ $deal['id'] }}" wire:model="deal_id">
                </div>
                <div class="form-group col-md-3" id="datepickerfield">
                    <div class="input-group date taskduedatepicker">
                    <input type="text" name="taskduedate" class="form-control" id="taskduedate" placeholder="Due Date" data-provide="datepicker" data-date-autoclose="true" data-date-today-highlight="true" autocomplete="off">
                    </div>
                </div>
            </div>
            <div class="form-row">
                <div class="form-group col-md-12">
                    <input type="hidden" name="deal_id" id="deal_id" value="{{ $deal['id'] }}" wire:model="dealid">
                    <button class="btn btn-primary" wire:click="addTask" type="submit">Add</button>
                </div>
            </div>
            </div>
            <div>
                <ul class="list-group">
                    @foreach($deal['tasks'] as $task)
                    <li class="list-group-item d-flex justify-content-between align-items-center">
                        <div>
                            <input type="checkbox" class="mr-4">
                            {{Carbon\Carbon::parse($task['taskduedate'])->format('m/d/Y')}} - {{$task['tasktext']}}
                        </div>
                        <div>
                            <form class=".mb-0" action="#" method="POST">
                                @csrf
                                <button class="btn btn-sm btn-danger">&times;</button>
                            </form>
                        </div>
                    </li>
                    @endforeach
                </ul>
            </div>
        </div>
</div>
@endforeach

And my controller:

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Task;

class Contactshow extends Component
{

    public $contacts;
    public $tasktext;
    public $deal_id;
    public $taskduedate;

    public function mount($contacts)
    {
        $this->contacts = $contacts;
    }

    public function render()
    {
        return view('livewire.contactshow');
    }

    public function addTask()
    {
        dd($this->deal_id);
        Task::create([
            'deal_id' => $this->deal_id,
            'tasktext' => $this->tasktext,
            'taskduedate' => $this->taskduedate,
        ]);
    }
}
Jan
08
1 week ago
Activity icon

Replied to Property [taskduedate] Does Not Exist On The Component Instance.

Wow. Not sure how I missed that. So I added the public property. I no longer get the error. Thanks!

Jan
06
1 week ago
Activity icon

Started a new Conversation Property [taskduedate] Does Not Exist On The Component Instance.

I thought I followed the docs for this Livewire component but I am receiving this error:

Livewire controller:

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Task;

class Contactshow extends Component
{

    public $contacts;
    public $tasktext;
    public $deal_id = '';

    public function mount($contacts)
    {
        $this->contacts = $contacts->toArray();
    }

    public function render()
    {
        return view('livewire.contactshow');
    }

    public function addTask()
    {
        Task::create([
            'deal_id' => $this->deal_id,
            'tasktext' => $this->tasktext,
            'taskduedate' => $this->taskduedate,

        ]);
    }
}

View Code:

<div class="form-row">
        <div class="input-group date form-group col-md-9">
               <input type="text" name="tasktext" class="form-control" id="tasktext" placeholder="New Task" wire:model="tasktext">
        </div>
        <div class="form-group col-md-3" id="datepickerfield">
                 <div class="input-group date">
                     <input type="text" name="taskduedate" class="form-control" id="taskduedate" placeholder="Due Date" wire:model="taskduedate" data-provide="datepicker" data-date-autoclose="true" data-date-today-highlight="true" autocomplete="off">
                 </div>
        </div>
</div>
<div class="form-row">
        <div class="form-group col-md-12">
                <input type="hidden" name="deal_id" value="{{ $deal['id'] }}" wire:model="deal_id">
                <button class="btn btn-primary" wire:click="addTask" type="submit">Add</button>
         </div>
</div>

Not sure why it isn't catching 'deal_id' since I used 'wire:model="deal_id"'.

Wire:model should work on hidden fields, right?

Dec
31
2 weeks ago
Activity icon

Replied to Livewire.js 500 Internal Server Error

But I'm going to go that route and check the upgrade docs as I go. I think upgrading Laravel will fix the Livewire issue.

Activity icon

Replied to Livewire.js 500 Internal Server Error

Right. But if I go step by step then I will upgrade 3 times.

Activity icon

Replied to Livewire.js 500 Internal Server Error

Would it be easier to just do a fresh install and then try to move my controllers, models, and views over and then make config changes as necessary? Or can I just make the Laravel framework change in my composer.json file and let Laravel take care of the rest?

Activity icon

Replied to Livewire.js 500 Internal Server Error

Ok. I am just now realizing that this project sat around untouched, before adding Livewire, MUCH longer than I thought. The Laravel version on this app is 5.6.16.

I will upgrade to the latest version and then check Livewire again.

Activity icon

Replied to Livewire.js 500 Internal Server Error

When I type the link in directly I receive this message:

ErrorException (E_DEPRECATED)
Non-static method Livewire\LivewireJavaScriptAssets::unminified() should not be called statically

If I do not include

@livewireAssets

in the head tag, my page has no errors. I have uninstalled and reinstalled Livewire twice on my project.

Not sure what to do now. I agree with @nakov , this is weird. Might be a bug or conflict, but unsure what the next troubleshooting step is.

Dec
30
2 weeks ago
Activity icon

Replied to Livewire.js 500 Internal Server Error

local.ERROR: Non-static method Livewire\LivewireJavaScriptAssets::unminified() should not be called statically {"exception":"[object] (ErrorException(code: 0): Non-static method Livewire\LivewireJavaScriptAssets::unminified() should not be called statically at I:\laragon\www\REAssist\vendor\laravel\framework\src\Illuminate\Routing\Route.php:197) [stacktrace]

Activity icon

Replied to Livewire.js 500 Internal Server Error

No use of "defer".

Interestingly, I still have the standard welcome.blade.php in my app that contains the error, so I added the

@livewireAssets

to that file to skip the app.blade.php setup to see if that was a factor. I still get the same error.

I think I'm going to clear the Composer cache and reinstall the Livewire package like I did before, but this time skipping the cache and going straight to the repository. I honestly don't think that will work but I'm gonna try. :)

Activity icon

Replied to Livewire.js 500 Internal Server Error

Interesting. It loaded just fine on a fresh, clean project. I only required Livewire, then added the

@livewireAssets

in the head of the welcome.blade.php view.

No error. Checked the Sources tab in Developer Tools of Chrome and it shows that livewire.js loaded just fine.

Not sure what is blocking it, but it shows that the USB setup is not the issue.

Activity icon

Replied to Livewire.js 500 Internal Server Error

Yes. Very weird.

I tried it in Microsoft Edge (which I never use) and I received a similar error:

HTTP500: SERVER ERROR - The server encountered an unexpected condition that prevented it from fulfilling the request. GET - http://reassist.test/livewire/livewire.js?id=18f463023ea07950cbf6

Trying now on a new app.

I am running my apps on Laragon, running on a USB drive. That makes everything slow, but shouldn't affect whether Livewire installs and runs properly, right?

Activity icon

Replied to Livewire.js 500 Internal Server Error

Ok. Added the line to config/app.php. Ran composer dump-autoload.

Restarted the server for good measure.

Same error.

Activity icon

Replied to Livewire.js 500 Internal Server Error

Removed livewire from composer.json. Ran composer update (tried install but it told me to run update to make sure composer.lock was current) Composer removed Livewire Ran composer require livewire/livewire It installed (from cache) Ran my app Same error.

Activity icon

Replied to Livewire.js 500 Internal Server Error

Side note, why is it looking for the livewire.js in this directory: http://newapp.test/livewire/??

There is no "livewire" directory in the public directory.

Activity icon

Replied to Livewire.js 500 Internal Server Error

Tried it. Still get:

net::ERR_ABORTED 500 (Internal Server Error) on the same URL for Livewire.js

Activity icon

Replied to Livewire.js 500 Internal Server Error

The specific error says:

Failed to load resource: the server responded with a status of 500 (Internal Server Error), and references the livewire.js file.

This 500 error often happens when a file isn't found in the expected path. I'm following the basic documentation of Livewire.

Activity icon

Started a new Conversation Livewire.js 500 Internal Server Error

Anyone using Livewire?

The head of my app.blade.php ends like this:

@livewireAssets
</head>

To load Livewire, but when I load my component view, I see the following error in the Google Chrome console:

http://newapp.test/livewire/livewire.js?id=baf105a7de86deff8ac1 Status: 500

Am I calling Livewire the wrong way. Looks like it can’t find livewire.js. My app is in the root directory, as is standard in a Laravel installation. I did not install Laravel in a subdirectory.

Dec
27
3 weeks ago
Activity icon

Replied to Collection ToArray() Loses Collection Name. Just Says "array"

That is now working with your suggested syntax. But I am wondering why I can't use the Collection syntax like I had before.

Is it because Livewire does not accept this syntax because it is using Javascript behind the scenes which can only use arrays?

Dec
26
3 weeks ago
Activity icon

Replied to Collection ToArray() Loses Collection Name. Just Says "array"

My mistake. I am working in Livewire and changed the syntax to "$this->deals", and left off the "$this->" in the view, though now I am getting the "Trying to get a property "id" of non-object" error in this code:

@foreach($this->deals as $deal)
    <div class="col-md-6">
        <div class="well">
            <div class="row">
                <div class="col-md-9"><h3><a href="/deals/{{$deal->id}}">{{$deal->dealtype}}</a></h3></div>

on the last line at "{{$deal->id}}

I think this is happening because it is not an array and not an object. Is that right?

Activity icon

Replied to Collection ToArray() Loses Collection Name. Just Says "array"

Makes sense, though when I try that, I receive an "Undefined variable: deals" error on the line that starts the @foreach loop

Activity icon

Started a new Conversation Collection ToArray() Loses Collection Name. Just Says "array"

If I convert the collection "$deals" to an array using:

$deals->toArray()

It returns 2 arrays that both say "array:16" with the underlying data.

array:2 [▼
  0 => array:16 [▶]
  1 => array:16 [▶]

With the collection, I would get 2 separate arrays, but named "Deal", with different numbers.

Collection {#289 ▼
  #items: array:2 [▼
    0 => Deal {#284 ▶}
    1 => Deal {#282 ▶}
  ]
}

How do I name the array I convert the collection to, so I can reference them with something like:

$deal->id

Thanks.

Activity icon

Replied to Pass Variable To Included Livewire Component

Unless you mean, why don't I run the queries within the Livewire component to lookup the values I want?

Because I already have ran the queries, in the previous view that calls the Livewire component.

And it defeats the DRY principle of development. The $deals collection is sitting in the Livewire controller. It should be easily passed to the view, but I have tried every syntax I can think of. Livewire is made for Laravel. It should work with collections and arrays easily.

How do I get that data of the $deals collection into the view?

Activity icon

Replied to Pass Variable To Included Livewire Component

I don't know what that means. How do I do that?

Activity icon

Replied to Pass Variable To Included Livewire Component

Ok, so now I can get the $deals to dd() properly from the Deals.php Livewire controller, and it includes the underlying tasks collection, so the data is getting to the controller, but I can't get it into the Livewire view.

I get the "Undefined variable: deals" error.

Here is my updated code:

Line calling the Livewire component:

 @livewire('deals', $deals)

Livewire Controller:

<?php

namespace App\Http\Livewire;

use Livewire\Component;

class Deals extends Component
{
    public $deals;

    public function mount($deals)
    {
        return view('livewire.tasks', [
            'deals' => $deals
        ]);
    }
}

Livewire View:

@foreach($deals as $deal)
    <div class="col-md-6">
        <div class="well">
            <div class="row">
                <div class="col-md-9"><h3><a href="/deals/{{$deal->id}}">{{$deal->dealtype}}</a></h3></div>
                <div class="col-md-3">
                    <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>
                    <a href="link_to_action('[email protected]', $title, $parameters = array(), $attributes = array());">Delete</a>
                </div>
            </div>

            <div class="row">
                <div class="col-md-6"><h4>Price: {{moneyformat($deal->price)}}</h4></div>
                <!-- Calculation for Commission dollars from Price and CommissionPercentage -->
                <div class="col-md-6"><h5> Comm: {{moneyformat($deal->price * $deal->commissionpercentage * .01)}} - ({{$deal->commissionpercentage}}%)</h5></div>
            </div>
            <div class="tasks">
                <h5>Tasks</h5>
                <div class="card-block">
                    {!! Form::open(['route' => ['tasks.store']]) !!}
                    {{ csrf_field() }}
                    <div class="form-group">
                        {{Form::textarea('tasktext', null, array('placeholder' => 'Your task here', 'class' => 'form-control', 'rows' => '2'))}}
                    </div>
                    <div class="form-group">
                            {{Form::text('taskduedate', null, array('placeholder' => 'Due Date', 'class' => 'form-control', 'data-provide' => 'datepicker', 'data-date-autoclose' => 'true', 'data-date-today-highlight' => 'true'))}}
                    </div>
                    <div class="form-group">
                        {{Form::submit('Add Task', array('class' => 'btn btn-primary'))}}
                    </div>
                    <input type="hidden" name="deal_id" value="{{ $deal->id }}">
                    {{Form::close()}}
                </div>
                <div>
                    Livewire Tasks
                    <ul class="list-group">
                        @foreach($deal->tasks as $task)
                        <li class="list-group-item">
                            <input type="checkbox" class="mr-4">
                            <p>{{Carbon\Carbon::parse($task->taskduedate)->format('m/d/Y')}} - {{$task->tasktext}}</p>
                        </li>
                        @endforeach
                    </ul>
                    <ul class="list-group">
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            <div>
                                <input type="checkbox" class="mr-4">
                                Finish livewire screencast
                            </div>
                        </li>
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            <div>
                                Mow the lawn
                            </div>
                        </li>
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            <div>
                                Buy toilet paper
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
@endforeach

So, again, if I add:

dd($deals);

to the Livewire Deals Controller, it dumps a collection of 2 arrays. A deal in each array, with that tasks showing as an array under "relations", as their own collection, as I believe it is supposed to, exactly as it should be in the DB.

However, this data is not getting to the view.

Dec
24
3 weeks ago
Activity icon

Replied to Pass Variable To Included Livewire Component

Got it. I'll give that a try. I'll let you know how it goes. :)

Activity icon

Replied to Pass Variable To Included Livewire Component

I like that idea. But by "move everything", do you mean my whole app, or just the contact view, which includes the deal view, which includes the tasks Livewire component?

Activity icon

Replied to Pass Variable To Included Livewire Component

I can't even dd($deal) at the top of the Livewire component controller in the mount() method or the render() method to make sure it is receiving the variable '$deal'. When I try it tells me gives me the 'Undefined variable' error again. So, either the variable is undefined, or it's a collection, which Livewire can't use.

Huh?

Activity icon

Replied to Pass Variable To Included Livewire Component

Good idea.

Though now I get this error:

Livewire component's [tasks] public property [deal] must be of type: [numeric, string, array, null, or boolean]. Only protected or private properties can be set as other types because JavaScript doesn't need to access them.

Because 'deal' is a collection, which I have been taught by Laravel to use Relationships along with Collections for all of my data. But now the Laravel Javascript PHP miracle can't use Collections?

What is my life?

Activity icon

Replied to Pass Variable To Included Livewire Component

In their example, the variable sent is 'contactId', but the variable received by the mount function is 'id'. Then they run a query to define 'Contact', the defines the fields individually.

Doesn't seem like a practical Laravel style example.