jmacdiarmid

Member Since 2 Years Ago

Experience Points
850
Total
Experience

4,150 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
3
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 1
850 XP
Apr
08
5 days ago
Activity icon

Started a new Conversation Using Model Accessors And Mutators With Seeding And Testing (phpunit)

When I have accessors and mutators in a model when seeding, the model factory can't see the model properties.

For example:

In my User model, I tried setting up the fields as comment properties

/** 
 * @property mixed $name
 *
 */

and I've tried setting fields up as field variables


private string $name
 

then I created the getAttribute() and setAttribute() methods

public function getNameAttribute() 
{
	return $this->name;
}

public function setNameAttribute($value) 
{
	$this->name = $value;
}

UserFactory is the default out of the box factory - no changes.

In my phpunit test, I'm following the livewire screencasts for testing a User Profile and in one of the tests I have:


 $user = User::factory()->create();

in both of these cases, I get the following error:

 SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: users.name (SQL: insert into "users" ("email", "email_verified_at", "password", "remember_token", "updated_at", "created_at") values ([email protected], 2021-04-08 1
5:30:24, yIXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi, wyT8AnCf0f, 2021-04-08 15:30:24, 2021-04-08 15:30:24))

If I comment out all of the properties/fields and the get/set methods, seeding and phpunit tests work fine.

Any thoughts on how I can make the accessors and mutators work?

Mar
30
2 weeks ago
Activity icon

Replied to Need Help With Pushing Javascript In Livewire Blade Template

Ah ok. It was added to the app.blade layout but not the guest.blade layout.

        </div>

        @stack('modals')

        @livewireScripts

        @stack('scripts')

    </body>
</html>

Updated: It's working. :) I just added the stack('styles'), stack('modal') and stack('script') to my guest.blade layout which is the template I'm using for testing. I forgot I had added them to my app.blade template. :)

Thank you for pointing this out. I'll mark your response as best answer.

Activity icon

Replied to Need Help With Pushing Javascript In Livewire Blade Template

I have a delete method in the component class. The only thing I have in relation to "scripts" Is the @push('scripts') @endpush blade directives.

Activity icon

Started a new Conversation Need Help With Pushing Javascript In Livewire Blade Template

I'm having trouble with a button used to delete records and should display a confirmation dialog prior to deleting the record. I've read through the docs several times over and it's not clicking in my head. I've also tried some of the examples but they don't appear to work in my case either. What has worked is adding the

protected $listeners = [ event ,  method ]  

in the component class however this totally circumvents displaying the confirmation dialog.

I would like to figure this out because after this, I need to integrate a javascript/jquery signature pad into my project.

Here's my button:

<button wire:click="$emit('triggerDelete',{{ $contract->id }})"  class="bg-red-500 hover:bg-red-700 text-white font-bold py-1 px-4 rounded"  id="deleteContract">Delete</button>

Here is my in-line script:

@push('scripts')
    <script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/polyfill.js"></script>
    <script type="text/javascript">
        const Swal = require('sweetalert2')

        document.addEventListener('DOMContentLoaded', function (e) {
            @this.on('triggerDelete', contractId => {
                Swal.fire({
                    title: 'Are You Sure?',
                    text: 'Contract ' + contractId + '  will be deleted!',
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: '#d33',
                    cancelButtonColor: '#3085d6',
                    confirmButtonText: 'Delete!'
                }).then((result) => {
                    if (result.value) {
                        @this.call('delete',contractId)
                    } else {
                        console.log("Canceled");
                    }
                });
            });
        })
    </script>
@endpush

Mar
24
2 weeks ago
Activity icon

Replied to In Livewire, How Do I Determine If An Instance Of A Model Is Empty?

OMG! That worked!

The @forelse is really cool. :D Thank you for pointing that out!

Activity icon

Started a new Conversation In Livewire, How Do I Determine If An Instance Of A Model Is Empty?

