laravel-bridge/scratch is a Laravel package for for project from scratch.
It currently has 10 GitHub stars and 2.652 downloads on Packagist (latest version 1.7.0).
Install it with composer require laravel-bridge/scratch.
Discover more Laravel packages by laravel-bridge
or browse all Laravel packages to compare alternatives.
Last updated
Start Laravel project from scratch.
Run the following command to require package:
composer require laravel-bridge/scratch
Setup when you want to use the package
Require
illuminate/databaseandilluminate/events
Method setupDatabaseConfig() has 3 arguments, the following is signature:
public function setupDatabaseConfig(string $name, array $connection, bool $default = false);
$name is the database name.$connection is the database config only.$default will set the default database if true.Method setupDatabaseConfigs() has 2 arguments, the following is signature:
public function setupDatabaseConfig(array $connections, string $default = 'default');
$connections is the all connections config.$default specify the connection is default.index.php example for Database:
use LaravelBridge\Scratch\Application;
$connections = [
'driver' => 'sqlite',
'database' => __DIR__ . '/sqlite.db',
];
$app = Application::getInstance()
->setupDatabaseConfig('default', $connections, true)
->bootstrap();
Eloquent is easy, too.
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
}
// ---
$user = new User();
$user->username = 'root';
$user->password = 'password';
$user->save();
User::all()->toArray();
Require
illuminate/view, requireilluminate/translationwhen need translation.
index.php example for View:
use LaravelBridge\Scratch\Application;
Application::getInstance()
->setupTranslator(__DIR__ . '/lang')
->setupView(__DIR__, __DIR__ . '/compiled')
->withFacades()
->bootstrap();
echo View::make('view', ['rows' => [1, 2, 3]]);
Template example view.blade.php:
@foreach ($rows as $row)
{{ $row }}
@endforeach
Require
illuminate/logandilluminate/events
Method setupLogger() has 3 arguments, the following is signature:
public function setupLogger(string $name, LoggerInterface $logger, bool $default = false);
$name is the Log name, and use Facade Log::driver($name) to specify.$logger is the instance implemented Psr\Log\LoggerInterface.$default will set the default log driver if true.Here is a testing example:
$spy = new TestHandler();
$logger = new Monolog\Logger('test');
$logger->pushHandler($spy);
$this->target->setupLogger('test', $logger, true)
->bootstrap();
Log::info('log_test');
$this->assertTrue($spy->hasInfoRecords());
The configuration will use illuminate/config package. Following is the priority.
Use withFacades() to active Facade and register short class:
$app->withFacades();
View::make(); // It's works
Bootstrap is a lifecycle in Laravel Kernel. The following is bootstrapper order.
\Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables::class
\Illuminate\Foundation\Bootstrap\LoadConfiguration::class
\Illuminate\Foundation\Bootstrap\HandleExceptions::class
\Illuminate\Foundation\Bootstrap\RegisterFacades::class
\Illuminate\Foundation\Bootstrap\RegisterProviders::class
\Illuminate\Foundation\Bootstrap\BootProviders::class
In Scratch application, we can load config functionally. and use withFacades() to register Facade first. finally, call ServiceProvider::register() on every provider when call bootstrap(). Next, call ServiceProvider::boot() on every provider, just like Laravel Kernel.
bootstrap() has an argument $withAllLaravelProviders, register all laravel provider when true. Also, It's default true. However, use withoutLaravelProvider() if you don't want use some Laravel providers.
Projects:
Libraries: