SPL3S

SPL3S

Member Since 1 Year Ago

Experience Points
3,150
Total
Experience

1,850 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
26
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 1
3,150 XP
Aug
15
5 months ago
Activity icon

Replied to Getting List Of Products Only Containting Specific Like(trait) Count

changed from ::where to ::whereIn and it works as expected

    $liked = DB::table('likeable_like_counters')->where('count', '>=', '1')->pluck('likable_id');
        $products = Product::whereIn('id', $liked)->paginate(30)
Aug
13
5 months ago
Activity icon

Replied to Getting List Of Products Only Containting Specific Like(trait) Count

I also tried to pluck id of the liked product but it returns just the first product from the liked table

 $likedProducts = DB::table('likeable_like_counters')->where('count', '>=', 1)->pluck('likable_id');

        $products = Product::where('id', $likedProducts)->paginate(30);
Activity icon

Replied to Getting List Of Products Only Containting Specific Like(trait) Count

Thanks for the comment, but the likeCount is not stored in the same product table

Aug
12
5 months ago
Activity icon

Started a new Conversation Getting List Of Products Only Containting Specific Like(trait) Count

I have a bunch of products and some of them are liked using https://github.com/rtconner/laravel-likeable/tree/laravel-5 trait.

The problem is that I can't think of how to display products that have a certain amount of likes in a page.

At the moment I have:

    public function favouriteProducts(Product $product)
    {
        $products = Product::paginate(30);

        return view('products.favourite', compact('products'));
    }

With blade:

    <div class="row">
        @foreach($products as $product)
          @if($product->likeCount >= 1)
            @include('partials.product-card')
          @endif
        @endforeach
    </div>
    <div class="row">
       <div class="col"></div> 
            <div class="col mt-3">{{ $products->links() }}</div>
       <div class="col"></div>  
    </div>

But the problem is that 1 product is shown in first page, and then another liked product is show in page 125, so I guess there is issue with paginating? Product in page 1 is the first product created and liked.

Is there a way to sort the products by the likeCount counter?

Jul
24
5 months ago
Activity icon

Replied to Seeding Database Tables That Have Foreign Key Constrains, Or Better Way To Regenerate Models With Same Information

Thanks for the example, Laravel daily shows how to assign them randomly with new seeding, in my case I always want the Clothing match with Women's which then should match with skirt:

category->subcategory->subsubcategory Clothing->Women's->Skirt,

and then another would be:

Electronics->Portable->Laptops

Activity icon

Started a new Conversation Seeding Database Tables That Have Foreign Key Constrains, Or Better Way To Regenerate Models With Same Information

I did some research on how to seed with foreign keys, and most of them include faker, which then randomly assigns those fields.

Unfortunately, this doesn't really work for me (I think) as I need the same data every time.

I have a relationship of

category()->subCategory()->subSubCategory()->product

I keep all categories and subcategories in the database so that I could update, rearrange, or delete them. I want to be able to regenerate them on the fly rather than creating a category then going creating subcategories and later creating subSubCategories which all foreign key constrained.

        Schema::create('categories', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('slug')->unique();
            $table->timestamps();
        });

        Schema::create('sub_categories', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('category_id')->unsigned();
            $table->string('name');
            $table->string('slug')->unique();
            $table->timestamps();

            $table->foreign('category_id')
            ->references('id')->on('categories')
            ->onDelete('cascade');
        });


        Schema::create('sub_sub_categories', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('sub_category_id')->unsigned();
            $table->string('name');
            $table->string('slug')->unique();
            $table->timestamps();

            $table->foreign('sub_category_id')
            ->references('id')->on('sub_categories')
            ->onDelete('cascade');
        });

So I was thinking of using seeder for this to make my life easier

class CategoryTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
    //categories
        DB::table('categories')->insert([
            'name' => 'Clothing',
            'slug' => 'clothing',
        ]);
        DB::table('categories')->insert([
            'name' => 'Shoes',
            'slug' => 'shoes',
        ]);

    //subcategories
           DB::table('sub_categories')->insert([
                'category_id' => '1',
                'name' => 'Womens',
                'slug' => 'womens',
            ]);
            DB::table('sub_categories')->insert([
                'category_id' => '1',
                'name' => 'Mens',
                'slug' => 'mens',
            ]);
    }
}

But I face with

Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`paciaisau`.`sub_categories`, CONSTRAINT `sub_categories_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE) (SQL: insert into `sub_categories` (`category_id`, `name`, `slug`) values (1, Womens, womens))

What would be the right way of doing this?

Jul
23
6 months ago
Activity icon

Replied to PATCH Doesn't Update Database Table, But Payload Is Correct

Thanks! Removed the second request in the update and it works now.

Activity icon

Started a new Conversation PATCH Doesn't Update Database Table, But Payload Is Correct

This one is weird... I have several patch methods but this particular one doesn't want to work. I tried with different routes, with specifying the product that is being updated id, but somehow it doest reach the table. Maybe I missed something.

I also use cviebrock/eloquent-sluggable for the product model, but I have onUpdate=> true which allows to rewrite the slug.

Route::patch('/product/{product}', '[email protected]')->name('update.product')->middleware('auth');
    public function update(Request $request, Product $product) {

        $attributes = request([
            'name',
            'description',
            'sub_sub_category_id',
            'condition',
            'sellType',
            'price',
        ]);

        
        $product->update(request($attributes));

        return back()->with('message', 'Product info updated!');
    }
<form action="{{ route('update.product', $product->id) }}" method="POST" enctype="multipart/form-data">
                    @method('PATCH')
                    @csrf
                    <div class="form-group">
                        <label for="title">
                            Pavadinimas
                        </label>
                        <input class="form-control" id="productName" name="name" 
value="{{ $product->name }}" type="text">
                        </input>
                    </div>
                    <div class="form-group">
                        <label for="description">
                            Aprašymas
                        </label>
                        <textarea class="form-control" id="productDescription" name="description"  rows="3" value="">{{ $product->description }}
                        </textarea>
                    </div>
                    <div class="form-group">
                        <label for="category">
                            Kategorija
                        </label>
                        <select class="form-control" name="sub_sub_category_id">
                            @foreach($subSubCategories as $category)
                            <option value="{{$category->id}}">
                                {{$category->name}}
                            </option>
                            @endforeach
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="condition">
                            Būklė
                        </label>
                        <select class="form-control" name="condition">
                            <option>
                                Nauja, įpakuota, su etikėtėm
                            </option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="sellType">
                            Parduodu, keičiu, dovanoju
                        </label>
                        <select class="form-control" name="sellType">
                            <option>
                                Parduodu
                            </option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="price">
                            Kaina
                        </label>
                        <input class="form-control" id="productPrice" name="price" value="{{ $product->price }}" type="text"/>
                    </div>
                
                    <button class="btn btn-pink" style="color:white;" type="submit">
                        Atnaujinti informacija
                    </button>
                </form>

Here's the telescope payload

{
_method: "PATCH",
_token: "nHpgUOhYKUobBjeRlKWQ8juaWr4lNv9X3uEGAPGI",
name: "123",
description: "ertwertert",
sub_sub_category_id: "1",
condition: "Nauja, įpakuota, su etikėtėm",
sellType: "Parduodu",
price: "34"
}

and request details

Method  PATCH
Controller Action   App\Http\Controllers\[email protected]
Middleware  web, auth
Path    /product/8
Status  302
Duration    492 ms
Tags    Auth:2
Jul
22
6 months ago
Activity icon

Replied to SQL Cannot Add Forign Key

Check that they both match with the same settings, unsigned, Integer, also check if the engine matches (InnoDB).