286 Best Reply Awards

  • Member Since 1 Year Ago
  • 625 Lessons Completed
  • 2 Favorites

24th March, 2017

ohffs left a reply on Can Someone Point Me In The Right Direction? • 10 hours ago

It's hard to be very helpful without knowing what all those variables are and what happens after - but you could at least tidy things up a bit by having things like :

// your main function above


public function createImages($fromFile)

public function createLoopImage($fromFile)
    $this->makeImage($this->loopWidth, $this->loopHeight, $fromFile)
         ->save($this->LoopPath . $fromFile->getClientOriginalName());

public function makeImage($width, $height, $original)
    return Image::make($original)->resize($width, $height, function ($constraint) {

23rd March, 2017

ohffs left a reply on Can I Run Laravel Dusk On My Forge Server? • 1 day ago

You should be able to hook something up with xvfb.

ohffs left a reply on Extract Zip File And Select Png Files • 1 day ago

You can use the built-in PHP zip features - see the manual : http://php.net/manual/en/zip.examples.php .

21st March, 2017

ohffs started a new conversation Trick 'Next Video' Link At The End Of The Last Video In An Updating Series • 3 days ago

Ah, that title feels like a test method name I'd frown at ;-)

Anyway - recently-ish when I watch the last video in a series (like the current forum one) once it finishes it pops up the alert saying the 'Click for next video' kinda thing. And I think 'ah-ha! a new video was added while I was watching - sweet!'. Then click it and it shows a 'nuh-uh - come back in X hours' page and I think 'boo! tricked again!' ;-)

I'm quite used to being foiled by computers, so not a biggie by any means :-) But one of these minor niggles that I scowl at from time to time ;-)

ohffs left a reply on Reference In Seeders • 3 days ago

I think you're possibly trying to map an data-mapper mindset onto an active-record one? :-) Although one way I think you could achieve what you're after is by binding (in this case) a user model into the IoC container? Not quite sure if this would do what you want :

// SeederOne
$this->container->instance('seederUser', $yourSpecificUser);
.. do whatever

// SeederTwo
$user = $this->container->make('seederUser');

Maybe... ;-) Or extend the base Seeder class with your own reference/getter/setters as needed maybe?

ohffs left a reply on Reference In Seeders • 3 days ago

I don't think there's anything quite like the fixtures in the terms you're describing. What is it you're trying to end up with at the end?

ohffs left a reply on Stupid Question, Is There A Company Behind Laravel? • 3 days ago

At the moment it's a open source package largely controlled by Taylor. The various paid-for services he runs like forge, spark and his new patreon offer let him work on the framework pretty much full-time.

Possibly in time there will be some kind of 'laravel foundation' or something. But remember that laravel is only ~5yrs old from inception. Symfony is ~10yrs and Django is a bit more than that.

But we'll see I guess :-)

ohffs left a reply on Is There A Deprecation Policy? • 3 days ago

Sometimes things are marked as deprecated for a specific release (i.e., L5.2 says it will deprecate feature X in 5.3). Sometimes things just disappear without being marked as deprecated though - so ymmv ;-)

20th March, 2017

ohffs left a reply on Cpanel • 4 days ago

What was it set to before? A common setting is '022' - but you are probably better asking the hosting co to set it back to the default...

ohffs started a new conversation Non-existent Columns In Sqlite • 4 days ago

I was re-factoring some code and all my tests against sqlite were passing - 'oh good!'... I thought. Then ran the code against mysql and it blew up.

Turns out in sqlite if you do :

select non-existing-column from table;

It gives an error, but if you do :

select "non-existing-column" from table;

It doesn't. Which is... interesting ;-). In my case it was an 'orderby' clause which was still running against a column which had been renamed - sqlite just went 'yeah, sure, whatever' - mysql wasn't so happy though.

Eloquent (possibly PDO itself, not sure) wraps the field names in quotes, so you will not get the error back from sqlite.

Anyway - wasn't sure if anyone else had come across this and there was a work-around. I know sqlite is pretty forgiving of most things - but the quoted-vs-not-quoted was a new one on me!

18th March, 2017

ohffs left a reply on How To Convert/Import Excel To SQL • 6 days ago

Yeah - spreadsheets are evil :-/ Down the years I've had to do a lot of 'guesses' for fields - so maybe test for a date that could be :


11 30 1990

30th Nov 1990

30 November 1990

Nov 30th, 1990

Friday 1990/Nov 30th

On and on :-/

