Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Console/FlushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\Scout\Console;

use Illuminate\Console\Command;
use Laravel\Scout\Exceptions\ScoutException;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'scout:flush')]
Expand All @@ -26,10 +27,14 @@ class FlushCommand extends Command
* Execute the console command.
*
* @return void
*
* @throws ScoutException
*/
public function handle()
{
$class = $this->argument('model');
class_exists($class) || class_exists($class = app()->getNamespace()."Models\\{$class}")
|| throw new ScoutException("Error: Model [{$class}] not found.");

$model = new $class;

Expand Down
5 changes: 5 additions & 0 deletions src/Console/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Command;
use Illuminate\Contracts\Events\Dispatcher;
use Laravel\Scout\Events\ModelsImported;
use Laravel\Scout\Exceptions\ScoutException;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'scout:import')]
Expand Down Expand Up @@ -32,10 +33,14 @@ class ImportCommand extends Command
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*
* @throws ScoutException
*/
public function handle(Dispatcher $events)
{
$class = $this->argument('model');
class_exists($class) || class_exists($class = app()->getNamespace()."Models\\{$class}")
|| throw new ScoutException("Error: Model [{$class}] not found.");

$model = new $class;

Expand Down
5 changes: 5 additions & 0 deletions src/Console/QueueImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\Scout\Console;

use Illuminate\Console\Command;
use Laravel\Scout\Exceptions\ScoutException;
use Laravel\Scout\Jobs\MakeRangeSearchable;
use Symfony\Component\Console\Attribute\AsCommand;

Expand Down Expand Up @@ -32,10 +33,14 @@ class QueueImportCommand extends Command
* Execute the console command.
*
* @return void
*
* @throws ScoutException
*/
public function handle()
{
$class = $this->argument('model');
class_exists($class) || class_exists($class = app()->getNamespace()."Models\\{$class}")
|| throw new ScoutException("Error: Model [{$class}] not found.");

$model = new $class;

Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Commands/QueueImportCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Laravel\Scout\Tests\Feature\Commands;

use Error;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Support\Facades\Queue;
use Laravel\Scout\Exceptions\ScoutException;
use Laravel\Scout\Jobs\MakeRangeSearchable;
use Orchestra\Testbench\Attributes\WithConfig;
use Orchestra\Testbench\Attributes\WithMigration;
Expand Down Expand Up @@ -254,7 +254,7 @@ public function test_it_dispatches_jobs_with_correct_parameters()

public function test_it_handles_invalid_model_class()
{
$this->expectException(Error::class);
$this->expectException(ScoutException::class);

$this->artisan('scout:queue-import', ['model' => 'NonExistentModel']);
}
Expand Down