nexxai

nexxai

Member Since 1 Year Ago

Experience Points
21,790
Total
Experience

3,210 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
204
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 5
21,790 XP
Aug
16
2 months ago
Activity icon

Replied to Save Image From Remote URL

Have you tried adding "https:" to the from of the URL to see if it's related to a missing scheme?

Aug
15
2 months ago
Activity icon

Replied to Storage::assertMissing Failing; File Is Actually Gone In Real Life

That worked perfectly. Thank you so much!

Activity icon

Replied to Storage::assertMissing Failing; File Is Actually Gone In Real Life

I'm using Storage::fake('digitalocean'); at the top of the test though, so it's using the local storage for testing. It's the local (testing) storage where it fails; using the route normally (when it actually reaches out to DigitalOcean) works perfectly fine which is what makes no sense.

Activity icon

Started a new Conversation Storage::assertMissing Failing; File Is Actually Gone In Real Life

I have this test:

    public function deletingAStudioResultsInTheLogoBeingDeleted()
    {
        $this->signIn();

    Storage::fake('digitalocean');

        $studio = make(\App\Studio::class, [
            'name' => 'Fox Searchlight',
            'logo' => UploadedFile::fake()->image('fox-searchlight.jpg', 100, 100)->size(100),
        ]);

        $this->json('POST', route('studio.store'), $studio->toArray());

        // We want to first make sure it exists before we delete it, otherwise we might just be testing NULL
        Storage::disk('digitalocean')->assertExists('logos/fox-searchlight.jpg');

        $this->call('DELETE', route('studio.destroy', $studio));

        Storage::disk('digitalocean')->assertMissing('logos/fox-searchlight.jpg');
    }

testing this method:

    public function destroy(Studio $studio)
    {
        Storage::disk('digitalocean')->delete($studio->logo);

        $studio->delete();

        request()->session()->flash('success', 'Deleted '.$studio->name);

        return redirect()->route('studio.index');
    }

If I actually access this method through my browser, it correctly reaches out to DigitalOcean and deletes the logo. The problem is that if I run the test, I get:

> Executing task: /Users/user/.composer/vendor/bin/phpunit /Users/user/code/project/tests/Feature/StudioTest.php --filter '^.*::deletingAStudioResultsInTheLogoBeingDeleted( .*)?$' <

PHPUnit 7.5.14 by Sebastian Bergmann and contributors.

F                                                                   1 / 1 (100%)

Time: 729 ms, Memory: 28.00 MB

There was 1 failure:

1) Tests\Feature\StudioTest::deletingAStudioResultsInTheLogoBeingDeleted
Found unexpected file at path [logos/fox-searchlight.jpg].
Failed asserting that true is false.

/Users/user/code/project/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php:82
/Users/user/code/project/tests/Feature/StudioTest.php:316
/Users/user/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:201
/Users/user/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:160

FAILURES!
Tests: 1, Assertions: 2, Failures: 1.
The terminal process terminated with exit code: 1

Am I using the wrong assertion, or am I missing something?

Activity icon

Replied to How To Storage::fake() An Entire Set Of Tests

Ugh, I knew that. I'm an idiot.

Thanks!

Activity icon

Started a new Conversation How To Storage::fake() An Entire Set Of Tests

I have a class that an uploaded file is required and so I've added the UploadedFile::fake() to the factory, but I really don't want to be uploading actual files to the host for every test (there are a lot of tests) and so I want to mock the Storage. The Laravel docs say to use "Storage::fake()" which makes sense but I don't want to have to add that to every test and so I was hoping to use it in the __construct method like:

<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Foundation\Testing\RefreshDatabase;

class StudioTest extends TestCase
{
    use RefreshDatabase;

    public function __construct()
    {
        Storage::fake('storage_location');
    }

but when I do, I get this error:

PHP Fatal error:  Uncaught ReflectionException: Class path.storage does not exist in /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php:790
Stack trace:
#0 /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php(790): ReflectionClass->__construct('path.storage')
#1 /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php(667): Illuminate\Container\Container->build('path.storage')
#2 /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php(615): Illuminate\Container\Container->resolve('path.storage', Array)
#3 /Users/path/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(121): Illuminate\Container\Container->make('path.storage', Array)
#4 /Users/path/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(846): app('path.storage')
#5 /Users/path/vendor/laravel/framework/src/Illuminate/Support/Facades/Storage.php(26): in /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 790

Fatal error: Uncaught ReflectionException: Class path.storage does not exist in /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php:790
Stack trace:
#0 /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php(790): ReflectionClass->__construct('path.storage')
#1 /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php(667): Illuminate\Container\Container->build('path.storage')
#2 /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php(615): Illuminate\Container\Container->resolve('path.storage', Array)
#3 /Users/path/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(121): Illuminate\Container\Container->make('path.storage', Array)
#4 /Users/path/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(846): app('path.storage')
#5 /Users/path/vendor/laravel/framework/src/Illuminate/Support/Facades/Storage.php(26): in /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 790

which I assume has something to do with the fact that Storage:: is just a facade, but I don't know enough PHP to know what to do about it or even the right terms to Google.

Can anyone help me out?

Aug
11
2 months ago
Activity icon

Replied to Str Slug With Arabic Not Working

Also, this would be a great place to contribute to the Laravel framework, by adding support for Arabic to the slug generator

Aug
01
2 months ago
Activity icon

Replied to Not Saving To Database

@aurawindsurfing Looks like you got it right. I'm not sure why it worked fine in tinker but not via http, but regardless, adding the $pipeline->save() to the controller worked.

Thanks so much for your help!

Activity icon

Replied to Not Saving To Database

Here's a wrinkle: it works fine when I use artisan tinker.

@aurawindsurfing - I'll try your method and report back in a moment.

Activity icon

Replied to Not Saving To Database

I only have the one database and schema on this machine, and I've confirmed that even by closing and re-opening TablePlus that the table is completely empty. I also use this database for sessions and those are persisting properly.

Activity icon

Replied to Not Saving To Database

Also, if I update the $this->save() to dd($this->save());, it returns true. So it obviously thinks it's saving correctly, but for whatever reason, the DB isn't actually doing it.

Activity icon

Started a new Conversation Not Saving To Database

I have this model/methods:

<?php

namespace App;

use Illuminate\Support\Arr;
use Illuminate\Database\Eloquent\Model;
use App\Http\Requests\PipelineRequest;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Auth;

class Pipeline extends Model
{
    use SoftDeletes;

