Jump to content

fastsol

Moderators
  • Content Count

    803
  • Joined

  • Last visited

  • Days Won

    9

fastsol last won the day on July 26 2015

fastsol had the most liked content!

Community Reputation

39 Good

About fastsol

  • Rank
    Prolific Member
  • Birthday 10/17/1978

Contact Methods

  • Website URL
    http://amecms.com

Profile Information

  • Gender
    Male
  • Location
    Minnesota

Recent Profile Visitors

203,475 profile views
  1. Found it, on the hosting server the Master is listed as 500M but the Local version says 32M. Thank you, I will track down where that is being set.
  2. My local setup is WAMP and I don't know of anything specific that I changed on that setup to allow more than 32M of memory. My local setting is 128M in the ini file.
  3. Any ideas as to where on a system running WHM that I could find such a setting? I already called my host and the only thing they looked at was the ini setting.
  4. Yes I know. This is the blade file code: @extends('layouts.admin') @section('content') @include('layouts.partials.form-errors') <div class="row"> <div class="col-lg-2"> <a href="{{ route('admin.quotes.appointments.phone.create') }}" class="mr-4">Add Install Time</a> </div> <div class="col-lg-2"> <a href="{{ route('admin.quotes.appointments.off') }}" class="mr-4">Take Days Off</a> </div> <div class="col-lg-5"> <form action="{{ route('admin.quotes.appointments.index') }}" method="get" class="form-inline mb-2"> <input type="text" name="date" class="form-control datepicker mb-2" placeholder="Search Date" value="{{ request('date') }}"> <button class="btn btn-primary mt-0 ml-2 mb-2">Search</button> </form> </div> </div> @if($search) {!! alert('warning', 'Currently in Search Mode') !!} @endif @if($appointments->count()) <div id="backtotop">Back To Top</div> <form action="{{ route('admin.quotes.appointments.purchased') }}" method="post" id="mark-as-done"> @include('helpers.previous_page_input_full_url') @csrf <button class="btn btn-primary float-right mb-2">Mark Checked Installs As Done</button> @adminTable(['headings' => ['Date', 'Name', 'Vehicle', 'Product / Notes', 'Actions']]) @foreach($appointments->chunk(5) as $chunks) @foreach($chunks as $appointment) <tr> <td> @php $color = $appointment->install_time->lessThan(\Carbon\Carbon::tomorrow()) ? 'text-danger' : ($appointment->install_time->lessThan(\Carbon\Carbon::tomorrow()->addDay()) ? 'text-primary' : '') @endphp <span class="{{ $color }}">{{ $appointment->install_time->format(config('sitespec.scheduler.install_time_display_format')) }}</span> </td> <td> @if($appointment->deposit) <div class="customer-name"> <a href="{{ searchByUrl($appointment->deposit->quote->customer->name) }}" data-toggle="tooltip" data-placement="bottom" title="{{ $appointment->deposit->quote->customer->phone }}"> {{ $appointment->deposit->quote->customer->name }} @if($appointment->deposit->quote->customer->gift_name) &nbsp;{!! GIFT_ICON !!} @endif </a> <div class="customer-details"> {{ $appointment->deposit->quote->customer->phone }} @if($appointment->deposit->quote->customer->gift_name) <br><br> {{ $appointment->deposit->quote->customer->gift_name }} {!! $appointment->deposit->quote->customer->gift_phone ? '<br>'.$appointment->deposit->quote->customer->gift_phone : '' !!} {!! $appointment->deposit->quote->customer->gift_date ? '<br>'.$appointment->deposit->quote->customer->gift_date->format('m-d-Y') : '' !!} @endif </div> </div> @elseif(optional($appointment->phoneAppointment)->customer) <a href="{{ searchByUrl($appointment->phoneAppointment->customer) }}"> {{ $appointment->phoneAppointment->customer }} </a> @endif </td> <td class="text-center"> @if($appointment->deposit) {{ $appointment->deposit->quote->customer->strippedVehicle }} @if($appointment->deposit->quote->customer->vyear->wires->count()) <a href="{{ route('admin.wires.show', $appointment->deposit->quote->customer->vyear) }}">{!! INFO_ICON !!}</a> @else {!! RED_X !!} @endif @elseif(optional($appointment->phoneAppointment)->vehicle) {{ $appointment->phoneAppointment->vehicle }} @endif </td> <td class="text-center"> @if($appointment->deposit) {{ $appointment->deposit->quote->changedProduct->count() ? $appointment->deposit->quote->changedProduct->first()->name : $appointment->deposit->product->name }} @elseif(optional($appointment->phoneAppointment)->product) {{ $appointment->phoneAppointment->product->name }} @endif {{ $appointment->notes ? ' - '.$appointment->notes : '' }} </td> @php $bg = ($appointment->deposit && !$appointment->deposit->quote->purchased && now() > $appointment->install_time->addHour(2)) ? 'bg-warning' : ''; @endphp <td class="text-center text-md {{ $bg }}"> <a href="{{ $appointment->deposit ? route('admin.quotes.appointments.app.edit', $appointment->deposit) : route('admin.quotes.appointments.phone.edit', $appointment) }}" class="mr-2"> {!! EDIT_ICON !!} </a> @if($appointment->deposit && $appointment->deposit->quote->purchased) {!! CHECK_MARK !!} @else <a href="javascript:void(0)" class="delete_record mr-2" data-url="{{ route('admin.quotes.appointments.destroy', $appointment) }}" data-toggle="modal" data-target="#destroy_confirmation">{!! GARBAGE_ICON !!}</a> @if($appointment->deposit) <div class="custom-control custom-checkbox custom-control-inline"> <input type="checkbox" class="custom-control-input" id="purchased{{ $appointment->id }}" name="purchased[]" value="{{ $appointment->deposit->id }}"> <label class="custom-control-label" for="purchased{{ $appointment->id }}"></label> </div> @endif @endif </td> </tr> @endforeach @endforeach @endadminTable </form> @include('partials.modals.destroy_confirmation') @else {!! alert('warning', 'No Appointments scheduled at this time.') !!} @endif @endsection @section('scripts') <script> $(function () { $('[data-toggle="tooltip"]').tooltip() }); </script> @endsection And this is the query: $appointments = Appointment::with( 'deposit.quote.customer.vmake', 'deposit.quote.customer.vmodel', 'deposit.quote.customer.vyear.wires', 'phoneAppointment.product', 'deposit.product', 'deposit.quote.changedProduct' ) ->where(function($query) use($validator) { return $this->appointmentWhere($query, $validator); }) ->whereNull('cancelled') ->orderBy('install_time') ->get(); As you can see I'm loading a fair number of relationships. The query is in the Controller. The problem comes when it tries to render the blade file. It will get so far in rendering and then error out of memory. I'm using the chunk method but even setting the chunk to 5 or less doesn't solve the problem. I imagine the problem is arrising from trying to access the deep relationship data on so many lines multiple times. I've also tried something like this but it too didn't help. @php $customer = $appointment->deposit->quote->customer; @endphp <div class="customer-name"> <a href="{{ searchByUrl($customer->name) }}" data-toggle="tooltip" data-placement="bottom" title="{{ $customer->phone }}"> {{ $customer->name }} @if($customer->gift_name) &nbsp;{!! GIFT_ICON !!} @endif </a> <div class="customer-details"> {{ $customer->phone }} @if($customer->gift_name) <br><br> {{ $customer->gift_name }} {!! $customer->gift_phone ? '<br>'.$customer->gift_phone : '' !!} {!! $customer->gift_date ? '<br>'.$customer->gift_date->format('m-d-Y') : '' !!} @endif </div> </div> That was to reduce the number of relationship dives to get at the data.
  5. So I have a page that is loading a good amount of models and then looping those in the blade file. The issue I am trying to fix is on my hosting server I keep getting this error Symfony\Component\Debug\Exception\FatalErrorExceptionGET /admin/quotes/appointments Allowed memory size of 33554432 bytes exhausted (tried to allocate 53248 bytes This only happens on my hosting server which is a dedicated server with 8GB of meomry and the php.ini file is set to 500M already. BUT on my local laptop where I only have 128M set in the ini file and run the exact same data on the page it loads just fine. Why is the memory having an issue on my hosting server but not local that is set at a lower limit? I've already tried running the loop with the chunk method but it hasn't helped. I'm not having an N+1 issue either cause debugbar shows the same number of queries ran no matter how big the data set I pull from the db. This is a critical page in my site and it's busy season right now, so this is a very bad thing to have happen. Luckily it only affects one page in the admin area so my customers aren't affected by it.
  6. round was the one thing I didn't try, Thank you! This gives the correct result. $price = '278.53'; $cents = $price * 100; $end_result = (int)round($cents); // Gives me 27853 as expected. also works for 278.59 I knew the issue was a precision thing, I just couldn't find the right combination of functions to make it work. In the end it was so simple (as I figured it would be).
  7. So I am trying to take a string value of dollars (posted from a form) and times it by 100 to get the cents Integer value of the dollars. For some reason if I do this with something like 278.53 I end up with 27852. Same concept for 278.59 ends up as 27858. I don't understand why or how to make it work. I've tried many things and nothing has made it work. $price = '278.53'; // posted from the form $cents = $price * 100; // converting to cents. end_result = (int)$cents // This will end up being 27852 not 27853.
  8. This is the piece of information that made it work how I want in all environments. I now understand that in the boot() it was just adding the scope to the list but not actually running it at that moment. By putting the admin/* in the apply() of the scope itself the request()->path() had been populated and worked as expected in testing also. Thank you so very much, I've been beating my head for a while on this as I kept coming back to it when I'd make a new test that it was affecting. This is what I ended up with: class IsActiveScope implements Scope { /** * @param Builder $builder * @param Model $model * @return Builder|void */ public function apply(Builder $builder, Model $model) { if(!request()->is('admin/*')) { return $builder->where($model->getTable() . '.active', '=', 1); } return $builder; } } And just this in the boot of the model: public static function boot(){ parent::boot(); static::addGlobalScope(new IsActiveScope()); }
  9. It appears that I can set a static method within the unit test itself that does transfer over when doing $this->get(route(''blah));. So I should be able to do the middleware method as you suggested, but then manually set the $enabled to false within the test before using $this-get(). This is a workaround I guess, but it still feels icky since I having to go around the actual code that runs the site normally to make it work just for the test. Maybe it's a compromise I'll have to live with. I had previously tried your last suggestion with the env settings and that made it work in reverse where now the customer side of the code was failing and the admin side was passing because I still couldn't set a true of false value based on a condition, the env value was just set as soon as the test started. I know I'm no where near a "great" coder, especially with Laravel as this is only my second site using it, so many of these little quirks about testing and env are slightly new to me.
  10. Ok so I was wrong, my session method was not working either. I'm starting to see the issue here though. When I run the site normally the middleware is triggered BEFORE the route model binding, but when unit testing the middleware is triggered AFTER the route model binding. I have confirmed this by die dumping in multiple places in the chain to see which gets triggered first. The results are as I stated above, unit testing the model binding is first in the chain which is why no matter what I do here it will likely fail cause I am not able to set any variable/class/anything beforehand to tell the model not to use the scope. Like I said originally, this is only an issue during testing, and really only makes it so I can't test 1 thing on certain models on either the customer side or admin side depending on when the scope is being applied. So maybe I just give up on this and know that that 1 specific test can't be handled through unit testing. I may end up doing Dusk anyway, so it would be tested then correctly.
  11. I've been testing the last 30 minutes by making 2 middleware that uses session() to set the decision to add the scope. Session seems to be the only way to retain the decision throughout the application due to varying class scopes (not the model scope) and such. So far it's working in production and the quick unit tests I ran. I have to do some more testing to ensure it's working as I need, but so far it looks good. Thank you very much, I just needed an idea of how else to set the decision besides the request() and you helped me there.
  12. The way I have it now works great in production, although I do understand it being weird to manage it the way I have. The ONLY time it doesn't work is during unit testing. I like your way of applying it but I don't think it will solve the original issue I posted about. Reason being (primarily) is that when using route model binding, this would still fail to set I believe cause route mode binding appears to apply it's scopes at the route service provider level which is before the middleware level and hence would be too late to NOT apply the scope. Hopefully that made sense. Any other suggestions or maybe I'm wrong, but I feel I'm not after all the testing and messing around trying to make it work for several hours already.
  13. I am having a hard time figuring out a way to set the pathInfo within the request when testing. Here is the scenario: I am adding a global scope to a model in the boot() of that model that is conditional based on the route that given. This works great under normal usage but testing it fails the condition because the pathInfo within the request is only "/". What I don't understand is that AFTER the response is returned from the $this->get() in the test, the request has all the correct data, but it is NOT populated beforehand at the route model binding level. It is populated by the time it hits the middleware, but that is too late to attach or not attach a global scope for a route model binding situation. The page in question is protected behind auth middleware, so the $this->fakeUser(); is simply a quick function to be() a user; Here is the model code: public static function boot(){ parent::boot(); if(!request()->is('admin/*')){ static::addGlobalScope(new IsActiveScope()); } } As you can see the code is just checking if the route is "admin/*", so any admin pages essentially. But not matter what I have tried, the route always comes through as "/" when it hits that piece of code and the route model binding level. If you do a dd(request()); AFTER the $response in the test, the route has been populated at that point and is correct. This is the test: /** @test */ public function see_correct_active_icons_for_each_brand() { $this->fakeUser(); $brand1 = factory(Brand::class)->create(['name' => 'A', 'active' => true]); $brand2 = factory(Brand::class)->create(['name' => 'B', 'active' => false]); $brand3 = factory(Brand::class)->create(['name' => 'C', 'active' => true]); $response = $this->get(route('admin.brands.index')); $response->assertSeeInOrder([$brand1->displayStatus(),$brand2->displayStatus(), $brand3->displayStatus()]); } How can I fake this or is there another way to add the global scope in the manner that works like I have it now? @requinix I see that you know a good amount about Laravel, any insight?
  14. Thank you for the explanation. It's certainly something I've not encountered. This was supposed to be a simple sales tax couple functions that someone found that under certain sets of numbers it was off by 1 cent cause it wasn't rounding up for those instances. I messed around a bit more and got this to work so far and seems to product the correct amounts for a few different values. The functions are identical to what I was running before except I changed the 2nd param of the round() to a 3 instead of 2. Unless you feel this will cause other major issues, I'll probably run with this until I can implement a money type library. // Returns formatted number with sales tax added function addSalesTax($num, $rate) { return number_format(round(($num * $rate), 3), 2); } // Returns just the tax amount function calculateTax($num, $rate) { return number_format(round((($num * $rate) - $num), 3), 2); } $num = 635.00; $num2 = 583.00; $rate = 1.05500; echo addSalesTax($num, $rate); echo '<br>'; echo calculateTax($num, $rate); echo '<br><br>'; echo addSalesTax($num2, $rate); echo '<br>'; echo calculateTax($num2, $rate);
  15. I'm fighting with a very simple round() that isn't giving me the correct output. In the example below the first var_dump shows the value of the calculation performed. The calculation is correct. Next it runs through the round() native function and comes out incorrect. Then I run a round() again but set another var to the same value as the first calculation but by simply setting the number rather than letting php do the math. Then run it through the round() and it comes out to what I expect it should be. So why is the first one not coming out right? $num = 583.00; $rate = 1.05500; $t = (($num * $rate) - $num); var_dump($t); //comes out 32.065 float CORRECT $just_tax = round($t, 2); var_dump($just_tax); //comes out 32.06 float INCORRECT should be 32.07 $t2 = 32.065; //Explicitly set the same value as $t above $just_tax2 = round($t2, 2); var_dump($just_tax2); //comes out 32.07 float CORRECT
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.