design-studio

design-studio

Member Since 4 Years Ago

Experience Points 79,440
Experience
Level
Lessons Completed 1072
Lessons
Completed
Best Reply Awards 6
Best Answer
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.

19 Jul
4 months ago

design-studio left a reply on DB Design Help =>driver Can Own One Car And Supplier Can Own More Than One Car , How To Design This

As far as database goes it seems like a classic polymorphic relationship. Check out the Polymorphic Relations docs.

In your case you need to replace the posts with driver, videos with supplier and comments with cars.

31 May
6 months ago

design-studio left a reply on Where Auth Routes -route::auth()- Get Connected To Guest Middleware?

if you look at the the controllers used buy this method, which are all the controllers in app/Http/Controllers/Auth you will see the answer you are looking for. The middleware are registered in each controller __construct method.

29 Mar
8 months ago
20 Feb
9 months ago

design-studio left a reply on Give Notification To User When Integrity Constraint Violeted

you are missing a return statement.

the last line should be

return  Redirect::to('profile_me')->with($notification);
29 Jan
10 months ago

design-studio left a reply on Relationships In Existing Project

I think that there is a mix-up in what you are trying to do. You said the B is a pivot Table, but your explanation does not match. If B is indeed a pivot table it can be simplified.

A has the following:

public function C()
{
    return $this->belongsToMany(C::class)->latest();
}

C will have the following:

public function A()
{
    return $this->belongsToMany(A::class)->latest();
}

You don't even need to create the B Class (although you can if you need to add functionality to it).

If you need to get more data from the pivot table take a look at the 'Retrieving Intermediate Table Columns' section in the many-to-many documentation.

28 Jan
10 months ago

design-studio left a reply on I Can't Delete The Thread :/

A little more data is required.

24 Jan
10 months ago

design-studio left a reply on Current Week

You could do something like this:

public function getCurrentWeekRecords() {
    $now = \Carbon\Carbon::now();
    $weekStart = $now->subDays($now->dayOfWeek)->setTime(0, 0);
    return \App\Model::where('created_at', '>=', $weekStart)->get();
}

This would get you a collection of App\Models that were created in the past week.

23 Jan
10 months ago

design-studio left a reply on How Do I Rebind A Singleton ?

I am have not used laravel/passport before, but if you would like to try the first option you shuold extend the passport service provider Laravel\Passport\PassportServiceProvider. There you can override the methods you want, be it registerAuthorizationServer or makeAuthorizationServer.

Don't forget to register your service provider instead of Laravel\Passport\PassportServiceProvider

14 Jan
10 months ago

design-studio left a reply on Undefined Property: PHPExcel::officename (View: /var/www/html/test/resources/views/view.blade.php)

Glad I could help. Please mark one of my responses as best reply, if you find it so.

11 Jan
11 months ago

design-studio left a reply on Undefined Property: PHPExcel::officename (View: /var/www/html/test/resources/views/view.blade.php)

You should check the returned $results class. I think it is a collection of rows or sheet (that extends laravel's collection).

Try to dump the variable (dd($result)) or its class (get_class($result)) to know it's type and how to continue.

If it is a collection of rows or sheets you need to drill to the row and then get the row data.

The row is also a collection so you'll need to use collection methods to retrieve data from it: $results->get('officename')

10 Jan
11 months ago

design-studio left a reply on Undefined Property: PHPExcel::officename (View: /var/www/html/test/resources/views/view.blade.php)

What Error are you getting ?

I think the error might be related to the $data variable. I think you need to pass the $data down the functions:

Another error I see here is that on the code that you show here, there is an unnecessary } at the end.

Try this:

\Excel::load('/storage/app/sample.xls', function($excel) use ($data) {

    $excel->sheet('sample', function($sheet) use ($data) {
        $sheet->loadView('view',array('data' => $data));
        $sheet->setOrientation('landscape');
    });
        
})->export('xls');
  
09 Jan
11 months ago

design-studio left a reply on Using Two Methods Of Registration

I think I would go about it a bit differently.

I would use the standard Auth() method to register, and set a default role. Then I would add a setRole or addRole method (depending on whether a user can have many roles) on the User model. The functions will be called as you wanted from the admin side of the application.

03 Jan
11 months ago

design-studio left a reply on I Need Help To Find Out A Solution

This fits exacly a Polymorphic Relationship.

In polymorphic relationship the parent model (Location in your case) has a relationship that allow connecting to different models while saving does models (Admin and Agent in your case) classes and their id.

You might need to make some changes thought. I think this should work:

On your location table you need to change the columns to added_by_type and added_by_id.

Now in your Location model you can use this method:

public function added_by() {
    return $this->morphTo()
}

On your Admin and Agent models you can use this methods to get the locations:

public function locations() {
    return $this->morphMany(App\Location::class, 'added_by');
}

You can use different names, but you'll need to dive into the code to know what extra parameters you'll need to use.

Hope i didn't make any mistakes, since I just wrote the code here :-)

25 Dec
11 months ago

design-studio left a reply on Laravel Page And Subpage Schema

I think That you should choose from either option A or B. Option C to me seems complex considering the other 2 and Option D to me is not worth considering.

For both options A and B don't forget to use either trait or hierarchy.

I would go with option A, since I think this would be the simplest to manage, although option B might be faster performance wise (I am not a performance guy).