    protected $guarded = [];

    /**
     * Create a single API key
     *
     * @return string
     */
    public static function generate_api_key()
    {
        $randomness = random_bytes(256);
        $key = urlencode(hash('sha256', $randomness));

        return $key;
    }

    public function ingest($row, $schema_id)
    {
        $this->name = $row[0];
        $this->table_name = $row[0];
        $this->created_by_user_id = Auth::id();
        if (!$this->api_key_primary) {
            $this->api_key_primary = Pipeline::generate_api_key();
        }
        if (!$this->api_key_secondary) {
            $this->api_key_secondary = Pipeline::generate_api_key();
        }
        $this->dependsOn_azure_data_pipeline_activity_name = 'ETL Log and Load';
        $this->callback_url = null;
        $this->modified_column_name = $row[1];
        if (Arr::exists($row, 2)) {
            $this->version_table_name = $row[2];
        }
        $this->schema_id = $schema_id;

        $this->save();
        dd($this);
    }
}

When I hit the Pipeline::ingest route with the appropriate data, it does spit out a result:

Pipeline {#727 ▼
  #guarded: []
  #connection: "mysql"
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: true
  #attributes: array:13 [▶]
  #original: array:13 [▼
    "name" => "Equipment"
    "table_name" => "Equipment"
    "created_by_user_id" => 5
    "api_key_primary" => "6bf0cc9129525b02cfd4a4de794d4323d4c255451143da79cc6be87b98951815"
    "api_key_secondary" => "163dfb8087594a0377e4be3cbec6a6dd99a22d8d5ab9d852488113ef421df182"
    "dependsOn_azure_data_pipeline_activity_name" => "ETL Log and Load"
    "callback_url" => null
    "modified_column_name" => "ModifiedUTC"
    "version_table_name" => "08d84af1816ebc474ef4c5e4dbfe6841abb042c46103965b3940f46fc51bd731"
    "schema_id" => "3"
    "updated_at" => "2019-08-01 17:36:43"
    "created_at" => "2019-08-01 17:36:43"
    "id" => 232
  ]
  #changes: []
  #casts: []
  #dates: array:1 [▶]
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: []
  #forceDeleting: false
}

with even the id value incrementing every single time, but nothing is actually persisted to the database. I feel like I'm taking crazy pills here.

Can anybody see what I'm missing?

May
22
4 months ago
Activity icon

Replied to PHPUnit Will Not Use :memory: Database

So it turns out that even though I had defined the phpunit.xml file to use ":memory:", at some point I had edited config/sessions.php from 'driver' => env('SESSION_DRIVER', 'database'), to 'driver' => 'database',so it was still trying to use the database for sessions.

Fixed it back to what it should have been, and now my entire test suite has gone down from around 90 minutes to ~5.

Thanks @diegoaurino for your suggestions, but it turns out you can't fix stupid.

Activity icon

Replied to PHPUnit Will Not Use :memory: Database

@diegoaurino Thanks for that suggestion, but I actually already tried that

Configuring my phpunit.xml to use:

  <env name="DB_CONNECTION" value="testing"/>

as well as:

  <env name="DB_CONNECTION" value="sqlite"/>
   <env name="DB_DATABASE" value=":memory:"/>
May
21
4 months ago
Activity icon

Replied to PHPUnit Will Not Use :memory: Database

For posterity's sake, I compared my phpunit.xml with one from a new, blank Laravel installation and noticed that the entries within have gone from <env to <server so I updated those and now it's still failing but at least it's a console error now, and not within some HTML:

➜  exampleSite git:(issue-collections-edit-not-showing-correct-format) ✗ phpunit --filter a_user_can_reorder_a_Examples_characters_by_importance
PHPUnit 7.5.9 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 231 ms, Memory: 20.00 MB

There was 1 error:

1) Tests\Feature\ExampleTest::a_user_can_reorder_a_Examples_characters_by_importance
Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = ? and table_name = laralum_permissions and table_type = 'BASE TABLE')

/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:624
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:333
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Schema/MySqlBuilder.php:18
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:237
/Users/nexxai/code/exampleSite/vendor/laralum/permissions/src/PermissionsChecker.php:43
/Users/nexxai/code/exampleSite/vendor/laralum/laralum/src/LaralumServiceProvider.php:59
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:32
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:90
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:34
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Container/Container.php:576
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:817
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:800
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:801
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php:17
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:210
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:311
/Users/nexxai/code/exampleSite/tests/CreatesApplication.php:19
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:92
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:69
/Users/nexxai/code/exampleSite/tests/Feature/ExampleTest.php:15
/Users/nexxai/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:207
/Users/nexxai/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:163

Caused by
Doctrine\DBAL\Driver\PDOException: SQLSTATE[HY000] [2002] Connection refused

/Users/nexxai/code/exampleSite/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:31
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:67
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:46
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:182
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:918
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:943
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:399
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:325
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:657
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:624
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:333
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Schema/MySqlBuilder.php:18
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:237
/Users/nexxai/code/exampleSite/vendor/laralum/permissions/src/PermissionsChecker.php:43
/Users/nexxai/code/exampleSite/vendor/laralum/laralum/src/LaralumServiceProvider.php:59
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:32
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:90
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:34
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Container/Container.php:576
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:817
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:800
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:801
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php:17
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:210
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:311
/Users/nexxai/code/exampleSite/tests/CreatesApplication.php:19
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:92
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:69
/Users/nexxai/code/exampleSite/tests/Feature/ExampleTest.php:15
/Users/nexxai/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:207
/Users/nexxai/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:163

Caused by
PDOException: SQLSTATE[HY000] [2002] Connection refused

/Users/nexxai/code/exampleSite/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:67
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:46
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:182
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:918
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:943
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:399
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:325
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:657
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:624
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:333
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Database/Schema/MySqlBuilder.php:18
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:237
/Users/nexxai/code/exampleSite/vendor/laralum/permissions/src/PermissionsChecker.php:43
/Users/nexxai/code/exampleSite/vendor/laralum/laralum/src/LaralumServiceProvider.php:59
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:32
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:90
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:34
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Container/Container.php:576
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:817
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:800
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:801
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php:17
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:210
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:311
/Users/nexxai/code/exampleSite/tests/CreatesApplication.php:19
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:92
/Users/nexxai/code/exampleSite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:69
/Users/nexxai/code/exampleSite/tests/Feature/ExampleTest.php:15
/Users/nexxai/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:207
/Users/nexxai/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:163

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
➜  exampleSite git:(issue-collections-edit-not-showing-correct-format) ✗ 
Activity icon

Started a new Conversation PHPUnit Will Not Use :memory: Database

Ok so I'm definitely taking crazy pills, I just can't figure out which ones.

No matter what I do, I cannot get PHPUnit to use the in-memory database. I've tried:

