design_studio

design_studio

Member Since 5 Years Ago

Experience Points
101,490
Total
Experience

3,510 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
1270
Lessons
Completed
Best Reply Awards
9
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 21
101,490 XP
Mar
26
2 weeks ago
Activity icon

Replied to Eloquent WhereHas Relationship With Constraint On Particular Related Entity

Did you try limiting the amount of items in the books query ?

for example:

return $user->whereHas('books', function (Builder $query) {
	$query->latest()
		->limit(1)
		->where('status', '=', 'deleted');
});
Mar
03
1 month ago
Activity icon

Replied to How To Pass Array From Jquery Ajax To Php

Can you print out the $_REQUEST ?

Also, maybe the problem is the data you are passing? shouldn't it be:

data:{QB:QB, function:'Save_Question'},
Activity icon

Replied to How To Create A Dynamic Model With Laravel ?

What i did in a situation similar what you tried to do, but added some functionality to make it easier for me to interact with it, as follows:

First I created a method for defining the dynamic type of the model (which is an alias for setting the table)

public function setDynamicType($dynamicType)
{
    return $this->setTable($dynamicType);
}

I then added a static ofDynamicType method. This method was the main way to interact with all query related logic the dynamic model. This way i could use it to create new model Assets::ofDynamicType('domain')->create($attributes);

public static function ofDynamicType($dynamicType)
{
    return (new static)->setDynamicType($dynamicType);
}

Also, to make sure that a table was always declared when interacting with the model I override the getTable method. If no table is declared a custom exception is thrown.

public function getTable()
{
    if (!isset($this->table)) {
        throw new MissingTableException('No table is set for the Assets model. table must be set!');
    }

    return parent::getTable();
}

I also added mutator to make it easier to do $assets->dynamic_type = 'domain', in case i need it (never used it though)

public function setDynamicTypeAttribute($dynamicType)
{
    $this->setDynamicType($dynamicType);
}

All this makes things a bit more complicated, so like @sinnbeck said, if you don't have a lot of types you should consider creating a model for every type.

In that case you can make them all inherit from Assets, or use a trait, and in it's constructor set the table dynamically based on the model name, for example

public function __construct(array $attributes = [])
{
    $this->setTable(Str::snake(class_basename(this)));
    parent::__construct($attributes);
}
Mar
01
1 month ago
Activity icon

Awarded Best Reply on Many Products In Many Catalogs On Many Positions

You don't need to add a relationship. You need to use the many-to-many relationship.

First add a column (lets say order_num) in the relationship pivot catalog_product table. The new column will represent the order for a given product in a given catalog.

Next when you update the relationship, so it will retrieve that column when it is retrieving the relationship, as explained in the Retrieving Intermediate Table Columns in the Many to Many section in the docs.

While you are at it you can order it like so (the products method in the Catalog model class):

public function products() {
    return $this->belongsToMany(Product::class)
            ->withPivot( 'order_num')
            ->orderBy('catalog_product.order_num');
Activity icon

Replied to Many Products In Many Catalogs On Many Positions

You don't need to add a relationship. You need to use the many-to-many relationship.

First add a column (lets say order_num) in the relationship pivot catalog_product table. The new column will represent the order for a given product in a given catalog.

Next when you update the relationship, so it will retrieve that column when it is retrieving the relationship, as explained in the Retrieving Intermediate Table Columns in the Many to Many section in the docs.

While you are at it you can order it like so (the products method in the Catalog model class):

public function products() {
    return $this->belongsToMany(Product::class)
            ->withPivot( 'order_num')
            ->orderBy('catalog_product.order_num');
Jan
05
3 months ago
Activity icon

Replied to Dashboard Values From Different Controller.

You are of course correct @nakov. It depends on the project needs.

One can think of a way to create a class that get the required data and using it in the 2 controllers as needed. it depends on the complexity.

Activity icon

Replied to Return Another Blade File Using Ajax

It depends of your needs, but it requires the same logic of: creating a route, that your ajax will interact with, and responding (returning) the view you want to return.

If it is only one specific view, you can d with :

Route::get('ajax-url', function () {
    return view('ajax-view');
});

Of course if this need to be used more extensively, you will need to use a controller, and a more complex logic.

Activity icon

Replied to Dashboard Values From Different Controller.

If you don't mind data being exposed to all views, i find sharing data with all views to be simpler then view composer.

Activity icon

Replied to Determine What Model Loaded Relationship

Can you tell us the relationship of the Car to the Supplier and Manufacturer? Since Both Supplier and Manufacturer have a hasMany relation, i assume the Car is related with belongsTo ?!

Why is it important to know if it was eager loaded ? Once loaded the car should know who loaded it and you could try using the instanceof to find out who is the "owner".

Also, an idea would be to try using the model events (maybe retrieved) to dig in deeper.

Dec
22
3 months ago
Activity icon

Replied to Prevent Sync From Saving Within Saving Event On Eloquent Model

Can you show how and when are you saving the relation?

While returning false does stop the saving, it does not necessary mean that the relationships are not saved (They usually would be saved).

You should try using the database transaction that the framework offer.

Either do it using the saveOrFail method of the model (simplest way), or use the database transaction when you need to in your code (you would use the static::saving to throw an exception).

Dec
16
3 months ago
Activity icon

Awarded Best Reply on When And Why Use Each() Or Map() On A Collection?

While both iterates over the collection (and you can achieve the same results in both) there intention are not the same.

Use theeach iteration to loop over the collection and run a callback with each item.

use the map iteration to create a new collection, and use that new collection (maybe somewhere else in the application).

Activity icon

Replied to When And Why Use Each() Or Map() On A Collection?

While both iterates over the collection (and you can achieve the same results in both) there intention are not the same.

Use theeach iteration to loop over the collection and run a callback with each item.

use the map iteration to create a new collection, and use that new collection (maybe somewhere else in the application).

Dec
15
3 months ago
Activity icon

Replied to Auto Resolution With Service Providers As Singleton Not Working

Is your service provider registered in config/app.php ?

Or are you using Laravel AppServiceProvider ?

Activity icon

Replied to Provide API-Client To Controller

You can also try using a Form Request.

While the documentation of form request explain hot to use the form request for validation, you can use it and instantiate it in the controller method.

This as the advantage of being a request so all request methods an properties are available, and you can use it to validate and/or authorize.

Then you can add functionality to the Form Request class you create to be used by the controller.

Dec
12
3 months ago
Activity icon

Replied to PDF File Are Not Open In Browser. On Click It Directly Download.

This is a browser issue, and not coding issue. You can see an explanation from this simple search results link

for example' in chrome:

  • On your computer, open Chrome.
  • At the top right, click More Settings.
  • At the bottom, click Show advanced settings.
  • Under Privacy, click Content settings.
  • Under PDF Documents," check the box next to "Open PDF files in the default PDF viewer application.
  • (Uncheck this box if you want PDFs to open automatically when you click them.)
Activity icon

Replied to How To Get All Orders Of Customers Assigned To A Specific Agent Using Query Builder

You are right. I think it could actually work with whereHas. Like this:

App\Order::whereHas('customers', function (Builder $query) {
    $query->where('agent_id', Auth::id());
})
->whereHas('customers.tags', function (Builder $query) {
    $query->where('id', 243)->whereNotIn('id', [3343, 445, 333]);
})
->whereHas('products', function (Builder $query) {
    $query->whereIn('id', [18, 33, 29]);
})
->get();

I am not sure this will result in what you want since i think this will not give you customers without tags at all. for that maybe you need to add statement that adds customers with no tags at all.

May be like this:

App\Order::whereHas('customers', function (Builder $query) {
    $query->where('agent_id', Auth::id());
})
->whereHas('customers.tags', function (Builder $query) {
    $query->where('id', 243)->whereNotIn('id', [3343, 445, 333]);
})
->doesntHave('customers.tags', 'or')
->whereHas('products', function (Builder $query) {
    $query->whereIn('id', [18, 33, 29]);
})
->get();
Dec
11
3 months ago
Activity icon

Replied to Eager Loading On Polymorphic Relationships

Sounds like you need to query a polymorphic relationship existence, like in the Querying Polymorphic Relationships documentation

Try (to get all directors):

$users = App\Modules\User\Models\User::whereHasMorph(
    'child',
    [App\Modules\User\Models\Director::class]);
Activity icon

Replied to How To Get All Orders Of Customers Assigned To A Specific Agent Using Query Builder

Can you try the following (It is not test, since i haven't got the code):

App\Order::whereHas('customers', function (Builder $query) {
    $query->where('agent_id', Auth::id());
})
->whereHas('customers.tags', function (Builder $query) {
    $query->where('id', 243);
})
->whereDoesntHave('customers.tags', function (Builder $query) {
    $query->whereNotIn('id', [3343, 445, 333]);
})
->whereHas('products', function (Builder $query) {
    $query->whereIn('id', [18, 33, 29]);
})
->get();
Dec
10
3 months ago
Activity icon

Replied to Eager Loading On Polymorphic Relationships

Like @mthomas said, a look at your models and relationships methods would help a lot.

Until then:

Are Responsible , Director, Admin are child ? (meaning the name of the relationship method is child ?)

You should try looking at Querying Relationship Existence

Activity icon

Replied to Avoiding Duplicates In A Many To Many Relationship With The Same Table

While it is not exactly what you asked for, i would like to offer 2 options / suggestions.

-1-

While having duplicates is not a good thing, if you don't anticipate a lot of data it is not a big downside.

-2-

Maybe try to change the logic: add a "family" of sort. It can be done either by simply adding a family attribute to the Kidor Add a Family model and add relationships for the family and kid.

This can be utilize to manage other common data of the siblings, if you have any.

Activity icon

Awarded Best Reply on Problem With Editing Dropdown Values , Please Check My Code Where I Going Wrong

In the controller you should select only the head offices related to the selected city.

In the edit method after you retrieved the city you should

$HeadOffice = HeadOffice::where("city_id", $city)->get();
Dec
09
4 months ago
Activity icon

Replied to Problem With Editing Dropdown Values , Please Check My Code Where I Going Wrong

In the controller you should select only the head offices related to the selected city.

In the edit method after you retrieved the city you should

$HeadOffice = HeadOffice::where("city_id", $city)->get();
Activity icon

Replied to Problem With Editing Dropdown Values , Please Check My Code Where I Going Wrong

Your problem is the result of 2 things i can see:

First: In the edit file, in the head office select you have selected set on the if and on the else

@if($br->head_office_id == $DistributorOtherInfos->dist_company_ho)
    <option value="{{$br->head_office_id}}" selected>{{$br->head_office_name}}</option>
@else
    <option value="{{$br->head_office_id}}" selected>{{$br->head_office_name}}</option>
@endif

Second: The other issue is that the controller brings all the head offices, and not only those related to the selected city.

Dec
04
4 months ago
Activity icon

Replied to Function Store(Request $request)

Not clear enough what data you get and what you are tying to do. If you are trying to save an album_id data, did you update the $fillable of the model ?

Take a look at mass assignment in laravel docs.

Activity icon

Replied to Where Are You All From?

Givatayim , Israel

Dec
03
4 months ago
Activity icon

Replied to Using GroupBy() On Table Relations

It seems to me that something is a bit off...

If you are grouping and then paginating, that is a lot of extra costs.

You can have a look at Pagination with Group By

Activity icon

Replied to Accessing A Users MorphMany Relationship

I think some data is missing.

Can you give more details on the relationship of the Snippet and the posts and comments? Do Post and Comment inherit from Snippet ? Are the related to it ?

And what is the relationship between them and the user ?

Activity icon

Replied to Using GroupBy() On Table Relations

Can you explain why you need to group them by place_name? Like @bobbybouwmann said, if you'd group them like that you will lose data of places.

Nov
27
4 months ago
Activity icon

Replied to Laravel Blade View

If it worked, please mark as best reply. tnx.

Nov
26
4 months ago
Activity icon

Replied to Laravel Blade View

I think You are writing an invalid html, and that cause the problem.

You need to put the inner (subjects table) inside a tr and td tags.

I added comments near the new html:

<table class="table table-borderless table-hover">
    <thead>
        <tr>
            <th>&nbsp;</th>
            <th scope="col">student.Id</th>
            .............
        </tr>
    </thead>
    <tbody>
    @foreach($data as $student)
        <tr class="clickable" data-toggle="collapse" id="row{{ $student['id'] }}" data-target=".row{{ $student['id'] }}">
            <td>{{ $student['id'] }}</td>
        </tr>
        @if ($student['subjects'])
            <tr> <!-- <= new wrapping row -->
                <td> <!-- <= new wrapping column  -->
                    <table class="table table-sm table-dark collapse row{{ $student['id'] }}">
                        <thead>
                            <tr>
                                <th scope="col">subject.Id</th>
                                    ..............
                            </tr>
                        </thead>
                        <tbody>
                        @foreach($student['subjects'] as $subject)
                            <tr>
                                <td>{{$subject['id']}}</td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                </td> <!-- <= end new column -->
            </tr> <!-- <= end new row -->
        @endif
    @endforeach
    </tbody>
</table>

Personally I would not use table, but that is another thing.