himala

himala

Member Since 2 Weeks Ago

Experience Points
560
Total
Experience

4,440 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
2
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.

Level 1
560 XP
May
22
1 week ago
Activity icon

Replied to Can Someone Please Help Me Why This Is Not Working????? Laravel Blade

Me too, I changed the code to this:

              foreach($lines as $key => $line)
            {
               if(array_key_exists($key, $matches) && !empty($matches[$key]))
                   {
			echo $line;
              	    }
             }

and it worked

Activity icon

Replied to Can Someone Please Help Me Why This Is Not Working????? Laravel Blade

I tried using for loop

                                                    for($i = 0; $i < count($matches); $i++)
                                                    {
							echo $i; // outputs 01234
                                                        // echo $lines[$i];
                                                    }

But still shows undefined offset:5 this is dd($lines):

array:5 [▼
  0 => "all purpose"
  1 => "baking pan"
  2 => "chocolate chips"
  3 => "nuts"
  4 => "raisins"
]

count($matches) is 5

Activity icon

Replied to Can Someone Please Help Me Why This Is Not Working????? Laravel Blade

Please help I don't know what to do :(

Activity icon

Started a new Conversation Can Someone Please Help Me Why This Is Not Working????? Laravel Blade

<?php
  foreach($store->product as $product)
{
        $product_names[] = $product->name;
 }

     foreach($lines as $line)
     {
        	$matches[] = array_filter($product_names, function($var) use ($line) { return preg_match("/\b$line\b/i", $var); });
       }

	?>

@foreach ($matches as $key=>$value)
 	{{ $lines[$key] }}
@endforeach
 {{ dd($matches, $lines) }}

dd($matches):

array:5 [▼
  0 => array:1 [▶]
  1 => array:1 [▶]
  2 => array:1 [▶]
  3 => []
  4 => array:1 [▶]
]

dd($lines):

array:5 [▼
  0 => "all purpose"
  1 => "baking pan"
  2 => "chocolate chips"
  3 => "nuts"
  4 => "raisins"
]

When I remove the {{ dd($matches, $lines) }} it crashes and shows Undefined offset: 5 error. Please help :((

May
20
1 week ago
Activity icon

Started a new Conversation How To Access An Attribute Inside A Collection

Can someone please explain to me how I can access the product name?

I have the results array and this is whats inside when i dd($result)

array:6 [▼
  0 => null
  1 => Illuminate\Database\Eloquent\Collection {#1281 ▼
    #items: array:2 [▼
      0 => App\Product {#1282 ▼
        #guarded: []
        #connection: "mysql"
        #table: "products"
        #primaryKey: "id"
        #keyType: "int"
        +incrementing: true
        #with: []
        #withCount: []
        #perPage: 15
        +exists: true
        +wasRecentlyCreated: false
        #attributes: array:7 [▼
          "id" => 1
          "store_id" => 1
          "category_id" => 1
          "name" => "All Purpose Flour"
          "price" => 199.0
          "created_at" => "2020-05-19 22:47:30"
          "updated_at" => "2020-05-19 22:47:30"
        ]

Thanks in advance!

Activity icon

Replied to How To Search For An Item With Relationships (SOLVED)

I tried to do that but it produces an error maybe because I have 'branch' function in my products that returns hasMany BranchInventory::class

which has the branch_id

and my BranchInventory has 'branch' function that returns hasMany 'Branch::class' so i can compare them with

branch_id from BranchInventory an the id from the Branch table. My naming convention is wrong

Activity icon

Replied to How To Search For An Item With Relationships (SOLVED)

Thank you so much!! I've been trying to figure this out for about 6 hours now. Thanks again!

Activity icon

Replied to How To Search For An Item With Relationships (SOLVED)

THANK YOU! But am i doing this right?

    $city = 'Manila';
    foreach ($arr as $line) {
        $products[] = \App\Product::where('name', 'LIKE', '%' . $line . '%')
            ->whereHas('branch', function ($query) use ($city) {
                $query->whereHas('branch', function ($query) use ($city) {
                    $query->where('city', $city);
                });
            })
            ->get();
    }
Activity icon

Replied to How To Search For An Item With Relationships (SOLVED)

I want to use branchesInventory branch_id and product_id to connect with branches table

Activity icon

Replied to How To Search For An Item With Relationships (SOLVED)

Product.php

class Product extends Model { protected $guarded = []; public function store() { return $this->belongsTo(Store::class); }

public function category()
{
    return $this->belongsTo(Category::class);
}

public function branch()
{
    return $this->hasMany(BranchInventory::class);
}

}

Branch.php

class Branch extends Model { protected $guarded = [];

public function store()
{
    return $this->belongsTo(Store::class);
}

public function branchInventory()
{
    return $this->hasMany(BranchInventory::class);
}

}

BranchInventory.php

class BranchInventory extends Model { protected $guarded = [];

public function branch()
{
    return $this->belongsTo(Branch::class);
}

public function product()
{
    return $this->belongsTo(Product::class);
}

}

Activity icon

Started a new Conversation How To Search For An Item With Relationships (SOLVED)

I have Products, BranchInventories, and Branch models with hasMany relationships

My Product table has id, and name

and my BranchInventory table has product_id, branch_id

and my Branch table has city, and address

What I want to do is a search item, for example:

the search item is 'All Purpose Flour' and city is 'Manila'

Search for App\Product::where('name', 'LIKE', '%all purpose flour%') AND branch('city', 'Manila') ->get()

Can you please help me? I hope you can understand my question. Thanks in advance

May
19
2 weeks ago
Activity icon

Started a new Conversation How To Add An Exception To Unique Laravel Rule Validation

Hi guys, I have a validation that goes like this

My user can create many categories for his/her product and my categories table looks like this

id user_id name created_at updated_at

CategoryController.php

// Creates category

public function create() { $data = request()->validate([ 'name' => 'required|unique for that user_id ]); }

What I want to happen is it checks if there's an existing category_name under that user_id

Can you help me please? Thanks in advance!

May
14
2 weeks ago
Activity icon

Replied to Which Ones Better When Storing Data? Laravel

Thanks for the reply!

Activity icon

Started a new Conversation Which Ones Better When Storing Data? Laravel

Hi guys i'm a complete beginner in laravel and i'm a bit confused when using relationships. Can you tell me which one is better when storing a comment on a post with the logged in user id? 1.

    $data = request()->validate([
        'comment' => 'required',
        'post_id' => 'required'
    ]);
    $comment = auth()->user()->comments()->create($data);

or this one:

    $data = request()->validate([
        'comment' => 'required',
    ]);
    $data['user_id'] = auth()->user()->id;

    $comment = $post->comments()->create($data);

They do the same thing but i just wanna know which one is better. Thanks in advance!!