SPL3S

SPL3S

Member Since 6 Months Ago

Experience Points 2,440
Experience Level 1

2,560 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 21
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

13 Jun
5 days ago

SPL3S left a reply on Show Other Products Owned By The Owner

@NAKOV - Thanks for pointing that out it works now!

@foreach($products as $item)
    @if($product->owner_id === $item->owner_id)
        {{ $product->name }}
    @endif
@endforeach

SPL3S started a new conversation Show Other Products Owned By The Owner

I have a product page where all the product info is shown, and at the bottom, I want to show other products owned by the owner, but I can't think of the way doing it...

I have $product->owner_id which displays the owner's id 'SPL3S' but if I try to do


@if($product->owner_id == $product->owner_id)

   @foreach($products as $product)
       
       {{ $product->name }}
   
   @endforeach

@endif

I still get all the products owned by other users too. I also tried to store owner_id as

$owner = $product->owner_id;

and then doing same if rule


@if($product->owner_id == $owner)

    @foreach($products as $product)
        
        {{ $product->name }}
    
    @endforeach

@endif

but still get all the products in the table

10 Apr
2 months ago

SPL3S left a reply on Hide Submit Form When Data Present In DB & Show Update Form

Ok I made it to work:

@if($clubName != NULL)
    <form action="/club-info/{{ $clubInfo_id }}" method="POST">
    @method('PATCH')
    @csrf
@else
     <form action="/events/{{ $event->id }}/club-info/{{ $clubInfo_id }}" method="POST">
        @csrf
        @endif

I had to make a not very nice query, I would like to find loquent way of doing it:

 $clubName = \DB::table('club_infos')->where(['user_id' => $user_auth_id, 'event_id' => $event->id])->value('club_name');
