robrogers3

Software Engineer at CrowdStar

Experience

84,350

45 Best Reply Awards

  • Member Since 2 Years Ago
  • 930 Lessons Completed
  • 2 Favorites

21st November, 2017

robrogers3 left a reply on Redirecting After Authentication Not Working • 2 hours ago

your english is fine.

so, what's the purpose of the design? what is the use of this different table?

robrogers3 left a reply on Package Development Workflow • 2 hours ago

btw, check out the russian doll caching series on laracasts. he creates a package there and goes through the workflow.

robrogers3 left a reply on Access Constraint Violation • 2 hours ago

share an image of the whoops output.

you are passing null into eloquent somewhere!

question why do you new up a Model?

Just do:

$inspection = $template->replicate();

also when you push your should push the relations.


foreach($template->getRelations() as $relation => $items){
    foreach($items as $item){
        unset($item->id);
        $inspection->{$relation}()->create($item->toArray());
    }
}

i wonder if that's what's happening here?

you are creating a very shallow copy.

robrogers3 left a reply on Laravel Is Not Defined • 3 hours ago

php artisan what?!?!?!

this is js, not php.

use chrome dev tools. to echo out what it thinks window.laravel is.

and can you confirm that the html above is in the header of your sites html.

robrogers3 left a reply on Relationship Help • 3 hours ago

@madsynn

yep. we are inline. I was wondering about that 'no zipcode' thing you had above.

@corban we mostly line up.

and the key is being able to search for a clinic via zipcodes as corban notes.

Location is easy:

class Location
{
  public function clinic()
  {
    return $this->belongsTo(Clinic::class);
  }

  //or see optional
  public function zipcodes()
  {
    return $this->hasMany(Zipcode::class);
  }
}

Zipcode You can leverage hasManyThrough to get the clinics that are in a locations zipcodes.

class Zipcode
{
  public function location()
  {
    return $this->belongsTo(Location::class);
  }

  //A clinic does not have a direct connection to clinics but Eloquent can 
  //Do that work for you via hasManyThrough
  public function clinics()
  {
    return $this->hasManyThrough(Clinic::class, Location::class);
  }

}

as in:

    $zipcodes = Zipcode::with('clinics')->whereIn('zip', [3232,323,3223])->get()->transform(function($zip) {return $zip->clinics;})->all();
    
    

robrogers3 left a reply on Package Development Workflow • 11 hours ago

I actually develop it in a project, then I pull it out.

Having it in the project makes it easier to develop, and write tests.

once you pull it out, just make a separate package and pull it in via composer.

note you can specify a path to the project so it's a symlink which makes it easy to change the package -- inside the project you are working on.

    "repositories": [
    {
            "type": "path",
            "url": "/Users/robrogers/projects/laravel-jsonaware-exception-handler"
    }
    ],

robrogers3 left a reply on Laravel Is Not Defined • 11 hours ago

comment out the window.echo. recompile, and in console. type window.Laravel and then Laravel. see if you find something.

and yeah, make double sure this

    <script>
         // rename myToken as you like
     window.Laravel = {};
         window.Laravel.csrfToken =  {"csrfToken":"diDLWEg9plrt7v33hfJP97b0lcuZACFOMCHU9PU7"}        </script>

is in your header.

robrogers3 left a reply on Access Constraint Violation • 11 hours ago

what line are you getting the error on.

find the line, grab the and do something like: dd($eloquent->method()->toSql());

also is this correct: return $this->belongsToMany(InspectionSection::class, 'inspection_sections', 'inspection_id', 'id');

The third argument is the foreign key name of the model on which you are defining the relationship, while the fourth argument is the foreign key name of the model that you are joining to:

'inspection_id' is the foreign key, and id is the model key? you the joining model key you are referring to is id? normally I'd see something like 'inspection_id', 'foo_id' (id is the primary key, usually)

robrogers3 left a reply on Does Your Vue Do Nothing? • 11 hours ago

so, now vue is fine?

what do you mean by loosing categories?

robrogers3 left a reply on Does Your Vue Do Nothing? • 1 day ago

it's not caching. look at vue dev toolbar. and see what's going on.

it's a must.

robrogers3 left a reply on Understanding Laravel DB::table VS Eqloquent Return Type • 1 day ago

The return type of query builder is:

Illuminate\Database\Query\Builder

Eloquent is a wrapper around Builder (if wrapper is the right word).

In essence, all of the Eloquent::where('foo', 'bar') goes through the Illuminate\Database\Query\Builder to make the queries.

you can check these out in php artisan tinker:

