ptorres

Member Since 4 Months Ago

Experience Points
4,070
Total
Experience

930 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
36
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
4,070 XP
Mar
08
1 month ago
Activity icon

Started a new Conversation Updating Table As User Make Selections In Other Table In Same Page.

Hi,

My first Laravel Livewire attempt

Livewire v2.x Laravel v8.x

I want the table "Selected Services" to be updated as the user selects services in the table "Services".

Any advice is much appreciated.

createPetitions.php

<?php

namespace App\Http\Livewire;

use App\Models\Service;
use Livewire\Component;

class CreatePetitions extends Component
{
    public $selectedServices = [];

    public function updateSelectedServices()
    {
        //What do I do here?
    }

    public function render()
    {
        return view('livewire.create-petitions', [
            'services' => Service::all()
        ]);
    }
}

create-petitions.blade.php

<div class="mb-8">
    <h3>
        {{ __('Services') }}
    </h3>
    <div>
        @if($services->count())
            <table class="table table-striped">
                <thead>
                    <th></th>
                    <th>{{ __('Category') }}</th>
                    <th>{{ __('Services') }}</th>
                </thead>
                <tbody>
                    @foreach ($services as $item)
                        <tr>
                            <td>
                                <input wire:model="selectedServices" type="checkbox" value="{{ $item->id }}">
                                <label for="{{ $item->id }}"></label>
                            </td>
                            <td>{{ $item->category->name }}</td>
                            <td>{{ $item->name }}</td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        @endif
    </div>
</div>
<div class="mb-8">
    <h3>
        {{ __('Selected Services') }}
    </h3>
    <div>
        @if($selectedServices->count())
            <table class="table table-striped">
                <thead>
                <th>{{ __('Category') }}</th>
                <th>{{ __('Services') }}</th>
                </thead>
                <tbody>
                    @foreach ($selectedServices as $selectedService)
                        <tr>
                            <td>{{ $selectedService->category->name }}</td>
                            <td>{{ $selectedService->name }}</td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        @endif
    </div>
</div>
	
Mar
05
1 month ago
Activity icon

Replied to Pivot Table OrderBy - Laravel 8.x

Thank you @npispas that worked nicely.

Activity icon

Started a new Conversation Pivot Table OrderBy - Laravel 8.x

Hi everyone,

Laravel 8.x

Please, I have a pivot table “application_service” that holds the choices made by the app users in regards to the services they choose.

Note that each service belongs to a category.

I want to show the chosen services ordered by: first, category.order then by, service.order. Any advice on what to do to achieve this?

Model Application

public function services()
    {
        return $this->belongsToMany(Service::class)->withTimestamps();
    }

Model Service

public function applications()
    {
        return $this->belongsToMany(Application::class)->withTimestamps();
    }

Table (pivot) application_service

class CreateApplicationServiceTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('application_service', function (Blueprint $table) {
            $table->id();
            $table->foreignId('application_id');
            $table->foreignId('service_id');
            $table->timestamps();

            $table->foreign('application_id')
                ->references('id')
                ->on('applications')
                ->onDelete('cascade');

            $table->foreign('service_id')
                ->references('id')
                ->on('services')
                ->onDelete('cascade');

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('application_service');
    }
}

Controller

public function show($uuid)
    {
        $application = Application::where('uuid', $uuid)->firstOrFail();

        return view('applications.edit', compact('application'));
    }

View

//Need to be ordered by category and then by service.

@foreach($application->services as $service)
	<ul>
		<li>{{ $service->category->name }} - {{ $service->name }}</li>
	</ul>
@endforeach

Thank you.

Feb
20
1 month ago
Activity icon

Started a new Conversation Mail Markdown Messages - Invalid Argument Supplied For Foreach()

Issue:

Hi, I have the following setup, why do I get the error:

Invalid argument supplied for foreach() (View:

Thank you.

Controller

$services = Services::all();

Mail::to($mail_to_address)->send(new ApplicationNew($services));

dd($services);

Illuminate\Database\Eloquent\Collection {#1816 ▼
    #items: array:281 [▼
    0 => App\Models\Service {#1815 ▼
      #fillable: array:15 [ …15]
      #connection: "mysql"
      #table: "services"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:18 [ …18]
      #original: array:18 [ …18]
      #changes: []
      #casts: []
      #classCastCache: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: []
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #guarded: array:1 [ …1]
    }
    1 => App\Models\Service {#1814 ▶}
    ...
}

ApplicationNew.php

<?php

namespace App\Mail;

use App\Models\Services;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class ApplicationNew extends Mailable
{
    use Queueable, SerializesModels;

    public $services;


    public function __construct($services)
    {

        $this->$services = $services;
    }


    public function build()
    {
        return $this->markdown('emails.applications.new');
    }
}

new.blade.php

@component('mail::message')
@foreach($services as $service)
{{ $service->name }}
@endforeach
@endcomponent

Error

Invalid argument supplied for foreach() (View:...