6 Best Reply Awards

  • Member Since 4 Years Ago
  • 1033 Lessons Completed
  • 2 Favorites

19th July, 2018

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 • 2 months ago

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.

31st May, 2018

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

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.

29th March, 2018

design-studio left a reply on Return User Model • 5 months ago


20th February, 2018

design-studio left a reply on Give Notification To User When Integrity Constraint Violeted • 7 months ago

you are missing a return statement.

the last line should be

return  Redirect::to('profile_me')->with($notification);

29th January, 2018

design-studio left a reply on Relationships In Existing Project • 7 months ago

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.

28th January, 2018

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

A little more data is required.

24th January, 2018

design-studio left a reply on Current Week • 7 months ago

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.

23rd January, 2018

design-studio left a reply on How Do I Rebind A Singleton ? • 8 months ago

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

14th January, 2018

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

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

11th January, 2018

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

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')

10th January, 2018

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

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));

9th January, 2018

design-studio left a reply on Using Two Methods Of Registration • 8 months ago

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.

3rd January, 2018

design-studio left a reply on I Need Help To Find Out A Solution • 8 months ago

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 :-)

25th December, 2017

design-studio left a reply on Laravel Page And Subpage Schema • 8 months ago

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.

3rd December, 2017

design-studio left a reply on Help With Querying A Model • 9 months ago

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? • 9 months ago

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

26th November, 2017

design-studio left a reply on Order Table Using Another Table • 9 months ago

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()

22nd November, 2017

design-studio left a reply on Check BelongsToMany Before Deleting It • 10 months ago

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

20th November, 2017

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

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

19th November, 2017

design-studio left a reply on Keeping Correct Data On Views • 10 months ago

While sharing variables across views is great (as 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)

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

    // OR redirect to the [email protected], you started with
    return redirect()->route('home.index')
    return redirect()->to('/')

15th November, 2017

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

  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 or maybe in some sub-directory, for example ? if so 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.

14th November, 2017

design-studio left a reply on Poly-polymorpic Relations? • 10 months ago

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:


13th November, 2017

design-studio left a reply on Poly-polymorpic Relations? • 10 months ago

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 • 10 months ago

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 • 10 months ago

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'])
        ->paginate(request()->perPage ? request()->perPage : 15);

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

6th February, 2017

design-studio started a new conversation Visual Studio Code • 1 year ago

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.


Edit Your Profile

Want to change your profile photo? We pull from