In my render method, I'm trying to retrieve all records ordered by Id and Desc

 $contracts = Contract::orderBy('id', 'desc');
 return view('livewire.contracts', compact('contracts'));

In my blade view of the component, I'm using $contracts to build a table. I have inside of a @if @endif where I check to see if it's empty or not. It's only displaying table header. Any thoughts about how I can fix this?

<table>
     <thead>
            <tr>
                      <th>blah blah name</th>
            </tr>
     </thead>
@if (!empty($contracts)) 
     @if (count(array($contracts) > 0)
     
           @foreach($contracts as $contract)
				<tr>
                       <td>   {{ Str::limit($contract->company, 25) }}   </td>
                </tr>
           @endforeach   			

	 @endif
@else
            	<tr>
                       <td>   Sorry - No Data Found  </td>
                </tr>
@endif 

</table>

Mar
17
3 weeks ago
Activity icon

Replied to Building A Wrapper? For An External Api

Indeed, it is tricky. I've been researching this off and on while over the last 4-5 months. Most of the examples on the api docs are using curl cli. I found a site with quite a few conversion tools including a tool that will convert curl cli commands to php. https://onlinedevtools.in/curl

What's also surprising is that Simpli.fi doesn't have any examples on GitHub. I did manage to stumble across a script that shows how send a "GET" query which was written in python.

The only thing I've found so far on YT is tips on advertising using their service such as Retargeting, Geo-targeting and Geofencing.

Mar
16
4 weeks ago
Activity icon

Replied to Building A Wrapper? For An External Api

I will need to capture data for new client campaigns using a form and will need to post the data using the simplifi api. Once the campaign data has been submitted then we plan to use the api for tracking and reporting purposes. Any api used for this app will be third-party apis for instance, I'm also planning to use the Asana api to automate the creation of new tasks when a contract is approved by our client.

Activity icon

Replied to Building A Wrapper? For An External Api

Thank you for this. I'll give it a try. :)

Activity icon

Started a new Conversation Building A Wrapper? For An External Api

I'm using Laravel 8 and need to integrate a third-party "external" api into my app but I'm not sure how to go about it. I've successfully connected to the third-party service using Guzzle, made my first "get" and I received a json string as expected but not sure where to go from there. I've read some articles that say I need to use an APIresource to transform the data into a format that can be saved to a database and/or rendered in a view.

I found a post here on Laracasts https://laracasts.com/discuss/channels/general-discussion/create-api-wrapper-best-practice and started to go through the course here https://laracasts.com/series/incremental-api-development. Both sources are 5 years old.

I've walked through several articles on API development that suggest creating a custom facade, custom service provider, etc. and tried to duplicate what they the poster demonstrated but can't seem to get the code to work; in the router, the alias of the facade isn't found and wants me to create the class in the route file.

Most examples I find are using Laravel version prior to Laravel 8.

Articles: https://www.codecheef.org/article/how-to-create-and-use-custom-facade-in-laravel-6 https://medium.com/@cmanish049/creating-custom-facades-in-laravel-b9b72d573752

The api I need to integrate is for the Simpli.fi advertising for digital marketing agencies and media companies. https://simpli.fi/

My goal is to find an updated resource that will show me how to do this and I'm hoping someone can point me in the right direction. The Laravel documentation is a bit vague so another "hope" I have is that I can find an example.

Mar
10
1 month ago
Activity icon

Replied to Seeding A Table Referencing Foreign Keys

Thank you for that. Yes, I know it's wrong which is why I posted. I was hoping someone might be able to tell me what I'm doing wrong as indicated by the green "assistance" sticker at the top of the post. :)

Activity icon

Replied to Seeding A Table Referencing Foreign Keys

Ok. Yes, that gives me null too. Anyone else?

Activity icon

Replied to Seeding A Table Referencing Foreign Keys

It's null on your end most-likely because you don't have my table data. :)

Activity icon

Started a new Conversation Seeding A Table Referencing Foreign Keys