I used to just have a big series of if (preg_match(style1.... if (preg_match(style2.... etc. But more recently I've been doing a try { Carbon::parse($field) catch (... and only if Carbon can't parse it I fall back to manual. Carbon catches about 90% of the cases so there's less to do manually and you can usually fix those up by hand.

But yeah - it's a pain. Embedded tabs, control characters, hidden formatting - all really, really unpleasant to deal with :-/

ohffs left a reply on Laracasts SVG • 6 days ago

I saw heroicons getting a few plugs online.

I think they are smaller than embedded images - with the bonus of being able to style them with css, resize them etc. So (ideally!) you just include one svg file and if you want it in red, double the size on one page, but 1/4 the size on another, extra-bold on another - you don't need to generate a load of different versions of the image.

ohffs left a reply on How To Convert/Import Excel To SQL • 6 days ago

If you use something like phpexcel or spout it can read an xls(x) file in and spit out the data in any format you want to make. Both of those also understand if a column in excel is formatted as a date and will turn it into a datetime object for you.

But if the data is in a fairly random free-format style (as is often the case with spreadsheets - don't get me started or I'll be here all day) then you're probably going to have to do some work transforming it with various tests/regex etc.

ohffs left a reply on What Do I Need To Do For A Refund All My Money In Laracast Yearly Subscription? • 6 days ago

You're probably better asking via the site's support page than posting on the forum...

16th March, 2017

ohffs left a reply on Populating A <select> Tag With The Next 6 Months Using Carbon • 1 week ago

Something along the lines of :

$dates = [];
foreach (range(0, 5) as $offset) {
    $dates[] = Carbon::now()->addMonths($offset);


<select name="month">
    @foreach ($dates as $date)
        <option value="{{ $date->month }}">{{ $date->month }}</option>

14th March, 2017

ohffs left a reply on Tell Browser To Cache • 1 week ago

You could have a look into etags.

ohffs left a reply on Artisan Always Adds '<?php' • 1 week ago

Somewhere under app/Console? If you've added any commands or fiddled with the Kernel.php file?

13th March, 2017

ohffs left a reply on Db Transaction: What If Server Crashes In The Middle Of A Transaction ? • 1 week ago

The exact mechanism varies from db-server to db-server. You'd have to do some pretty thorough research if you want to know the exact details. I'm happy enough to leave it in 'magic I don't really have to understand' section of my brain ;-)

ohffs left a reply on Export Large Excel/CSV (10-20K Records) • 1 week ago

Maybe try spout - it's a lot lighter than the php excel. It doesn't do everything that php excel does, but for straight xls it's pretty fast.

12th March, 2017

ohffs left a reply on Handle Recurring Tasks Monthly On The 30/31 • 1 week ago

I think you'll need to have it run the confirmation box when the user submits the form, rather than after. You'll have to do a bit of reading up on sweetalert - or try searching on here - lots of people have asked similar questions.

ohffs left a reply on Db Transaction: What If Server Crashes In The Middle Of A Transaction ? • 1 week ago

If it makes it clearer - you can think of a transaction as writing to a copy of the table - only when you 'commit' the changes are written back to the original. So you can get the last inserted id within the transaction - but if it fails then the copy is discarded and the original is left as if nothing had happened.

ohffs left a reply on Db Transaction: What If Server Crashes In The Middle Of A Transaction ? • 1 week ago

The inserts would only happen at the commit line - so nothing should happen in this case.

ohffs left a reply on Handle Recurring Tasks Monthly On The 30/31 • 1 week ago

It's a function - so you need to call it by doing something like $task->nextTaskDay('2017-03-31'), which should (in theory) give you back a carbon date object of '2017-04-30' as the next month (april) only has 30 days.

11th March, 2017

ohffs left a reply on Handle Recurring Tasks Monthly On The 30/31 • 1 week ago

Personally, I'd tell them not to be so silly ;-) Or if I was feeling more helpful flash a message to them explaining what was going to happen. And that they were silly ;-)

More seriously, maybe they have a good reason for the 31st as a contractor only comes on those months, maybe not. Maybe you need to offer a more clear 'last day of the month' option - but what happens if that's a holiday/weekend? Hard to say - it's your code & clients :-)

But depending on your code/logic either of our examples should get you there. It really depends how you are scheduling the tasks and how you're triggering them as to how it's implemented though. If you are pre-populating future events, or if you are running once a day against a 'creation' event, or...

ohffs left a reply on Testing For Model Function • 1 week ago

Not sure what to suggest - maybe try dd'ing the manager pivot table data and see what might be causing it to fail.

ohffs left a reply on Testing For Model Function • 1 week ago

Did you try the change in my Edit: ? It looks like previous managers is looking for dates in the future?

ohffs left a reply on Testing For Model Function • 1 week ago

At a guess, the test is running too quickly - so the date check is seeing the same thing. As a quick check try adding sleep(2); between the hiring & firing :-) Also double check the column is a datetime and not just a date. I made that mistake a few weeks ago - well done me.. ;-)

ohffs left a reply on Search • 1 week ago

Generally you would use a separate tracking ID rather than just the database 'id' column. It might be a random string, or it could be semi-random with some information embedded in it (maybe a date, a code for source & destination or whatever) which is useful for humans processing the order to see at a glance.

Using the db ID is usually a bad idea for publicly facing things like tracking orders - partly it's easy to guess other numbers, and partly it's a pretty big clue to competitors as to how many customers/orders you are shipping (imagine you are ordering from a company who are trying to look very reliable and 'trust us with your valuable order' and then you see you are order number #00003 - you might think twice about giving them your order :-)

And yes - that would probably be in your controller. You could add a helper to the model though to make it read a little nicer, something like :

class Item extends Model
  public static function findByTrackingCode($code)
    return static::where('tracking_code', '=', $code)->first();

Then where-ever you need to do that in controllers etc you can just call Item::findByTrackingCode($theCode). That also has the benefit that if you change the column name or need some logic - none of your controllers need to worry about it.

ohffs left a reply on Search • 1 week ago

Is the 'id' the id column in the database, or a custom tracking id? It sounds like all you need is something like :

public function showItem($code)
  $item = Item::where('tracking_code', '=', $code)->first();
  if (!$item) {
    // return some kind of not found page
  return view('item.show', compact('item'));

In your view you can hide the admin/staff only parts inside an @ifclause or if the views are very different maybe a different view returned from the controller - or a separate admin controller.

ohffs left a reply on Handle Recurring Tasks Monthly On The 30/31 • 1 week ago

I haven't tried this, but something like it might be a bit neater at least. It's the same idea, just re-written a little :

function nextTaskDate($dueDate)
    $taskDay = Carbon::parse($dueDate)->day;
    $nextMonth = Carbon::parse($dueDate)->startOfMonth()->addMonth();
    $nextDay = max($taskDay, $nextMonth->daysInMonth);
    return $nextMonth->day($nextDay);

ohffs left a reply on How To Test Multiple File Upload ? • 1 week ago

I've got an almost identical test atm which works ok. The main difference I can see is that instead of ->json('post'... I'm doing ->call('POST'...

10th March, 2017

ohffs left a reply on Should I Learn Jquery ? • 2 weeks ago

I think jquery is a great way to learn the basis of web-focused javascript and also the DOM itself. It's got a lot of helpful features and (perhaps more importantly) it hides a lot of browser-version-strangeness from you so you don't need to worry so much about 'ah, apart from internet explorer...' which was 'such fun' down the years ;-)

Learning 'plain' JS is also valuable of course - especially now that a lot of the things that made jQuery so helpful are baked into the language itself. And if you're ever needing to do anything like nodejs it'll be invaluable.

Vue is (for me!) like a cleaner jQuery. I don't need to worry so much about things like 'oh, that div was toggled and now that element.parent.siblings.show doesn't work - hrm...' that can be a pain with jQuery. For instance if you have a big complicated form with lots of state & logic, then vue can be way easier to use than jQuery.

But jQuery is great - it's very likely you'll use it in projects for years to come. I use it almost every time I need JS as there are so many libraries based on it. You don't need to become a jQuery guru to get a whole lot of value from learning it.

9th March, 2017

ohffs left a reply on Laravel 5.4 Auto Convert Empty Text Input To Null? • 2 weeks ago

Maybe try commenting out the line with the new middleware and see how it goes?

8th March, 2017

ohffs left a reply on New Website. • 2 weeks ago

The easiest way to find out is to email another dev/company in your area/country with the spec and ask how much they'd do it for :-)

ohffs left a reply on Cannot Run Laravel 5.4 On PHP 7.0.16-1+xenial • 2 weeks ago

If that's a VM, then it's probably not getting enough entropy to generate 'randomness'. If you have ssh on the machine try running cat /dev/random and cat /dev/urandom (you'll have to control-c to quit the commands).

If both of those seem 'sluggish' then you might need to talk to the hosting provider.

ohffs left a reply on CSS Framework For EPOS Like Buttons On Tablet. • 2 weeks ago

Do the people who will be using it have any other systems to use? Eg, if they're on android tablets maybe using a material theme like materialize might be more 'native' feeling? If they are windows tablets then the metro one - etc.

7th March, 2017

ohffs left a reply on Should I Start My Project Immediately With VueJS Or Can I Integrate It Later? • 2 weeks ago

can I build my app entirely with Laravel and then integrate VueJS


As for jquery -> vue, it's a different way of going about things, but as someone who is terrible at JS I didn't find it too hard.

ohffs left a reply on DB Queries Within A For Loop • 2 weeks ago

If it's only a couple of queries I wouldn't worry too much, but if you're looping over lots items then doing another query in each loop then you might want to re-think how you're going about things.

5th March, 2017

ohffs left a reply on Trying To Get Property Of Non-object • 2 weeks ago

$data is an array - you'd have to do $data['locate'].

ohffs left a reply on Current URL With Query String • 2 weeks ago

Does $request->fullUrl() return it?

3rd March, 2017

ohffs left a reply on Can I Use Laravel Valet On Windows Os • 3 weeks ago

@victormongi I don't know - check the website?

2nd March, 2017

ohffs left a reply on Videos Won't Load • 3 weeks ago

Just a 'me too'. I've been trying to re-watch https://laracasts.com/series/learn-vue-2-step-by-step/episodes/19 for a week or so and it won't play from home.

The display shows http://imgur.com/a/Wi1RI and the console logs have the following if it's any help :

VIDEOJS: ERROR: (CODE:4 MEDIA_ERR_SRC_NOT_SUPPORTED) The media could not be loaded, either because the server or network failed or because the format is not supported. Object { code: 4, message: "The media could not be loaded, eith…" }  all.min.js:4:17776
    e.logByType https://laracasts.com/js/all.min.js:4:17776
    l.error https://laracasts.com/js/all.min.js:4:18039
    Q</e.prototype.error https://laracasts.com/js/all.min.js:7:3727
    Q</e.prototype.handleTechError_ https://laracasts.com/js/all.min.js:6:27304
    e.bind/i https://laracasts.com/js/all.min.js:4:8364
    e.bind/i https://laracasts.com/js/all.min.js:4:8364
    l/o.dispatcher https://laracasts.com/js/all.min.js:4:20822

Most other videos play fine - just the odd one or two. That one reliably fails every time for me though. This in on FF 51.0.1 macos 10.12.

1st March, 2017

ohffs left a reply on VPS Specs • 3 weeks ago

As you say - 'it depends'. There isn't much 'in general' you can say without way, way more details. You could try something like locust to see how you get on though.

27th February, 2017

ohffs left a reply on Sanity Check: Filesystem Management • 3 weeks ago

Assuming a 'page' is the main focus of your application, I'd be tempted to make a class (call it what you will!) that represented it and had the right logic.

So you could end up with :

use Some\Markdown;

class Page
    protected $realFile;
    protected $parser;

    public function __construct(Markdown $parser)
        $this->parser = $parser;

    public function resolve($path, $name)
        $file = $this->findDirect($path, $name);
        if (!$file) {
            $file = $this->findSlugged($path, $name);
        if (!$file) {
            // blow up
        $this->realFile = $file;
        return $this;

    public function asHtml()
        if (!$this->realFile) {
            // blow up
        return $this->parser($this->realFile);

    // ...

Then you can do things like :

$contents = (new Page)->resolve($path, $page)->asHtml();

Maybe ;-) I'm bored waiting on dinner cooking, so just typing off the top of my head ;-)

ohffs left a reply on Want To Create My Own Mini Video Platform Like Youtube • 3 weeks ago

There are a few I've seen crop up over the past year or so - haven't used them much beyond tinkering on a home network though :




ohffs left a reply on Let's Start This New Project With 5.4... NOT ! :( • 3 weeks ago

The testing stuff is the big issue with 5.4 for me too.

I think it would have been nicer to do something like 5.4 had the same functionality as 5.3 plus dusk if you want to pull it in, with some kind of deprecation notice about the current tests/browserkit for 5.5+.

I would still much prefer to have the HTTP + Basic Web(browserkit) + Advanced Web(dusk). The framework made such great strides in getting people on-board with TDD (almost to the point where it was quicker to develop with TDD than not), shifting the ground under us in a point-release 'surprise everyone!' change is quite annoying...

26th February, 2017

ohffs left a reply on Use LogicException From PHP • 3 weeks ago

If you do throw new \LogicException, does that work?

ohffs left a reply on Determine User Internet Conection Speed Using Javascript Or Php • 3 weeks ago


  • 1megabyte == 8megabits

  • Download a 1megabyte file in 1second == 8mbs connection

  • Download a 0.5megabyte file in 0.5seconds == 8mbs connection

  • Download a 0.5megabyte file in (0.5 * 2) seconds == (8 / 2) mbs connection

From there you can do the calculations for other mbs, hopefully.

ohffs left a reply on Determine User Internet Conection Speed Using Javascript Or Php • 3 weeks ago

Because you know the size of the file - so if you know how long it takes to download, you have a very rough ball-park idea of how fast their connection is.

Edit Your Profile

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