>>> get_class(DB::table('sometable')) //it returns the Query/Builder.

>>> $t = App\Foo::where('id',3); //it returns Illuminate\Database\Eloquent\Builder

>>> get_class($t->getQuery()); //it returns  Query/Builder.

bottom line: if you want to access eloquent's Illuminate\Database\Eloquent\Builder

do $t->getQuery();

but the question is why would you? because you are actually already using it.

like in this example:

App\Thread::where(function ($query) { $query->where('threads.id', '>', 1);})->get();

$query is QueryBuilder

there is an excellent series on this called Advanced Eloquent. Check it out.

20th November, 2017

robrogers3 left a reply on Redirecting After Authentication Not Working • 1 day ago

You know I don't want to sound mean. But why do you and some many other people use terrible names for methods and variables.

What on earth does 'c_user' mean?

I understand if the code is not in english but still???

you note:

how can i change the table for auth?

Unless you are prepared to write a lot of code, using a different table for auth is not wise. (I learned this the hard way).

Then authentication and login process is deeply tied to that table schema. Note you can alter it to have other attributes you may need.

Let me know why you want to use another table? (the purpose)

robrogers3 left a reply on Relationship Help • 1 day ago

Ok.

Some more clarifications:

you say:

so id a person searching for service in their own zip code searches for a clinic in one of the 20 zip codes it will pull up the clinics 3 locations even if it's not in the zip codes with no location attached.

please rewrite this it's very confusing: "even if it's not in the zip codes with no location attached." How can clinic be found if it doesn't have an associated zipcode?

But check this out: i think the formatting screwed this up. The idea is the Clinic services Locations and Locations are comprised (usually) of zipcodes.

CLINIC 1
  Location 1
    Zipcode 1 Zipcode 2
  Location 2
     Zipcode3
  Location 3
     No ZipCode
    
CLINIC 2
  Location 22
    Zipcode 21  Zipcode 22
  Location 23
    Zipcode 23
  Location 24
     No Zipcode

This means, you could say, that a clinic is a SuperSet of Locations, and Locations 'can be' a SuperSet of Locations

Sound about right?

Note: given the idea of searching by zipcodes, if there are no zipcodes associated to a Location which is associated with a clinic. That's weird.

Also one more question: Can a clinic be in more than one Location?

robrogers3 left a reply on Relationship Help • 1 day ago

yeah. humm. I thought I replied to your last reply. weird. cause I had it all written out.

lemme see if I can find it.

robrogers3 left a reply on With() Does Not Work If I Use Where() In Relations • 1 day ago

humm, I can't reproduce this.

what happens if you do a ->where('1', '=', '1')? //always true

also do a dd(Activity::with('custom_fields', 'lead')->where(/some other cond/)->toSql()) and same with getBindings()

robrogers3 left a reply on Method Not Allowed • 1 day ago

usually a method not allowed means your are say doing a post to a route that only handles a get.

I'd double check the form via the chrome dev tools and verify it's a post.

also check the network on submit and see that it's a post.

also, general question why do people use the Form helpers they seem to make things harder to read and don't seem to provide much benefit. it actually seems like there are more characters. than just <form ...>

robrogers3 left a reply on Problem With V-model On Input (read-only) • 1 day ago

ok. so you need to get that value into vue somehow right (at some point)?

well when you need it just grab the value using jquery. or just do $('textarea')[2].value

note there is a slider for vue.

https://github.com/NightCatSama/vue-slider-component

robrogers3 left a reply on Remove PreventDefault Event Listener After Back-end Validation Return True. • 1 day ago

nope. your using it in only one place.

place it at the top or change the @submit to @submit.prevent

robrogers3 left a reply on Problem With V-model On Input (read-only) • 1 day ago

That's right it'. And what's the point. It's read only so it's not reactive.

What are you trying to do. And why jquery?

robrogers3 left a reply on Remove PreventDefault Event Listener After Back-end Validation Return True. • 1 day ago

you forgot the prevent default.

robrogers3 left a reply on Bootstrap Vue Model - [Vue Warn]: Error In Event Handler For "click": "TypeError: Cannot Read Property 'show' Of Undefined" • 1 day ago

Well let's figure out what the $refs are cause that's your problem

Open the Vue Dev tools. Take a look at the Vue instance causing you trouble. Go back to the console and type in vm0.$refs

Let us know what you fine.

19th November, 2017

robrogers3 left a reply on Whoops Error Page Stopped Displaying • 2 days ago

have you changed your Handler.php file in App/Exceptions?

what's your .env file say for APP_DEBUG

it won't show whoops if that is not set to true.