Setting my .env to this (just to ensure it wasn't using the real database connection in the background):

DB_CONNECTION=sqlite
DB_DATABASE=":memory:"

and also:

DB_CONNECTION=testing

while having database.php show:

        'testing' => [
            'driver' => 'sqlite',
            'database' => ':memory:',
            'prefix' => '',
        ],

Configuring my phpunit.xml to use:

        <env name="DB_CONNECTION" value="testing"/>

as well as:

        <env name="DB_CONNECTION" value="sqlite"/>
        <env name="DB_DATABASE" value=":memory:"/>

This is an example error, which is weird because it's showing the Connection.php error inside the HTML of the page it's testing:

1) Tests\Feature\ExampleTest::a_user_can_reorder_a_Examples_characters_by_importance
Failed asserting that Failed asserting that '<!DOCTYPE html><!--


Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `sessions` where `id` = y6wLaM4CgTSQjVjpHzzcxOISLhZTfoLpaCr9mEiN limit 1) in file /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 664
Stack trace:
  1. Illuminate\Database\QueryException-&gt;() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
  2. Doctrine\DBAL\Driver\PDOException-&gt;() /Users/nexxai/code/examplesite/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:31
  3. PDOException-&gt;() /Users/nexxai/code/examplesite/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27
  4. PDO-&gt;__construct() /Users/nexxai/code/examplesite/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27
  5. Doctrine\DBAL\Driver\PDOConnection-&gt;__construct() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:67
  6. Illuminate\Database\Connectors\Connector-&gt;createPdoConnection() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:46
  7. Illuminate\Database\Connectors\Connector-&gt;createConnection() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24
  8. Illuminate\Database\Connectors\MySqlConnector-&gt;connect() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:182
  9. Illuminate\Database\Connectors\ConnectionFactory-&gt;Illuminate\Database\Connectors\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:918
 10. call_user_func() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:918
 11. Illuminate\Database\Connection-&gt;getPdo() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:943
 12. Illuminate\Database\Connection-&gt;getReadPdo() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:399
 13. Illuminate\Database\Connection-&gt;getPdoForSelect() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:325
 14. Illuminate\Database\Connection-&gt;Illuminate\Database\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:657
 15. Illuminate\Database\Connection-&gt;runQueryCallback() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:624
 16. Illuminate\Database\Connection-&gt;run() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Connection.php:333
 17. Illuminate\Database\Connection-&gt;select() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2124
 18. Illuminate\Database\Query\Builder-&gt;runSelect() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2112
 19. Illuminate\Database\Query\Builder-&gt;Illuminate\Database\Query\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2598
 20. Illuminate\Database\Query\Builder-&gt;onceWithColumns() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2113
 21. Illuminate\Database\Query\Builder-&gt;get() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php:77
 22. Illuminate\Database\Query\Builder-&gt;first() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2087
 23. Illuminate\Database\Query\Builder-&gt;find() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Session/DatabaseSessionHandler.php:91
 24. Illuminate\Session\DatabaseSessionHandler-&gt;read() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Session/Store.php:97
 25. Illuminate\Session\Store-&gt;readFromHandler() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Session/Store.php:87
 26. Illuminate\Session\Store-&gt;loadSession() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Session/Store.php:71
 27. Illuminate\Session\Store-&gt;start() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:81
 28. Illuminate\Session\Middleware\StartSession-&gt;Illuminate\Session\Middleware\{closure}() /Users/nexxai/.composer/vendor/illuminate/support/helpers.php:1027
 29. tap() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:82
 30. Illuminate\Session\Middleware\StartSession-&gt;startSession() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:51
 31. Illuminate\Session\Middleware\StartSession-&gt;handle() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
 32. Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
 33. Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
 34. Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse-&gt;handle() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
 35. Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
 36. Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}() /Users/nexxai/code/examplesite/app/Http/Middleware/UpdateLastSeen.php:19
 37. App\Http\Middleware\UpdateLastSeen-&gt;handle() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
 38. Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
 39. Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:66
 40. Illuminate\Cookie\Middleware\EncryptCookies-&gt;handle() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
 41. Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
 42. Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104
 43. Illuminate\Pipeline\Pipeline-&gt;then() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Router.php:682
 44. Illuminate\Routing\Router-&gt;runRouteWithinStack() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Router.php:657
 45. Illuminate\Routing\Router-&gt;runRoute() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Router.php:623
 46. Illuminate\Routing\Router-&gt;dispatchToRoute() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Router.php:612
 47. Illuminate\Routing\Router-&gt;dispatch() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176
 48. Illuminate\Foundation\Http\Kernel-&gt;Illuminate\Foundation\Http\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
 49. Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}() /Users/nexxai/code/examplesite/vendor/beyondcode/laravel-query-detector/src/QueryDetectorMiddleware.php:33
 50. BeyondCode\QueryDetector\QueryDetectorMiddleware-&gt;handle() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
 51. Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
 52. Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}() /Users/nexxai/code/examplesite/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php:58
 53. Barryvdh\Debugbar\Middleware\InjectDebugbar-&gt;handle() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
 54. Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
 55. Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}() /Users/nexxai/code/examplesite/vendor/fideloper/proxy/src/TrustProxies.php:57
 56. Fideloper\Proxy\TrustProxies-&gt;handle() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
 57. Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
 58. Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21
 59. Illuminate\Foundation\Http\Middleware\TransformsRequest-&gt;handle() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
 60. Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
 61. Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21
 62. Illuminate\Foundation\Http\Middleware\TransformsRequest-&gt;handle() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
 63. Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
 64. Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
 65. Illuminate\Foundation\Http\Middleware\ValidatePostSize-&gt;handle() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
 66. Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
 67. Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:62
 68. Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode-&gt;handle() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
 69. Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
 70. Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104
 71. Illuminate\Pipeline\Pipeline-&gt;then() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151
 72. Illuminate\Foundation\Http\Kernel-&gt;sendRequestThroughRouter() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
 73. Illuminate\Foundation\Http\Kernel-&gt;handle() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:347
 74. Illuminate\Foundation\Testing\TestCase-&gt;call() /Users/nexxai/code/examplesite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:170
 75. Illuminate\Foundation\Testing\TestCase-&gt;get() /Users/nexxai/code/examplesite/tests/Feature/ExampleTest.php:145
 76. Tests\Feature\ExampleTest-&gt;a_user_can_reorder_a_Examples_characters_by_importance() /Users/nexxai/code/examplesite/vendor/phpunit/phpunit/src/Framework/TestCase.php:1153
 77. PHPUnit\Framework\TestCase-&gt;runTest() /Users/nexxai/code/examplesite/vendor/phpunit/phpunit/src/Framework/TestCase.php:842
 78. PHPUnit\Framework\TestCase-&gt;runBare() /Users/nexxai/code/examplesite/vendor/phpunit/phpunit/src/Framework/TestResult.php:687
 79. PHPUnit\Framework\TestResult-&gt;run() /Users/nexxai/code/examplesite/vendor/phpunit/phpunit/src/Framework/TestCase.php:796
 80. PHPUnit\Framework\TestCase-&gt;run() /Users/nexxai/code/examplesite/vendor/phpunit/phpunit/src/Framework/TestSuite.php:746
 81. PHPUnit\Framework\TestSuite-&gt;run() /Users/nexxai/code/examplesite/vendor/phpunit/phpunit/src/Framework/TestSuite.php:746
 82. PHPUnit\Framework\TestSuite-&gt;run() /Users/nexxai/code/examplesite/vendor/phpunit/phpunit/src/Framework/TestSuite.php:746
 83. PHPUnit\Framework\TestSuite-&gt;run() /Users/nexxai/code/examplesite/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:641
 84. PHPUnit\TextUI\TestRunner-&gt;doRun() /Users/nexxai/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:207
 85. PHPUnit\TextUI\Command-&gt;run() /Users/nexxai/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:163
 86. PHPUnit\TextUI\Command-&gt;main() /Users/nexxai/.composer/vendor/phpunit/phpunit/phpunit:61











--><html>
  <head>
    <meta charset="utf-8">
    <meta name="robots" content="noindex,nofollow"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
    <title>Whoops! There was an error.</title>

It's almost as if PHPUnit is ignoring the phpunit.xml file altogether.

