Skip to content

Instantly share code, notes, and snippets.

Laracasts laracasts

Block or report user

Report or block laracasts

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@laracasts
laracasts / Gulpfile.js
Created Aug 20, 2014
PHPSpec auto-testing Gulpfile
View Gulpfile.js
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 Mar 2, 2019
Little JavaScript helpers for a Laravel app.
View usage.php
{{ 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 Aug 29, 2015
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…
View codeception-ex.php
<?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 Jan 27, 2016
So you want to allow one user to "follow" another user (like Twitter-style). Using Laravel and Eloquent, what's your preference?
View ex.php
<?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');
}
View CommandBus.php
<?php
// ...
/**
* Register a decorator for the command bus.
*
* @param string $decorator
* @return CommandBus
*/
View ex.php
<?php
// ...
public function store(RegistrationForm $form)
{
$form->validate(); // throws exception if fails
// save stuff
}
@laracasts
laracasts / StatusRepository.php
Last active May 19, 2018
Integration Testing Repositories That Use Eloquent (with Codeception)
View StatusRepository.php
<?php namespace Larabook\Statuses;
use Larabook\Users\User;
class StatusRepository {
/**
* Get all statuses associated with a user.
*
* @param User $user
@laracasts
laracasts / MailTestCase.php
Created Jun 14, 2014
Use Mailcatcher to test email.
View MailTestCase.php
<?php
use GuzzleHttp\Message\Response;
class MailTestCase extends TestCase {
protected $mailcatcher;
function __construct()
{
View gist:99535e8db4298056b76d
<?= 'Add your Wii U username below'; ?>
@laracasts
laracasts / ApiTester.php
Last active May 14, 2018
Incremental APISs: Refactoring Tests and Traits
View ApiTester.php
<?php
use Faker\Factory as Faker;
abstract class ApiTester extends TestCase {
/**
* @var Faker
*/
protected $fake;
You can’t perform that action at this time.