robrogers3 left a reply on WhereHas Relation Returns An Empty Collection • 2 days ago

please mark this as solved!

robrogers3 left a reply on Is There Any Report Generator For Laravel? • 2 days ago

umm, what out put (format) would you like?

also, what's wrong with html? head, footer? and what's number of page mean?

robrogers3 left a reply on Define New Custom Relationship Class • 2 days ago

you want to post your code?

robrogers3 left a reply on Define New Custom Relationship Class • 2 days ago

does flipwhoops or whatever show any information about the Exception. for example it should show:

  • model
  • and the relation name

robrogers3 left a reply on Link_to_route Keep Path • 2 days ago

what is 'if i use host localhost/test/ '

there is no such thing as a host/test that's a uri/url

how/where are defining the host?

robrogers3 left a reply on Getting The Correct Mimetypes When Uploading Files • 2 days ago

well

a) you could be gross and use a regex (nasty)

b) well creating a custom validator is not that bad, then just leverage that class. in your validator.

in 5.5 there is an artisan command to make a rule (for validation) but its' not tricky to do it manually. let me know if you want some boiler plate directions.

ps. really it's not hard at all

robrogers3 left a reply on Create Simple Admin Access (Logic Review) • 2 days ago

I agree with @martinbean. Don't reinvent the wheel. Spend your time working on the features of your site that don't have any 'wheels' yet. That's why laravel and frameworks are made. Spend less time on tooling and more time on features unique to your project.

Trust me you will learn a lot as you start implementing your features.

robrogers3 left a reply on After Refresh Go Back • 2 days ago

the mistake is you don't return a redirect. you directly return a view.

you should do (or something like this).

return redirect('/foo')-> withClients($products);

then in the foo route controller you can access the products via the session.

problem: if the $products data is large, the session is not the best way. let me know if you need help in this case

robrogers3 left a reply on 3 Way Pivot Table Or Complex Relationship • 2 days ago

Well it's time we all defer to @Snapey he's right.

But you need to define the inverse like so:

    public function shipments()
    {
        return $this->shippingTo()->union($this->shippingFrom()->toBase())->union($this->biller()->toBase());
    }

    public function shippingTo()
    {
        return $this->hasMany(Shipment::class, 'shipto_id');
    }

    public function biller()
    {
        return $this->hasMany(Shipment::class, 'biller_id');
    }

    public function shippingFrom()
    {
        return $this->hasMany(Shipment::class, 'shipfrom_id');
    }

@MPRYTHERO notice the first one. it allows you to fetch all shipments as a union.

I think I got this right.

robrogers3 left a reply on 3 Way Pivot Table Or Complex Relationship • 2 days ago

@Snapey thanks got it.

I think the problem is that @MPRYTHERO will need to find all of the customers shipments.

i.e. the reverse of your query.

would we have to define different getters (relations) for each say shipTo (destination), shipFrom (origin) etc. and then how could he union the results

robrogers3 left a reply on 3 Way Pivot Table Or Complex Relationship • 2 days ago

@Snapey got it thanks!

hey you say:

""" and create three columns on the shipments table for the above (or whatever you want to call the columns) """

am I stupid or do those columns need to be on the customer table as the referencing foreign key?

robrogers3 left a reply on 3 Way Pivot Table Or Complex Relationship • 2 days ago

@mprythero

one thing you said is kinda weird:

""" as an addition that a customer can be all three at once (as in origin, destination and biller). """

how is this possible? there is customer who bills himself? (if it's say interdepartmental, then I'd say we are missing something, like department)

also how can a customer be a biller?

Or we missing something? Perhaps a Customer is say 'Your' customer? and they basically could be:

  • a biller, or
  • a destination, or
  • a origin

Where you are tracking 'your Customer' on whether they are one, or 2 or all of these types?

That would change thing a bit, right?

@Snapey

Doesn't your solution restrict say finding ALL of the customer's shipments. i.e.'

For Customer: you wouldn't be able to do:

public function shipments()
{
    $this->hasMany(Shipment::class); //will look for customer_id
}

also, IF a customer can be a biller, you'd need:

public function biller(Customer::class, 'biller_id')
{
    $this->belongsTo(Customer::class, 'biller_id');
}

as a Customer is not just a customer, they could be any one of the 3 or a combination. According to @mprythero

18th November, 2017

robrogers3 left a reply on How To Build This Relationships Tree With Eloquent? • 3 days ago

@hnto is right, let's see a schema and some code.

in the meantime you have 2 things going on here:

  • roles
  • rights (Policies in laravel terms)

Regarding roles: you assign a role to a user, Admin, Editors.

Regarding Policies You will have a policy (rules) for 'authorizing' say managing posts

After you create a PostPolicy (artisan make:policy PostPolicy.)

you will have a method in the PostPolicy::update

it is in here you check the rights of the user who is trying to update the post.

it will look like this;

    public function update(User $user, Post $post)
    {
    //$user is the person currently trying to edit the $post
       //$post is the post they are try to edit
        return $user->id == $post->user_id;
    }


now the above case is simple. it's checking if the $user is the creator of the post.

if the user is not the editor but an Admin , find the posts's editor's Admin. and see if they are the same.

e.g. $user->id == $post->editor->creator->id.

robrogers3 left a reply on Automatic Ajax Request • 3 days ago

FYI, the $(function() {}) is jquery for onload (when the dom is ready to start handling js events - generally)

you don't need jquery to do it. you can register an event for the onload event like so

document.addEventListener("DOMContentLoaded", function() {
  // code... for ajax here you can also check the href for conditionally doing it.
});

robrogers3 left a reply on On Delete Cascade Not Affecting The References • 3 days ago

what database are you using. for example, sqlite doesn't support the cascade feature

robrogers3 left a reply on Reloading Relation Really Necessary After Attach? • 3 days ago

try: $this->assertTrue($box->fresh()->containsProduct($product));

robrogers3 left a reply on Route::middleware • 3 days ago

i means use:

use the 'auth' middleware (so only authenticated users can access the route.

AND

use the 'api' middleware, which defines it as an api route.

so to access the route you must be authenticated AND the url will be

foo.com/api/user

AND

some of the api middlewares will be applied. like throttle.

robrogers3 left a reply on Laravel - How To Validate Sum Of Values To Other Input Value • 3 days ago

where are you going to validate? js or php controller.?

robrogers3 left a reply on How To Return Data Within Job? • 3 days ago

you can but it's weird. (if sync not async)

like this:

register

Event::listen('event.x', function ($eventName, {
    return Post::all();

});

in controller.

$posts = Event::fire('event.x', [1,2]);

return view('welcome', compact($d));

robrogers3 left a reply on 3 Way Pivot Table Or Complex Relationship • 3 days ago

wow, you've had no help on this. but I've also looked at it, I'm a little stumped.

question, can a customer at one time be a biller, and another time a destination?

robrogers3 left a reply on Query On My Model Taking Too Much Time To Finish. • 3 days ago

what @shez1983 says. plus do an explain.

As in Explain select * from foo.

see if it's using indexes.

determine what's the date where clause is about. likes are expensive.

and yeah if AcctStartTime is a DateField then that's a problem.

robrogers3 left a reply on Laravel - How To Validate Sum Of Values To Other Input Value • 3 days ago

we don't want to read your html. show us your controller and validator with the request variables you want to validate.

yikes!

robrogers3 left a reply on Keeping Correct Data On Views • 3 days ago

public function softDelete(User $user)
    {
        //deleting the user contained in it's own instance, soft delete
       $user->delete();
        return view('home', compact('users', 'trashed_users')); //<-- where are these users and trashed users, you need to look them up first and assign them to $users and $trashed_users, 
        //returns the view <-- this view has no $users or $trashedusers

    }

action="/delete/{user}/softDelete"> <-- this needs {{$user->id}}

{user} <-- is just the string which translate to %7Buser%7D e.g. %7B == {

17th November, 2017

robrogers3 left a reply on Validation: Distinct When Nested Array. • 4 days ago

$foo = actually equal to [[''bar' => 2],['bar' => 3]]; so, unless your checking the $foo[0] and $foo[1], of course each inner arrays are unique.

so I'm not sure what you are trying to check.

robrogers3 left a reply on Admin Middleware Not Working In Production • 4 days ago

double check that with a dd($this->auth->user()) see what you get.

robrogers3 left a reply on Event Fire On Logout • 4 days ago

So to clarify

  • a user is logged in
  • the user requests a password reset
  • then immediately logs out?

I wonder how they do that, do you have an extra thingy that allows a logged in user to reset their password?

Anywho, what's your listener look like? post the code?

robrogers3 left a reply on Admin Middleware Not Working In Production • 4 days ago

what happens? the admin users never see the admin navbar?

I assume you have registered the MiddleWare registered.

can you verify your admin user has the correct profile? 99?

robrogers3 left a reply on Wanted To Move Away Values From .env • 4 days ago

try this:

in the AppServiceProvider update the boot method.

public function boot() { // alter .env path app()->useEnvironmentPath(base_path('..')); //or wherever }

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.