ohffs

Experience

191,180

266 Best Reply Awards

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

21st January, 2017

ohffs left a reply on Redis In Laravel - Password Protection • 8 hours ago

If redis is running on the same server as your laravel code - you're probably better making it bind to 127.0.0.1 only, if it isn't already.

Using the password is (afair) mostly there if you end up having to expose redis to the internet - which is generally a Bad Idea(tm).

ohffs left a reply on Laravel 5.3 Route Confusion For Search • 11 hours ago

You could maybe do something more like :

// Driver model
public function scopeSearch($query, $request)
{
  if ($request->has('first_name')) {
    $query->orWhere('first_name', 'like', "{$request->first_name}");
  }
  if ($request->has('phone_number')) {
    $query->orWhere....
  }
  return $query->select('id', 'first_name', ...);
}

// elsewhere in your app
function someThing(Request $request)
{
  $results = Driver::search($request)->get();
  // do something
}

ohffs left a reply on Laravel 5.3 Route Confusion For Search • 13 hours ago

Can you take the params as GET fields instead? Eg,

GET /api/search?first_name=jane

/api/search -> [email protected]')

function getSearchResults(Request $request)
{
  if ($request->has('first_name')) {
    ...
  }
  // etc
}

20th January, 2017

ohffs left a reply on Laravel Console Command, How To Output ñ Character • 1 day ago

If it's in a terminal, you'll have to make sure it supports unicode and the font you're using in it also has the right characters - not all of them do.

ohffs left a reply on Can't Laracast Be Free? :( • 1 day ago

@artem I've got nothing but admiration for you - I hope things get better in your country. I've got a Ukranian friend and I've seen her in tears watching the news from back home :'-/

18th January, 2017

ohffs left a reply on Is It Safe To Setup A Route Like This Or Is It Prone To Code Injection? • 3 days ago

That should be ok as the underlying libraries are covering a lot of the problems for you. If you're worried you can always add your own basic checks too though (ie, "does this $code look roughly like a code I expect?").

ohffs left a reply on Is It Safe To Setup A Route Like This Or Is It Prone To Code Injection? • 3 days ago

It entirely depends on what you do with $code - the routing is immaterial.

ohffs left a reply on Forum Help • 3 days ago

I don't think there's a realistic way to stop duplicate posts. Eg, are these the same?

what is laravel?

Tell me, what is laravel?

What is Laravel!

The content of those posts might also be very different. Even if you used a heuristic to manage those cases, there's

Help me, I have a problem

What do you think of this?

Which are probably valid duplicate post titles with varying content.

17th January, 2017

ohffs left a reply on Variable As Model Name, Is It Possible? • 4 days ago

@matthes no worries - glad it'll save you a bit of work :-)

ohffs left a reply on Disable PHPUnit Based On .env • 4 days ago

If all your tests inherit from the base TestCase then you could always over-ride the setUp method I guess. Maybe ;-) Something like :

    protected function setUp()
    {
        parent::setUp();
        if (env('APP_ENV') !== 'testing') {
           throw new \Exception('Argh!');
        }
    }

ohffs left a reply on Variable As Model Name, Is It Possible? • 4 days ago

@matthes have you looked into polymorphic relations seems to be what you're doing by hand?

ohffs left a reply on Laravel Cloud • 4 days ago

o_O

16th January, 2017

ohffs left a reply on To "Repository Pattern" Or Not? • 5 days ago

@DarkRoast could well be - there are a glorious 7,982 lines in the one class ;-) Apparently the code has never worked quite right either. I love consultants.... ;-)

ohffs left a reply on To "Repository Pattern" Or Not? • 5 days ago

@jekinney getThingWithOtherThing(); getThingWithOtherThingBetweenDates(); getThingWithOtherThingIfActive(); ..... I fear we have both faced the same nemesis ;-)

ohffs left a reply on To "Repository Pattern" Or Not? • 5 days ago

The old legacy project I'm working on just now has a section where the person writing it clearly 'saw the one true way' with the repository pattern.

There are 462 methods on the repository...

:: weeps ::

13th January, 2017