Is there a way that I can test (even something stupid like echoing out a "caught" string) if it's even seeing the phpunit.xml file, or if there's something obvious that I've done wrong with it?

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>

        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="DB_CONNECTION" value="testing"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
    </php>
</phpunit>
Mar
12
7 months ago
Activity icon

Replied to Eloquent Query For Great-grandchildren?

@JLRDW - Using his example, each employee's benefits date would be different, based on when they started with the company and/or when their probationary period concludes, for example.

Activity icon

Replied to TokenMismatch Exception - Cause: Blank Line Before <?php

If you view the source of the page, what is being returned as the <input type="hidden" name="_token" ... field? If you refresh the page, is the token value changing?

Activity icon

Replied to How To Find Last Row From Second Table, Along With Its First Table Row

Why not do this:

public function index()
    {
       $volumes = journal::with('volume')->first();
        return view('welcome',compact('volumes '));
    }


use App\volume;

class journal extends Model
{
   function volume()
     {
          return $this->hasMany(volume::class)
        ->orderByDesc('id');
     }
}

Replace ->get() with ->first(), and then orderByDesc() so that it fetches them in reverse order. You also don't need to specify 'journal_id' as Eloquent will assume that by default.

Activity icon

Replied to TokenMismatch Exception - Cause: Blank Line Before <?php

You will need to include the CSRF token as part of the sign-in process. If the sign-in page is part of the Laravel app, just add

@csrf

Within your <form> tags and it will supply that for you.

Alternatively, you can look into disabling CSRF for that page specifically, however due to the protection it provides your users, I would not recommend that.

Activity icon

Started a new Conversation Use Forge To Deploy From Azure DevOps Git Repo

I have a git repo hosted in our company's Azure DevOps tenant and I'm having a heck of a time getting Forge to see it as a proper repo.

Has anyone had success doing this, and if so, what did you provide for the repository information within Forge?

Oct
19
1 year ago
Activity icon

Replied to Sorting By Appended Attribute

You are the MAN! Thank you so much, that works perfectly!

Activity icon

Replied to Sorting By Appended Attribute

@wilk_randall So I just tried doing this:

    public function getTotalScoreAttribute()
    {
        if ($this->total_score) {
            return $this->total_score;
        }

        return $this->countTotalVotes();
    }

but it failed with this error:

Undefined property: App\Feature::$total_score 

I'm guessing because of the circular logic (to get the total_score, we first must get the total score....) I also tried doing this:

    public function getTotalScoreAttribute()
    {
        return $this->countTotalVotes();
    }

    public function getScoreAttribute()
    {
        if ($this->total_score) {
            return $this->total_score;
        }

        return $this->countTotalVotes();
    }

but still when I call $feature->score, it's still doubling the DB queries.

Activity icon

Started a new Conversation Sorting By Appended Attribute

Ok, so let's say I have a model like this:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\Helpers\Helper;

class Feature extends Model
{

    protected $appends = [
         'total_score'
    ];

    public function getTotalScoreAttribute()
    {
        return $this->countTotalVotes();  // this method is inside the Helpers\Helper
    }
}

and this controller method:

    public function index()
    {
        $features = Feature::all();

        $features->sortByDesc('total_score');

        return view('features.index')->withFeatures($features);
    }

Why does the total_score have to be computed twice, once during the initial get() but then again when I want to sort it by the score? When I return the collection before sorting, the total_score property/attribute is there, but it's like the ->sortByDesc() says "screw this, I'm doing it again myself". Am I doing something wrong, or is what I'm trying to do impossible?

Sep
11
1 year ago
Activity icon

Replied to Very Slow PHPUnit Tests Using PHP7.2 Or PHP7.1.

For those who are running PHP 7.2, I had to do this to remove xdebug:

pecl uninstall xdebug

Then I had to edit my php.ini file and remove the two xdebug.so lines. Once I did that, the speed of my test suite went from ~25 seconds down to 8.

Activity icon

Replied to Testing Validation Of An Input Array

@qiutuleng Thank you so much! That works perfectly!

Sep
10
1 year ago
Activity icon

Started a new Conversation Testing Validation Of An Input Array

Let's say I have this HTML:

<input type="text" id="name" name="name[]" class="form-control" value="" required="">
<input type="text" id="name" name="name[]" class="form-control" value="" required="">
<input type="text" id="name" name="name[]" class="form-control" value="" required="">
<input type="text" id="name" name="name[]" class="form-control" value="" required="">

And in my request validator, I have this:

public function rules()
{
    return [
        'name.*' => 'required|string'
    ];
}

The test that I'm trying to write to ensure that the validation is working is:

    $person = make('App\Person', ['name' => null]);
    $this->post('/person', $person->toArray())
        ->assertSessionHasErrors('name');

The validation actually works and makes sure that each entry has data in the field, but I don't understand how I'd test that with assertSessionHasErrors, because it looks for the name of the variable, but in this case it's an array ("name[]") rather than a single variable (e.g. "name").

I've tried variations on the assertSessionHasErrors() like:

        ->assertSessionHasErrors('name[]');

        ->assertSessionHasErrors('name.*');

But nothing I try will make it work.

Does anyone know what I'm missing here?

Sep
01
1 year ago
Activity icon

Replied to Unknown Database ':memory:'

So it turns out I'm an idiot.

I had both DB_CONNECTION as well as DB_DRIVER and DB_DATABASE defined in the phpunit.xml; I got rid of _DRIVER and _DATABASE leaving only _CONNECTION and it works now.

Activity icon

Replied to Unknown Database ':memory:'

If I try running it as "phpunit -c phpunit.xml", it just gives me the same errors again:

➜  project git:(master) ✗ phpunit -c phpunit.xml 
PHPUnit 7.3.3 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 804 ms, Memory: 42.69MB

There was 1 error:

1) Tests\Feature\ProductionTest::a_user_can_browse_productions
Illuminate\Database\QueryException: SQLSTATE[HY000] [1049] Unknown database ':memory:' (SQL: select * from `sessions` where `id` = Oqjne2uDE1BOEwWovGdo8pkqO45Pqzgb9Ijspuxq limit 1)

/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:624
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:333
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1963
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1951
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2435
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1952
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php:77
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1926
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/DatabaseSessionHandler.php:91
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/DatabaseSessionHandler.php:128
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/Store.php:129
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:87
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:218
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:189
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:352
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:168
/Users/nexxai/code/project/tests/Feature/ProductionTest.php:15

Caused by
Doctrine\DBAL\Driver\PDOException: SQLSTATE[HY000] [1049] Unknown database ':memory:'

/Users/nexxai/code/project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:50
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:65
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:44
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:182
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:915
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:940
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:399
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:325
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:657
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:624
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:333
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1963
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1951
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2435
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1952
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php:77
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1926
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/DatabaseSessionHandler.php:91
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/DatabaseSessionHandler.php:128
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/Store.php:129
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:87
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:218
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:189
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:352
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:168
/Users/nexxai/code/project/tests/Feature/ProductionTest.php:15

Caused by
PDOException: SQLSTATE[HY000] [1049] Unknown database ':memory:'

/Users/nexxai/code/project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:46
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:65
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:44
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:182
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:915
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:940
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:399
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:325
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:657
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:624
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:333
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1963
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1951
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2435
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1952
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php:77
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1926
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/DatabaseSessionHandler.php:91
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/DatabaseSessionHandler.php:128
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/Store.php:129
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:87
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:218
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:189
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:352
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:168
/Users/nexxai/code/project/tests/Feature/ProductionTest.php:15

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Activity icon

Replied to Unknown Database ':memory:'

No dice

➜  project git:(master) ✗ ./vendor/bin/phpunit phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
        backupStaticAttributes="false"
        bootstrap="vendor/autoload.php"
        colors="true"
        convertErrorsToExceptions="true"
        convertNoticesToExceptions="true"
        convertWarningsToExceptions="true"
        processIsolation="false"
        stopOnFailure="false">
    <testsuites>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>

        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="DB_CONNECTION" value="sqlite" force="true"/>
        <env name="DB_DATABASE" value=":memory:" force="true"/>
        <env name="DB_DRIVER" value="sqlite" force="true"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
    </php>
</phpunit>
PHP Fatal error:  Uncaught PHPUnit\Runner\Exception: Class 'phpunit' could not be found in '/Users/nexxai/code/project/phpunit.xml'. in /Users/nexxai/code/project/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php:102
Stack trace:
#0 /Users/nexxai/code/project/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(130): PHPUnit\Runner\StandardTestSuiteLoader->load('phpunit', '/Users/nexxai/c...')
#1 /Users/nexxai/code/project/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(73): PHPUnit\Runner\BaseTestRunner->loadSuiteClass('phpunit', '/Users/nexxai/c...')
#2 /Users/nexxai/code/project/vendor/phpunit/phpunit/src/TextUI/Command.php(169): PHPUnit\Runner\BaseTestRunner->getTest('phpunit', '/Users/nexxai/c...', Array)
#3 /Users/nexxai/code/project/vendor/phpunit/phpunit/src/TextUI/Command.php(148): PHPUnit\TextUI\Command->run(Array, true)
#4 /Users/nexxai/code/project/vendor/phpunit/phpunit/phpunit(53): PHPUnit\TextUI\Command::main()
#5 {main}
thrown in /Users/nexxai/code/project/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php on line 102

Fatal error: Uncaught PHPUnit\Runner\Exception: Class 'phpunit' could not be found in '/Users/nexxai/code/project/phpunit.xml'. in /Users/nexxai/code/project/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php on line 102

PHPUnit\Runner\Exception: Class 'phpunit' could not be found in '/Users/nexxai/code/project/phpunit.xml'. in /Users/nexxai/code/project/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php on line 102

Call Stack:
    0.0028     394664   1. {main}() /Users/nexxai/code/project/vendor/phpunit/phpunit/phpunit:0
    0.0194    2461432   2. PHPUnit\TextUI\Command::main() /Users/nexxai/code/project/vendor/phpunit/phpunit/phpunit:53
    0.0194    2461544   3. PHPUnit\TextUI\Command->run() /Users/nexxai/code/project/vendor/phpunit/phpunit/src/TextUI/Command.php:148
    0.0269    3017368   4. PHPUnit\TextUI\TestRunner->getTest() /Users/nexxai/code/project/vendor/phpunit/phpunit/src/TextUI/Command.php:169
    0.0269    3017368   5. PHPUnit\TextUI\TestRunner->loadSuiteClass() /Users/nexxai/code/project/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php:73
    0.0274    3034408   6. PHPUnit\Runner\StandardTestSuiteLoader->load() /Users/nexxai/code/project/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php:130
Activity icon

Replied to Unknown Database ':memory:'

And yes, sqlite is installed on my machine:

➜  project git:(master) ✗ brew install sqlite
Warning: sqlite 3.24.0 is already installed and up-to-date
To reinstall 3.24.0, run `brew reinstall sqlite`
Activity icon

Replied to Unknown Database ':memory:'

Ok, something I snipped might actually be important:

Caused by
PDOException: SQLSTATE[HY000] [1049] Unknown database ':memory:'

/Users/nexxai/code/project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:46
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:65
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:44
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:182
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:915
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:940
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:399
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:325
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:657
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:624
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:333
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1963
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1951
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2435
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1952
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php:77
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1926
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/DatabaseSessionHandler.php:91
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/DatabaseSessionHandler.php:128
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/Store.php:129
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:87
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:218
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:189
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:352
/Users/nexxai/code/project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:168
/Users/nexxai/code/project/tests/Feature/ProductionTest.php:15

It looks like it's trying to use MySQL even though I've specified sqlite as the driver. I've tried doing a

php artisan config:clear

but it doesn't seem to make a difference

Activity icon

Replied to Ajax Request Throws Methodnotallowed Exception

What some people might do to make the route more "REST-friendly" is make your vote route:

Route::post('/article/{article}/vote', '[email protected]');
Activity icon

Replied to Ajax Request Throws Methodnotallowed Exception

Yes, but Laravel doesn't know if "vote' is referring to an article (as in your first route) or a hardcoded path (your second route). Since it reads the file from top to bottom, just put the more specific route above the less specific one and it'll work like you expect.

Activity icon

Replied to Ajax Request Throws Methodnotallowed Exception

Right, so since you have

Route::get('/article/{article}', '[email protected]');

before

Route::post('/article/vote/{article}', '[email protected]');

in your routes/web.php file, it's matching on the first one instead of the second. Put the post route above the get route and it should start working.

Activity icon

Started a new Conversation Unknown Database ':memory:'

Am I missing something here? I've got my phpunit.xml set up correctly (I think):

<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/> 

But no matter what I do, I keep getting this error:

PHPUnit 7.2.7 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 874 ms, Memory: 42.66MB

There was 1 error:

1) Tests\Feature\ProductionTest::a_user_can_browse_productions
Illuminate\Database\QueryException: SQLSTATE[HY000] [1049] Unknown database ':memory:' (SQL: select * from `sessions` where `id` = zX4xORwbal5OzBZv7ZfuvAhHamcHZkAFTHUgxjn5 limit 1)


[snip...]

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

This is the entirety of the test file:

<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;

class ProductionTest extends TestCase
{
    use DatabaseMigrations;

    /** @test */
    public function a_user_can_browse_productions()
    {
        $response = $this->get('/productions');

        $response->assertStatus(200);
    }

}

I feel like I'm taking crazy pills.

Aug
19
1 year ago
Activity icon

Replied to Best Way To Bisect Two Large Collections

This is along the lines of what I ended up doing - I built each dropdown as a search field that queries the DB via an API endpoint, basically like an auto-complete.

Aug
18
1 year ago
Activity icon

Replied to Best Way To Bisect Two Large Collections

@Snapey @brightstormhq So what's happening prior to that is the user is filling out a form on the previous page that effectively a wide open text box that we then use a bunch of regex to parse specific items out of, but since we know that regexing user input is imperfect, what we want to do is provide the list of items we think we parsed out correctly, but then give all of the available items we know of below it, in case we messed up.

The more I think about it, the more I think I should have some kind of auto-completing text field that queries the DB for the available entries based on what's been typed rather than generating the list possibly as many as 20 or more times on a single page.

Thanks guys, I appreciate your input.

Activity icon

Started a new Conversation Best Way To Bisect Two Large Collections