```
20 Mar
2 months ago

SPL3S left a reply on Can Store File But Can't Destroy It

@SNAPEY - Thank you! indeed the destroy route was outside {event} route. That's why the store method worked because It was in the group prefix

Route::prefix('events/{event}')->group(function () {
Route::post('category-age', '[email protected]')->name('events.category.store');
});

and my destroy method was in its own

Route::delete('category-age/{categoryAge}', '[email protected]')->name('category.destroy');

So I guess I did this way at the beginning of building the structure, which worked without files being nested into folders.

I keep forgetting to check my routes setup when trying to debug.

19 Mar
2 months ago

SPL3S left a reply on Can Store File But Can't Destroy It

I tried to store event to a variable

$event = Event::all();

and call it this way, and now I get:

Property [title] does not exist on this collection instance.

where destroy dd($event) return:

Collection {#412 ▼
  #items: array:1 [▼
    0 => Event {#411 ▼
      #fillable: array:4 [▶]
      #connection: "mysql"
      #table: "events"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:6 [▼
        "id" => 1
        "title" => "Klaipeda Open 2018"
        "description" => "Klaipeda Open 2018 is biggest event  in klaipeda"
        "image" => "no_image.jpeg"
        "created_at" => "2019-03-07 15:59:58"
        "updated_at" => "2019-03-07 15:59:58"
      ]
      #original: array:6 [▼
        "id" => 1
        "title" => "Klaipeda Open 2018"
        "description" => "Klaipeda Open 2018 is biggest event  in klaipeda"
        "image" => "no_image.jpeg"
        "created_at" => "2019-03-07 15:59:58"
        "updated_at" => "2019-03-07 15:59:58"
      ]
      #changes: []
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: []
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #guarded: array:1 [▶]
    }
  ]
}

SPL3S left a reply on Can Store File But Can't Destroy It

@SNAPEY - My store dd($event) return:

Event {#428 ▼
  #fillable: array:4 [▼
    0 => "user_id"
    1 => "title"
    2 => "description"
    3 => "image"
  ]
  #connection: "mysql"
  #table: "events"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:6 [▼
    "id" => 1
    "title" => "Klaipeda Open 2018"
    "description" => "Klaipeda Open 2018 is biggest event in klaipeda"
    "image" => "no_image.jpeg"
    "created_at" => "2019-03-07 15:59:58"
    "updated_at" => "2019-03-07 15:59:58"
  ]
  #original: array:6 [▼
    "id" => 1
    "title" => "Klaipeda Open 2018"
    "description" => "Klaipeda Open 2018 is biggest event  in klaipeda"
    "image" => "no_image.jpeg"
    "created_at" => "2019-03-07 15:59:58"
    "updated_at" => "2019-03-07 15:59:58"
  ]
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [▼
    0 => "*"
  ]
}

But destroy dd($event) return:

Event {#390 ▼
  #fillable: array:4 [▼
    0 => "user_id"
    1 => "title"
    2 => "description"
    3 => "image"
  ]
  #connection: null
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: false
  +wasRecentlyCreated: false
  #attributes: []
  #original: []
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [▼
    0 => "*"
  ]
}

Why I don't get any attributes in destroy method?

SPL3S left a reply on Can Store File But Can't Destroy It

I just tried to dd() the whole method and it returned

false

Then I tried to dd($event->title) and it returned

null

For some reason destroy method can't get the $event-> title?

SPL3S left a reply on Can Store File But Can't Destroy It

That's the thing, I don't get any error, telescope also shows only the request for removing data from the table

Telescope Query

delete from
  `category_ages`
where
  `id` = 4

Which does remove the data from the table, but leaves the file present in the folder

SPL3S started a new conversation Can Store File But Can't Destroy It

If I use just directory and file name everything is fine, I can store and destroy.

Store

public function store(Event $event, CategoryAge $categoryAge) {

        if ($validFile = request()->validate([
            'music' => 'nullable|file|mimetypes:audio/mpeg,audio/mp4,audio/mp3,audio/mpeg4-     generic|max:6000'])) {
            $music = $validFile['music'];
            $fileName = $music->getClientOriginalName();
            $musicFileName = time() . '_' . $fileName;
            $music->storeAs('public/music/', $musicFileName);

        } else {
            $musicFileName = 'no music file';
        }
}

Destroy

public function destroy(Event $event, CategoryAge $categoryAge) {
        $categoryAge->delete();

        if ($categoryAge->music != 'no music file') {
            Storage::delete('public/music/' . $categoryAge->music);
        }

But if I concatenate $event->title I can only store, for some reason I can't destroy it...

Store (which stores into nested folder that corespond to event title)

$music->storeAs('public/music/' . $event->title, $musicFileName);

Destroy doesn't work

Storage::delete('public/music/' . $event->title, $categoryAge->music);
14 Mar
3 months ago

SPL3S left a reply on Hide Submit Form When Data Present In DB & Show Update Form

@BORISU - Controller

    public function show(clubInfo $clubInfo, Event $event, Athlete $athlete) {
        $user_auth_id = auth()->id();
        $clubInfoCoaches = ClubInfoCoaches::all();
        $clubInfoJudges = ClubInfoJudges::all();
        $clubInfoAccompanyingPerson = ClubInfoAccompanyingPerson::all();
        $clubInfo = clubInfo::all();

        return view('club-info.show', compact('event', 'clubInfo', 'athlete', 'user_auth_id', 'clubInfoCoaches', 'clubInfoJudges', 'clubInfoAccompanyingPerson'));
    }

route

 Route::get('events/{event}/club-info', '[email protected]')->name('events.club-info.show');

table

 Schema::create('club_infos', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('event_id');
            $table->unsignedInteger('user_id');
            $table->string('club_name');
            $table->string('club_country');
            $table->string('club_city');
            $table->string('club_head_of_delegation');
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users');

Event model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Event extends Model {
    protected $fillable = [
        'user_id',
        'title',
        'description',
        'image',
    ];

    public function athletes() {
        return $this->hasMany(Athlete::class);
    }

    public function categoryAges() {
        return $this->hasMany(CategoryAge::class);
    }

    public function club_infos() {
        return $this->hasOne(clubInfo::class);
    }
}

SPL3S left a reply on Hide Submit Form When Data Present In DB & Show Update Form

@BORISU - (auth()->user()->club_info) works but the issue now is that user has several club_info (for different events) so I get from other events if current event dont have any

11 Mar
3 months ago

SPL3S left a reply on Hide Submit Form When Data Present In DB & Show Update Form

@BORISU - You are right, there shouldn't be @foreach method, I am trying to make a relationship:

public function club_infos() {
        return $this->hasOne(clubInfo::class)->where('user_id')->auth()->id();
    }

and do a check if its valid or not. I will also have to check the last series which you referred about the activities, was it in the laravel from scratch?

08 Mar
3 months ago

SPL3S left a reply on Hide Submit Form When Data Present In DB & Show Update Form

@BORISU - This is just going to change the method, but the "submit" form will be still visible along with "update" isn't?

is there a way to use logic like?

@if($clubInfo->user_id == $user_auth_id && $event->id == $clubInfo->event_id)

So it checks if there is data entered by that user in the table, and then also checks if its for the current event. And if both are correct it will show PATCH form, else it will be POST form

SPL3S left a reply on Hide Submit Form When Data Present In DB & Show Update Form

@borisu the whole idea is that when you enter the data to the form I want "submit" form to disappear so that the user can only one club name country city etc. and after he submits, the same form then changes from POST to PATCH so he can then only update that entered information. I don't want the user to submit two clubInfo data

SPL3S started a new conversation Hide Submit Form When Data Present In DB & Show Update Form

Hey guys and girls,

I've been breaking my head for a few days trying to solve simple bug for advanced minds.

I have a simple form that submits some data to DB and it then changes to update method form. I made it work when there are no other entries in the table, but when there are more entries, my new submission form is not showing up for other users, and I know why, because of my count(). How could I change my logic instead of using count()?


    <table class="table">
        <thead>
            <tr>
                <th scope="col">
                    Club Name!!
                </th>
                <th scope="col">
                    Country
                </th>
                <th scope="col">
                    City
                </th>
                <th scope="col">
                    Head Of delegation
                </th>
            </tr>
        </thead>
            @if($event->clubInfos->count())
            @foreach($event->clubInfos as $clubInfo)
            @if($clubInfo->user_id == $user_auth_id)
        <tbody>
            
            <tr>
                <form action="/club-info/{{ $clubInfo->id }}" method="POST">
                    @method('PATCH')
                @csrf
                    <td>
                        <div class="form-group">
                            <input class="form-control" name="club_name" required="" type="text" value="{{ $clubInfo->club_name }}">
                            </input>
                        </div>
                    </td>
                    <td>
                        <div class="form-group">
                            <input class="form-control" name="club_country" required="" type="text" value="{{ $clubInfo->club_country }}">
                            </input>
                        </div>
                    </td>
                    <td>
                        <div class="form-group">
                            <input class="form-control" name="club_city" required="" type="text" value="{{ $clubInfo->club_city }}">
                            </input>
                        </div>
                    </td>
                    <td>
                        <div class="form-group">
                            <input class="form-control" name="club_head_of_delegation" required="" type="text" value="{{ $clubInfo->club_head_of_delegation }}">
                            </input>
                        </div>
                    </td>
                    <td>
                        <div class="form-group">
                            <button class="btn btn-success" style="cursor:pointer" type="submit">
                                Update
                            </button>
                        </div>
                    </td>
                </form>
                <td>
                    <form action="/club-info/{{ $clubInfo->id }}" method="POST">
                        @method('DELETE')
                        @csrf
                        <button class="btn btn-warning" style="cursor:pointer" type="submit">
                            clear
                        </button>
                    </form>
                </td>
            </tr>
        </tbody>
        @endif
        @endforeach
        @else
        <tbody>
            <form action="/events/{{ $event->id }}/club-info" method="POST">
                @csrf
                <tr>
                    <td>
                        <div class="form-group">
                            <input class="form-control" name="club_name" required="" type="text" value="{{ old('club_country') }}">
                            </input>
                        </div>
                    </td>
                    <td>
                        <div class="form-group">
                            <input class="form-control" name="club_country" required="" type="text" value="{{ old('club_country') }}">
                            </input>
                        </div>
                    </td>
                    <td>
                        <div class="form-group">
                            <input class="form-control" name="club_city" required="" type="text" value="{{ old('club_city') }}">
                            </input>
                        </div>
                    </td>
                    <td>
                        <div class="form-group">
                            <input class="form-control" name="club_head_of_delegation" required="" type="text" value="{{ old('club_head_of_delegation') }}">
                            </input>
                        </div>
                    </td>
                    <td>
                        <div class="form-group">
                            <button class="btn btn-primary" style="cursor:pointer" type="submit">
                                Save
                            </button>
                        </div>
                    </td>
                </tr>
            </form>
        </tbody>
    @endif
    </table>
</div>

23 Jan
4 months ago

SPL3S left a reply on Store Current(future?) Entry ID

@SNAPEY - Thanks! it did work. Same as @usaandi mentioned having it as variable, but your decoupling relationship made it work.

Now I just need to analyze how and everything worked

SPL3S left a reply on Store Current(future?) Entry ID

@SNAPEY - Hi Snapey,

Thanks for making neater and less typed, could you please elaborate on capturing the return value? at the moment I still get a NULL value.

And if you don't mind, can you explain what it does when it's decoupled like that?

$categoryAge->categoryAgeAthletes()

Thanks for your time

22 Jan
4 months ago

SPL3S started a new conversation Store Current(future) Entry ID

I'm sure there is a much smarter method to do this but my brain can't think of one, as I'm still learning basics...

I have a form where the user selects options and then selects multiple names. Options are stored to the table "categoryAge". Names are stored to "categoryAgeAthletes" table in order to keep each entry in separate rows so it's easier to edit for the user. I can store the data, but I can't figure how to get ID of the "categoryAge" entry in "categoryAgeAthletes" to keep track of it. I tried to use ['categoryAge_id' => $categoryAge->id] in for each loop, but it doesn't work as logically that ID doesn't exist at the time of the store function.

public function store(Event $event, CategoryAge $categoryAge)
    {
        
        $attributes = request()->validate([
            'ageGroup' => ['required', 'min:3'],
            'competitionCategory' => ['required', 'min:2'],
            'music' => ['required', 'min:4'],
            'nthCategory' => ['required', 'min:1']
        ]);

        //get multiple or single selected names
        $athleteNames = request('surnameName');
    
        categoryAge::create(
            $attributes + 
            ['event_id' => $event->id] + 
            ['user_id' => auth()->id()]
        );

        //store athletes names to categoryAgeAthletes table
        foreach ($athleteNames as $athleteName) {
           $data = new categoryAgeAthletes(
            ['surnameName' => $athleteName] +
            ['categoryAge_id' => $categoryAge->id] +
            ['user_id' => auth()->id()]
        );

           $data->save();
       }
        
        return back();  
    }