ohffs left a reply on VPS Ram 2 GB Almost Run Out Memory • 1 week ago

You're fine - you're only using 367mb of ram :

-/+ buffers/cache:     367088    1682848

The rest of your memory is being used by Linux to try and cache things to save hitting disk etc. It'll return it to your application if it needs it.

ohffs left a reply on Changing The Auth Model Laravel 5.3 • 1 week ago

Not sure about that I'm afraid - you'll have to do some debugging :-)

ohffs left a reply on Changing The Auth Model Laravel 5.3 • 1 week ago

Is there a reason you're doing use Illuminate\Foundation\Auth\Admin as Authenticatable; rather than the default `

If you change

use Illuminate\Foundation\Auth\Admin as Authenticatable;

to

use Illuminate\Foundation\Auth\User as Authenticatable;

See how that goes.

ohffs left a reply on Changing The Auth Model Laravel 5.3 • 1 week ago

On your Admin model, do you have :

use Illuminate\Foundation\Auth\User as Authenticatable;

class Admin extends Authenticatable
{
...

ohffs left a reply on Is It Worth Testing Really Small Wrapper Methods • 1 week ago

I tend not to unit test things where I'm doing something like you've got :

$model = new Model(['property' => 'X']);
$this->assertEquals('X', $model->property);

But I will make sure and test the logic/functionality through "higher level" tests, so covered by stuff like :

function test_a_user_can_be_marked_inactive()
{
  // whether $this->visit()->check('is_inactive') style or eventing or whatever
}

function test_a_user_cant_login_if_marked_inactive()
{
  // whatever
}

11th January, 2017

ohffs left a reply on QR Code Generator • 1 week ago

Not sure if it's what you're after, but https://github.com/tecnickcom/TCPDF can generate QR-codes, barcodes etc.

10th January, 2017

ohffs left a reply on It's For When The Release Of Laravel 5.4 ? • 1 week ago

I think the last thing I heard was 'before the end of January'.

ohffs left a reply on How To Assert That Events Were Fired And Inspect Data Using Fakes? • 1 week ago

In the docs you've linked to it has an example :

Event::fake();

Event::assertFired(OrderShipped::class, function ($e) use ($order) {
     return $e->order->id === $order->id;
});

ohffs left a reply on Sending Mail Laravel + Mailcatcher • 1 week ago

I think your problem is in :

'from' => ['address' => null, 'name' => null],

That's where you can set the sender address - either by hard-coding it in there or using the env() functions like for the 'host' parameter.

ohffs left a reply on Building Complex Seeders With Factories • 1 week ago

Yes, it's possible :-)

8th January, 2017

ohffs left a reply on What Is The Name Of The '->' In PHP OO • 1 week ago

@jlrdw I think I'm going to stick with 'arrowy thing' then - I was hoping for something more exciting ;-)

7th January, 2017

ohffs started a new conversation What Is The Name Of The '->' In PHP OO • 2 weeks ago

<inconsequential>

It's been (mildly) bugging me that I don't know the name of the -> when doing things like $model->method(). I keep calling it 'arrowy thing' which I would love to be true, but ... ;-)

</inconsequential>

ohffs left a reply on Helper With Eloquent Methods.. • 2 weeks ago

return collect($countries); will get you some of the way.

ohffs left a reply on HOW DOES FORGE REALLY WORK ? • 2 weeks ago

I'd guess it's mostly PHP with envoy. Not sure if it maybe uses something like ansible/puppet too.

ohffs left a reply on HOW DOES FORGE REALLY WORK ? • 2 weeks ago

Running commands over ssh?

5th January, 2017

ohffs left a reply on Get Another Controllers Output • 2 weeks ago

In endpoint terms, I guess I mean instead of doing something like :

$availableUsers = get('/users');
$years = get('/years');
$sales = get("/sales/{$years[0]}");
$... etc

You might be able to think of a different endpoint 'thing' (or 'class') so you can do :

$theLogicalEntityIWant = get('/reports/sales/thisyear');

I'm possibly not explaining myself very well - I'm just back to the day job after two weeks holiday and my brain is like swiss cheese... ;-)

