Skip to content

Instantly share code, notes, and snippets.

@laracasts
laracasts / ex.php
Last active August 29, 2015 14:17
Working on integration testing helper for PHPUnit.
<?php
class ExampleTest extends IntegrationTest
{
/** test */
public function it_verifies_that_pages_load_properly()
{
$this->visit('/');
}
@laracasts
laracasts / pivot-generator.php
Last active September 14, 2018 10:15
Artisan Pivot Migration Generator
<?php
namespace App\Console\Commands;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
class PivotMigrationMakeCommand extends GeneratorCommand
{
@laracasts
laracasts / gist:f4a304232c1be6dbb4f8
Last active February 16, 2023 20:19
Laracasts PHPStorm theme.
/**
* Destroy the user's session (logout).
*
* @return Response
*/
public function destroy()
{
Auth::logout();
flash()->info('You are now logged out.');
@laracasts
laracasts / Gulpfile.js
Created August 20, 2014 20:47
PHPSpec auto-testing Gulpfile
var gulp = require('gulp');
var phpspec = require('gulp-phpspec');
var run = require('gulp-run');
var notify = require('gulp-notify');
gulp.task('test', function() {
gulp.src('spec/**/*.php')
.pipe(run('clear'))
.pipe(phpspec('', { notify: true }))
.on('error', notify.onError({
@laracasts
laracasts / usage.php
Last active March 2, 2019 09:42
Little JavaScript helpers for a Laravel app.
{{ Form::open(['data-remote', 'data-remote-success-message' => 'I have now done the thing.']) }}
{{ Form::text('name') }}
{{ Form::submit('Submit', ['data-confirm' => 'Are you sure?']) }}
{{ Form::close() }}
@laracasts
laracasts / codeception-ex.php
Last active August 29, 2015 14:04
I want an acceptance test for an Artisan command that generates some files with boilerplate. However, this command is part of a Composer package. I'm trying to figure out the best way to actually call Artisan from the package. Right now, I'm just assuming the framework and doing ../../../artisan. Is there an alternative/better way that you'd sug…
<?php
$saveDir = './tests/acceptance/tmp';
$stubDir = './tests/acceptance/stubs';
$commandToGenerate = 'FooCommand';
$I = new AcceptanceTester($scenario);
$I->wantTo('generate a command and handler class');
// Is there a better way to call the Artisan command? Without having to expect the framework and do ../../../?
@laracasts
laracasts / ex.php
Last active January 27, 2016 13:08
So you want to allow one user to "follow" another user (like Twitter-style). Using Laravel and Eloquent, what's your preference?
<?php
// Option 1: the follow method immediately references the relationship and saves it.
class User extends Eloquent {
public function follows()
{
return $this->belongsToMany(self::class, 'follows', 'follower_id', 'followed_id');
}
<?php
// ...
/**
* Register a decorator for the command bus.
*
* @param string $decorator
* @return CommandBus
*/
<?php
// ...
public function store(RegistrationForm $form)
{
$form->validate(); // throws exception if fails
// save stuff
}