I'm trying to seed a Contracts table has 2 foreign keys which reference a Campaign Durations table and a Campaign Packages table. The Packages table has a foreign key that references the Campaign Duration table.

I want to:

  • randomly pick a Campaign Duration. (1 out of 3 choices)
  • randomly pick a Campaign Package based on the previously chosen duration Id .
  • Save both ids to the Contracts table.

This is the code I'm working with so far. The Campaign Duration line below works and the second line works somewhat but I can't access $package as an object or an array.

$duration = CampaignDuration::inRandomOrder()->first();
$package = CampaignPackage::with(['duration'])->inRandomOrder()->where('duration_id', '=', $duration->id)->first();
Feb
27
1 month ago
Activity icon

Replied to Trying To Get A Random Child Record.

In my ContractsTableSeeder, I have:

Contract::factory(25)->create();

In my ContractsFactory, I have:

  $duration = CampaignDuration::with('packages' )->inRandomOrder()->first();
    $package = CampaignPackage::where('duration_id','=', $duration->id)->inRandomOrder()->first();

    $setup_fee = 300;
    $creative_ad_set = (bool) (random_int(0,1) === 1);
    $creative_ad_set_cost = ($creative_ad_set) ? 300.00 : 0;
    $microsite_landingpage = (bool) random_int(0,1);
    $microsite_landingpage_cost = ($microsite_landingpage) ? 800.00 : 0;
    $deposit_amount = random_int(500, 1000) / 10;
    $monthly_impression_cost = 0;

    return [
        'company_id'                    => Company::all()->random()->id,
        'landing_page_url'              => $this->faker->url,
        'requested_startdate'           => $this->faker->date('Y-m-d'),
        'duration_id'                   => $duration['id'],
        'package_id'                    => $package['id'],
        'package_cost'                  => $package['price'],
        'creative_ad_set'               => $creative_ad_set,
        'creative_ad_set_cost'          => $creative_ad_set_cost,
        'setup_fee'                     => $setup_fee,
        'microsite_landingpage'         => $microsite_landingpage,
        'microsite_landingpage_cost'    => $microsite_landingpage_cost,
        'deposit_amount'                => $deposit_amount,
        'monthly_impression_amount'     => $package['monthly_investment'],
        'campaign_total_amount'         =>
            (float) $creative_ad_set_cost + (float) $microsite_landingpage_cost + (float) $setup_fee +
            (float) $deposit_amount + (float) $monthly_impression_cost,
        'additional_service_notes'      => $this->faker->sentences(random_int(0, 4)),
        'first_name_on_account'         => $this->faker->firstName,
        'last_name_on_account'          => $this->faker->lastName,
        'client_signature'              => '',
        'client_name_as_signed'         => $this->faker->name,
        'consultant_signature'          => '',
        'consultant_name_as_signed'     => $this->faker->name,
    ];
Feb
26
1 month ago
Activity icon

Started a new Conversation Trying To Get A Random Child Record.

I have 3 campaign durations {6 month, 12 month, and custom).

Only the first 2 have child package records.

Campaign Duration migration:

  • id
  • title

In my Campaign Duration Model:

public function packages(): HasMany { return $this->hasMany(CampaignPackage::class, 'duration_id', 'id'); }

Campaign Package migration

  • id
  • duration_id
  • title
  • price

In my Campaign Package Model:

public function campaign_duration(): BelongsTo { return $this->belongsTo(CampaignDuration::class, 'duration_id'); }

I can get the random duration with this:

$duration = CampaignDuration::with('packages' )->inRandomOrder()->first();

and a random child package with this:

$package = CampaignPackage::where('duration_id','=', $duration->id)->inRandomOrder()->first();

dd($package->id); < If I do this, I can get the random id

My goal is to use this when seeding a campaigns table however when I try to assign the $package->id value to an array element in the CampaignFactory , I get the following error when running migrate:fresh --seed