ohffs left a reply on Get Another Controllers Output • 2 weeks ago

Is there a 'missing' class in there somewhere? Sometimes when I find myself in this situation I realise could extract the shared data/logic into it's own class as it's a valid 'thing' on it's own.

Sometimes I'll extract it into something that feels a bit 'clunky' and vague while I flesh it out then think of a more appropriate name once it's got it's shape.

Not very specifically helpful I realise - but there we go :-)

4th January, 2017

ohffs left a reply on Modern Dev Forces Me To JS When I Want To PHP. • 2 weeks ago

@primordial

Lets all build monoliths starting at column 7

You've no idea how much that made me giggle ;-)

ohffs left a reply on Modern Dev Forces Me To JS When I Want To PHP. • 2 weeks ago

@primordial We're not old - we're just retro-chic ;-) And for amusement... http://adrianzandberg.pl/cobol-on-wheelchair/ ;-)

ohffs left a reply on Modern Dev Forces Me To JS When I Want To PHP. • 2 weeks ago

I'm sticking with fully integrated monoliths on the assumption they'll come back into fashion at some point ;-) I also know Cobol, if anyone's hiring.... ;-)

I try to keep the JS I use to a minimum. The last little project I did pulled in jq/datatables to make filtering some tables a bit easier - but other than that had no js involved at all. I sometimes watch videos of people doing modern JS stuff and seeing all the babel/gulp/node/whatever - 100mb of node_modules, build scripts, etc - and the end result often seems to be that you have one script tag instead of two or three. So you possibly save a few ms on tcp handshakes - but I kind of "don't get it" really.

3rd January, 2017

ohffs left a reply on How To Access Auth User Details In Config Files? • 2 weeks ago

Authentication info, afair, isn't available at that stage in the app. A more basic way to do it might be to have a helper on the user model that returns their path, like :

public function cachePath()
{
  return public_path('image/'.$this->id);
}

1st January, 2017

ohffs left a reply on Using Auth::id() In A Config File Doesnt Wotk • 2 weeks ago

The config files are loaded before the authentication is available. You'll have to do this in a different way I think.

31st December, 2016

ohffs left a reply on Testing An Obese Test • 3 weeks ago

(I'm a bit tipsy - it's hogmany here! so forgive me if this is all rubbish)

I think you're maybe trying to 'see' too much in the one test? Maybe think about breaking it down into something like :

  • an_event_can_have_multiple_matches
  • an_event_can_have_many_wrestlers
  • a_wrestler_can_be_removed_from_an_event
  • etc.

etc. Then you can do a small unit test something like :

$event = factory(...);
$event->addWrestlers(...);
$wrestlers = $event->formattedWrestlerList();
$this->assertEquals('Jim vs. Carol vs. Big Daddy', $wrestlers);

You've also got a lot of assertions which aren't really testing very much. For instance you do :

$event = factory(Event::class)->states('published')->create([... 'venue_id' => $venue->id, ...]);
...
$this->assertEquals($event->venue_id, $venue->id);

You're pretty much testing eloquent itself there rather than anything of your own logic. If you had something like :

$venue = factory(....);
$venue->addEvent($event1Data);
$venue->addEvent($event2Data);

Then you could make some assertions that the 'addEvent' method was doing what you expected, but doing things like :

$model->property = 2;
$this->assertEquals(2, $model->property);

Doesn't really get you much :-)

30th December, 2016

ohffs left a reply on Eloquent Update Record - Fillable Fields • 3 weeks ago

Should do - yep :-)

ohffs left a reply on Eloquent Update Record - Fillable Fields • 3 weeks ago

Do you mean something different from mass assignment?

Ie, do you mean that a record can only have it's title set at creation time but not when updating? You can grab just allowed fields from the request by doing $request->only(['field1', 'field2']) if that would help?

29th December, 2016

ohffs left a reply on Review My First Simple CRUD App • 3 weeks ago

You need to be a little careful with things like ->fill(). For instance if your user should only be able to update one or two fields then you can either set the $fillable or $guarded properties on the model - or instead of $request->all() you can do $request->only(['field1', 'field2']). Have a look at the mass assignment section for some details :-)

