Skip to content

Instantly share code, notes, and snippets.

View simonhamp's full-sized avatar
💭
Accidentally learning Rust

Simon Hamp simonhamp

💭
Accidentally learning Rust
View GitHub Profile
// Before
<h1>FooBar</h1>
<?php $foo = 'Foo'; ?>
<p>{{ $foo }}</p>
// After
<h1>FooBar</h1>
@include( 'partials/foo', [ 'foo' => 'Foo' ] )
<?php
trait AuthenticatesUsers {
public function getLogin() {
if (view()->exists('auth.authenticate')) {
return view('auth.authenticate');
}
return view('auth.login');
}
}
@simonhamp
simonhamp / Foo.php
Last active February 6, 2016 01:16
<?php
class Foo {
use AuthenticatesUsers {
getLogin as login;
}
public function getLogin() {
// Do my stuff
return $this->login()->with('myvar', 'Hello World');
}
@simonhamp
simonhamp / AppServiceProvider.php
Last active March 26, 2024 15:56
A pageable Collection implementation for Laravel
<?php
namespace App\Providers;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
class AppServiceProvider extends ServiceProvider
{
public function boot()

Keybase proof

I hereby claim:

  • I am simonhamp on github.
  • I am simonhamp (https://keybase.io/simonhamp) on keybase.
  • I have a public key ASAHPdAFANeP0F6wuxEQSZ1pduJknbEHdlTnEIcd6CuB8go

To claim this, I am signing this object:

<?php
/**
* Return the common parts from 2 strings.
*
* @param string $str1
* @param string $str2
* @param bool $from_end
* return string
*/
@simonhamp
simonhamp / AuthorizationTest.php
Created December 10, 2017 06:00
Laravel Testing: Ensure your controllers enforce authorization
<?php
namespace App\Tests;
use Illuminate\Support\Facades\Route;
class AuthorizationTest extends TestCase
{
public function setUp()
{
@simonhamp
simonhamp / RemoteArtisan.php
Last active February 10, 2021 10:41
RemoteArtisan: A way to call another Laravel/Lumen application's artisan command from the context of the current application.
<?php
namespace App;
use Dotenv\Dotenv;
use Illuminate\Support\Str;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
class RemoteArtisan
@simonhamp
simonhamp / list.php
Last active June 15, 2021 21:23
Using list() in foreach in PHP
<?php
$items = [
['field' => 'field1', 'values' => [0, 1, 2, 3, 4]],
['field' => 'field2', 'values' => ['cat', 'dog', 'horse']]
];
foreach ($items as list('field' => $field, 'values' => $values)) {
// can use $field and $values here now!
}
@simonhamp
simonhamp / BaseModel.php
Last active March 25, 2020 16:57
Eloquent: Simple Model Event Handling
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class BaseModel extends Model
{
/**
* Override the default boot method to register some extra stuff for every child model.