My last suggestion, and could be the most important one is to checkout the MorphOne Class. It is not a documented Class but dive into it's code, try and use it to see if it fits your need. From what i saw (and it can be guessed by the name) its result is not a Collection but rather a Model.

It would be great if you let us know what was you choice in the end, and why.

03 Dec
1 year ago

design-studio left a reply on Help With Querying A Model

The ->get() method returns an Eloquent Collection. if you are unfamiliar it is kind and array which is a multi result of the query you created (see the docs). In you case it will bring all App\Sb model that matches the given $token, even if there is only one model matching that.

The ->first() method returns the first model of that matches the given $token. It would in fact be the first model in the collection from the ->get method. From the model you can get whatever data you need.

You need to use the right method for any given situation. The show method is a classic place to use the ->first() method.

design-studio left a reply on 3 Category Tables With Same Structure, How To Manager Them With One Controller, Model, And View Etc At Admin?

Not sure what you mean exactly since you didn't gave much data on what exactly yon need help with, but it looks like what you need is a Polymorphic relationship. Check the docs to see if this is what you wanted

26 Nov
1 year ago

design-studio left a reply on Order Table Using Another Table

You should take a look at the counting-related-models docs You need to query the thread with the posts count, and then use that to sort by.

Assuming the relationship method in the Thread class is posts:

$threads = Thread::withCount('posts')->orderBy('posts_count')->get()

Of course if you use the post data in this request, you should also eager load them:

$threads = Thread::withCount('posts')->with('posts')->orderBy('posts_count')->get()
22 Nov
1 year ago

design-studio left a reply on Check BelongsToMany Before Deleting It

I would use events for this. I would use the deleting event to check if the model can be deleted, and stop the event if necessary.

see model events in the docs

20 Nov
1 year ago

design-studio left a reply on How To Dynamically Set Hidden Attribute, When Passing Model Data To Vue Components?

You said:

I tried to limit the passed data by using the $hidden-attribute on the model, but this doesn't work in all use cases. What does it mean ? what cases ? It should work for all attributes, including relationships.

You can also user the opposite $visible property or hiding/showing them at runtime. See: 'hiding-attributes-from-json' in the doc

19 Nov
1 year ago

design-studio left a reply on Keeping Correct Data On Views

While sharing variables across views is great (as @rumm.an explained), I think in the case you presented here I would rather delete the user and redirect either back or to the index, and let the index method deal with getting the users.

 public function softDelete(User $user)
 {
    $user->delete();

    // redirect back
    return redirect()->back();

    // OR redirect to the [email protected]ndex, you started with
    return redirect()->route('home.index')
    return redirect()->to('/')
}
15 Nov
1 year ago

design-studio left a reply on How Can I Solve This 404 Not Found Error Even When Route Exist

  1. You said your route list results in: POST | mappy | location | App\Http\Cont rollers\[email protected] | web,auth there is space in the middle of the word Cont rollers. I assume it is a mistake done when pasting the text here, but check it out.
  2. Are you running the command in the http://127.0.0.1:8000 or maybe in some sub-directory, for example http://127.0.0.1:8000/my_test_app/ ? if so @@rumm.an js points to the wrong url and it won't work, and you'll have to create the url in the js using laravel, like you tried.
14 Nov
1 year ago

design-studio left a reply on Poly-polymorpic Relations?

That looks OK to me. The pricesWhereType method, just like the prices doesn't return a collection. It returns a Illuminate\Database\Eloquent\Relations\MorphMany relation object. This objects delegates some methods to a \Illuminate\Database\Eloquent\Builder so you can use all the Builder methods to get what ever results you want. for example, to get all related retail prices use:

$product->pricesWhereType('retail')->get();
13 Nov
1 year ago

design-studio left a reply on Poly-polymorpic Relations?

I think you should have a Price model, (with prices table) that will have fields for the price value and the price type, priceable_id and priceble_type. The type field will represent the different type possible (retail, advisory, sales etc.. ) Then all objects that needs to have prices will use a trait that will have methods to get the related prices models, and related prices models by type:

trait HasPrices {

    /**
     * All related prices
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function prices() {
        return $this->morphMany(\App\Price::class, 'priceable');
    }

    /**
     * Related prices by type
     *
     * @param string $type
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function pricesWhereType($type) {
        return $this->prices()->where('type', $type);
    }

}

You can even define scope on the Price model and use in the traitto make it more readable.

Does that work ?

design-studio left a reply on Dynamic Routes

I think you have an exclamation mark where there shoudn't be one. That is it should be if($community) instead of if(!$community)

design-studio left a reply on Laravel Eloquent Order Posts By Created_at And Keep Sticky Post On Top

You can chain 2 orderBymethods. first order by sticky_post then order by created_at. So it will look like this:

public function index(PostFilter $filter)
{
    return Post::with(['author', 'category', 'tags'])
    ->orderBy('sticky_post')
    ->orderBy('created_at')
        ->withTrashed()
        ->filter($filter)
        ->paginate(request()->perPage ? request()->perPage : 15);
}

note: you can also use the latest method. check the docs for Ordering, Grouping, Limit, & Offset

06 Feb
1 year ago

design-studio started a new conversation Visual Studio Code

Hi Jeffrey. I was wondering if you tried the "Visual Studio Code"? What's your take on it? Also, if you liked it, and since I like simple concise way you explain things, I was wondering if you could give a run of your preferred setup for this editor.

Tnx.