ohffs left a reply on Review My First Simple CRUD App • 3 weeks ago

That's way better than my first attempts with Laravel after I made the shift from old-school PHP to 'modern' :-) Congratulations :-)

If you want a few things that stood out to me - mostly just 'places you could take more advantage of Laravel' stuff really...

In this section you have a lot of if/else statements etc where you can take advantage of laravel/models etc instead, eg :

public function show($id)
{
    $club = Club::with('terms', 'clubdetails')->findOrFail($id);
    if (!$club->Published) {
        return redirect()->action([email protected]')->withMessage('Club is not available yet');
    }
    return view('clubs.show', ['club'  => $club, 'yearGroups'  => $this->yearGroups]);
}

// Model

public function hasHeroImage()
{
    if (file_exists ....) {
        return true;
    }
    return false;
}

public function heroImagePath()
{
    return '/uploads/clubimages/.....';
}

public function getBookingButton()
{
    // not sure what this does - but it's here anyway!
    return new bookingButton($this->EventBriteID, $this->terms->BookingCloses);
}

// View

@if ($club->hasHeroImage())
    <img src="{{ $club->heroImagePath() }}">
@endif

You're also doing a lot of manual work updating models - I have code from when I started using the framework that looks exactly the same! :-) For instance you can replace a lot of code with laravel helpers :

// current code
      $club = Club::findOrFail($id);
      $club->ClubDetailID = $request->ClubDetailID;
      $club->TermID = $request->TermID;
      $club->Day = $request->Day;
      $club->Price = $request->Price;
      $club->Costs = $request->Costs;
      $club->StartTime = $request->StartTime;
      $club->EndTime = $request->EndTime;
      $club->Published = ($request->Published) ? true : false;
      $club->EventBriteID = $request->EventBriteID;

// you could
      $club = Club::findOrFail($id);
      $club->fill($request->all());
      $club->Published = ($request->Published) ? true : false;  // depending what 'Published' is you might be able to lose that too.

Honestly - your code is a great start :-) As you get more familiar with all the stuff the framework can do you'll save yourself a lot of typing if nothing else :-)

ohffs left a reply on Is It Possible To Merging Two Arrays Loop Into One? • 3 weeks ago

How do you want them merged? Do they have to preserve any kind of ordering? For basic merges there is https://laravel.com/docs/5.3/collections#method-merge and http://php.net/manual/en/function.array-merge.php - but it depends what you're wanting to end up with really.

ohffs left a reply on Testing For Output Order • 3 weeks ago

Not sure if there's anything specific that's been added to the framework recently, but I usually do something like in plain php-ish :

$response = $this->call('GET', '/some/route');
$this->assertTrue(preg_match('/thing1.*thing2.*thing3/s', $response->content());

ohffs left a reply on My Personal (bad) Experience With Forge Service • 3 weeks ago

@jfo Taylor made his first full-time hire this summer, so at least some of your issues/questions might be a little more covered now. I seem to remember reading that a lot of the new employee's time was going to be given over to helping with forge etc.

28th December, 2016

ohffs left a reply on External Monitor Tips • 3 weeks ago

I got one of these recently - very happy with it :-) https://www.amazon.co.uk/DELL-U2515H-ADZG-25-Inch-Monitor/dp/B00P6O3YYO

ohffs left a reply on Statemic Vs Wordpress • 3 weeks ago

Running sites without a db can be handy - for instance if you don't have a db ;-) It's easy to host them almost anywhere for almost $0 - easy to scale if that's an issue too. There's generally less security to worry about, not so much worry about upgrades, patches etc either.

Whether statamic is worth $199 to you is another matter though - it's certainly a bit friendlier than some of the other static site creators. I used to use pelican as I got fed up dealing with wordpress - but it's not as easy to use as statamic from what I've seen.

Up to you really :-)

27th December, 2016

ohffs left a reply on How To Return The Current Inserted Model As Object Using Model Events !! • 3 weeks ago

... Why do you want to do this when you already have the model?

Edit Your Profile
Update

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