I have a very large collection (several thousand items), and given a much smaller collection of similar items (let's say 5-20 of them), I need to find and select them for further processing.

Currently I do it like this:

        // This is the list of 5-20
        $new_items = Item::where('prepared', 0)
            ->get();

        // Get existing items..
        $all_items = Item::all();

        // and figure out which items haven't been shown above
        // to create a bisected/diffed collection of just them
        $remaining_items = $all_items->diffAssoc($new_items);

In the view I've got:

@foreach ($stuffs as $stuff)
<div class="row">
    <div class="form-group col-md-8">
        <label for="name[{{$stuff->id}}]">{{$stuff->name}}</label>

        <select class="dropdown-autocomplete-menu form-control" id="name[{{$stuff->id}}]" name="name[{{$stuff->id}}]">
            <option disabled selected>
                Select the item
            </option>

            <optgroup label="Detected items">
                @foreach ($remaining_items as $item)
                <option value="{{ $item->id }}">
                    {{ $item->full_name }}
                </option>
                @endforeach
            </optgroup>

            <optgroup label="Other items">
                @foreach ($all_items as $item)
                <option value="{{ $item->id }}">
                    {{ $item->full_name }}
                </option>
                @endforeach
            </optgroup>

            <option value="-999">Not listed</option>
        </select>
    </div>
@endforeach 

But if I understand it correctly (and I'm still very much a novice), this is the N+1 problem (or possibly much worse). Is there a way to more efficiently generate the view so that it doesn't take so long to render the page?

Jul
06
1 year ago
Activity icon

Replied to Question About Caching And Best Practices

Ok, so after each create/update/delete event, you update both the individual model in the cache, but also the collection of models in the cache using cache keys? I just want to make sure I'm understanding correctly.

Activity icon

Started a new Conversation Question About Caching And Best Practices

So I've finally put on my big boy pants and have decided to look into caching as one method to help increase performance of my application, but I'm having a hard time wrapping my head around the best way to go about it.

I know that physically it's simple: enable the Redis cache driver, add

use Illuminate\Support\Facades\Cache;

to the top of my controller and presto finito, we're caching. What I don't understand is how and when I should be caching.

My app is something vaguely similar to a wiki of sorts, and so there's no schedule in which data can be assumed to be static for. With that being the case, I know that I can't just do:

$sprockets = Cache::remember('sprockets', 60, function () {
    return Sprocket::all();
});

because what if someone updates a Data object within those 60 seconds; they're gonna be fed old data (right?). And because the site is very much based on user contributions, I don't want someone to make an update only to go back to the main index view and not see their changes.

So I feel like I'm missing a step, like one where after every update, not only is the database table updated, but also several keys in the cache (e.g. not only the individual model record, but also the overall index). And if that's the case, can someone point me in the direction of some information about how and when it's best to do that?

I feel like I've got this massive hole in my understanding here but I want - nay, need - to figure it out, if for no other reason than my own sanity.

Thanks

Apr
02
1 year ago
Activity icon

Replied to How Do I Properly Sort This Distant Relationship

For future searchers, this is what I ended up doing:

    $performer = Performer::where('id', $id)
        ->with('castmember.character', 'castmember.performance.tour.production')
        ->with(['castmember' => function ($query) {
            $query->join('performances', 'castmembers.performance_id', '=', 'performances.id')
                ->select('performances.*', 'castmembers.*')
                ->orderBy('date', 'asc');
        }])
        ->first();
Apr
01
1 year ago
Activity icon

Started a new Conversation How Do I Properly Sort This Distant Relationship

Here's the code:

    $performer = Performer::with(
        'castmember.performance.tour.production',
        'castmember.character'
    )
        ->where('id', $id)
        ->firstOrFail();

Here are the relationships:

Performer:

public function castmember()
{
    return $this->hasMany(\App\Castmember::class);
}

Castmember:

public function performance()
{
    return $this->belongsTo(\App\Performance::class);
}

and I'm trying to sort by the "date" property on the Performance model so that we can display a chronological list of every performance a performer has been a part of.

The Castmember model is something like a pivot table except each instance tracks 3 things: the performer we're talking about, the performance they performed in, and the character they played.

What I've tried:

  • Various joins
  • Query scopes
  • Nested query constraints
  • probably some other stuff I'm forgetting here

I feel like this can't be the first time someone's tried to do this, but I'm at a loss here; what am I missing?

Mar
25
1 year ago
Activity icon

Replied to Charts With Filters

Yeah, you'd want to build that filtering into your model query so that you're not returning every result and then filtering after the fact, since depending on how much data is in the original query, you could be looking at a TON of wasted resources (e.g. performing a query that returns 10,000 results only to filter out 100 after the fact to display; instead write the original query so that it only retrieves those 100 results the first time).

Activity icon

Started a new Conversation Can You Remove A Foreign Key Reference Without Dropping The Column Entirely?

Say I used these lines in a migration:

$table->integer('dog_id')->unsigned();
$table->foreign('dog_id')->references('id')->on('dogs');

Now say later in development, I realized that I should have generalized better and so what I want to do is rename the "dogs" table to "pets". I rename the table to "pets" and rename columns to "pet_id" and that all works, but the foreign key relationship is still pointing to the "dogs" table. Do I just do:

$table->dropForeign('dog_id');

and call it a day? If that actually drops all the data in that column then that's bad. Or is there something else I need to do too?

Thanks

Mar
17
1 year ago
Activity icon

Replied to Using Flysystem, How Do I Get Uploaded Files' Storage::url To Return The Correct CNAME

@shez1983 Darn, I was afraid that was going to be the case.

Thanks

Activity icon

Replied to Large List Of Collection Items (names) - Is There A Way To Skip To A Letter?

@jlrdw I'm not sure what you mean - I meant that I tested both with and without query parameters, just to rule out whether or not they were causing the problem.

Can you show me the examples you're referring to so that I can see if there's anything useful in them?

Thanks

Activity icon

Replied to Large List Of Collection Items (names) - Is There A Way To Skip To A Letter?

@Cronix So I tried that but now I'm getting:

Call to undefined method Illuminate\Database\Query\Builder::links()

even on the original request (with no query parameters). Is that because the query has been split up and it's gone from a collection to a query builder?

Activity icon

Started a new Conversation Large List Of Collection Items (names) - Is There A Way To Skip To A Letter?

We have a large database of names, and we'd like to allow our users to jump to a particular letter in a view. We currently just use basic pagination but that's becoming untenable as the list of names is constantly growing, and by a lot.

Is there a way where we can keep pagination (if not, that's OK), but have the ability for our users to skip to a particular letter in the list?

Current lookup code:

    $people = Person::where('approved', 1)
        ->orderBy('first_name')
        ->paginate(30);

Current (simplified) display code:

@foreach ($people as $person)

    <tr><td>{{ $person->name }}</td></tr>

@endforeach

$people->links()

I think I could probably do a groupBy, but the unintended side effect of using a groupBy is that it would either be one gigantic page split up into letter-specific names, or having a single page for each letter which will still look unbalanced if you have letters with a ton of names vs. letters with few or no names.

Thoughts?