Can someone tell me what I'm doing wrong?

ErrorException

Trying to get property 'price' of non-object

Feb
24
1 month ago
Activity icon

Replied to Having Trouble Understanding BPMN Frameworks.

Thank you very much for your reply.

What is the question? Well, in this case, it's like I have BPMN v2,0 in one hand, and Laravel in the other. I'm trying to determine whether or not I even need to use it and how would I do that. It's like asking what the question is to the answer "42".

To answer your question, if you have a solution, I won't turn it down... lol (joking, of course).

All seriousness aside, no. I wanted to give as much detail as I could so that someone could point me in the right direction. That, you did. I will consider myself, "pointed". : )

Feb
23
1 month ago
Activity icon

Started a new Conversation Having Trouble Understanding BPMN Frameworks.

I'm working on a project that will automate the process of creating and submitting advertising campaigns to a third-party resource that uses geolocation technology such as geo-targeting and geo-fencing. In the research that I've done, everything I've read makes it sound like this is something I need or should have in my project. There are a few php-based frameworks I have found but only 1 that works is compatible with Laravel.

The steps in our process is: 1- Contract creation 2- Client approves contract 3- Process enters a simultaneous split where a- Information is set to billing. b- Information is stored in database c- task is created in asana. d- enters the on-boarding/detailed requirements discussion with client. 4- Simultaneous split a- campaign is created b- ad graphics are created. 5- Campaign submission order is completed a- campaign ad content is attached 6- Campaign order is sent to third-party via Rest API. 7- Campaign order submission and creation confirmation is sent to client. 8- Campaign monitoring and reporting phase.

I'm working on creating a process in Camunda. Outside of that, I don't know where to start or how the BPMN framework is integrated into a Laravel application.

Each phase listed above must be completed before moving on to the next phase.

Feb
20
1 month ago
Activity icon

Replied to Laravel/Eloquent MySQL Relationship 1:n And 1:1 Help Needed

@lemmon Thanks for this. I'm definitely considering signing up for that. I need all the help I can get. :)

Feb
18
1 month ago
Activity icon

Replied to Laravel/Eloquent MySQL Relationship 1:n And 1:1 Help Needed

@lemmon and @jlrdw Thank you! :) I'll take a look at those resources.

Activity icon

Replied to Laravel/Eloquent MySQL Relationship 1:n And 1:1 Help Needed

I forgot to mention that the client table has a 1:n relationship with the campaigns table.

Activity icon

Started a new Conversation Laravel/Eloquent MySQL Relationship 1:n And 1:1 Help Needed

I'm building an app for a digital marketing agency to automate advertising campaign submission and tracking for clients. I'm having trouble wrapping my head around what relationships I need based on the current manual process. I'm the only developer working on this project so I feel like I'm sitting on an island out in the ocean. lol The way the process works now is we have a client prospect, a contract is created, if the prospect/client approves the process goes to the on-boarding/discovery phase followed by the campaign creation and insertion order creation.

The way I have my relationships set up so far is like this:

  1. Client table has a 1:n relationship with the contracts table.

  2. Contracts, discovery and insertion orders table has a 1:1 relationship with the campaigns table.

  3. Contracts table has an foreign key for both the client and campaigns table.

  4. Campaigns table has a foreign key for the Client table.

I created an ERD in MySQL Workbench. It shows identifying and non-identifying 1:1 and 1:n. Should I be concerned with these?

As far as the models go, I currently have:

In the Client model:

  • contracts hasMany(Contract::class)
  • campaigns hasMany(Campaigns::class)

In the Campaign model, I have:

  • client - belongsTo(Client::class)

In the Discovery and Insertion Order models:

  • campaign - belongsTo(Campaign::class)

In the Contract model:

  • client - belongsTo(Client::class)
  • campaign belongsTo(Campaign::class)

If you need additional information, please let me know.

Know of any resources, tutorials, etc that might help shed more light on this?

Jan
21
2 months ago