Skip to content

Instantly share code, notes, and snippets.

@Lelectrolux
Lelectrolux / FormTest.php
Last active October 15, 2020 16:55
Testing forms validation errors in laravel
<?php
namespace Tests\Feature;
use App\Models\Model;
use Generator;
use Illuminate\Foundation\Testing\RefreshDatabase;
// use Illuminate\Support\Facades\Mail;
use Tests\TestCase;
@Lelectrolux
Lelectrolux / Readme.md
Last active February 8, 2018 20:18
lastInteraction relation

First, I'm french, sleep deprived, the last thing I want is to appear smug or passive aggressive because my english isn't good enough.

In yesterday's Advanced Querying with Eloquent talk (which was very good), you defined a lastInteraction relation like this :

public function lastInteraction()
{
    return $this->hasOne(Interaction::class, 'id', 'last_interaction_id');
}

public function scopeWithLastInteraction($query)

First, I'm happy to delete the following or move it to a gist if it doesn't belong here, but I think some real life example/use case might be a good idea. I will answer question if you have any.


I got a few places where this feature would be handy. I run an app where we have a bunch of stuff (Hotel/Restaurant/Shop/Activity) classified by Region (Like US State if it speaks more to you) then City.

Here is a stripped down example.


Routes
@Lelectrolux
Lelectrolux / Readme.md
Last active August 16, 2016 23:09
Collection of packages to start a fresh install of Laravel 5
@Lelectrolux
Lelectrolux / 2016_07_08_201754_create_region_city_hotel_table.php
Last active August 3, 2016 13:52
[Laravel] implicit model binding in controller
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRegionCityHotelTable extends Migration
{
/**
* Run the migrations.
*
@Lelectrolux
Lelectrolux / ReadMe.md
Last active August 3, 2016 13:55
testing priority in laravel routing