Skip to content

Instantly share code, notes, and snippets.

View Mombuyish's full-sized avatar
Never stop progressing.

Yish Mombuyish

Never stop progressing.
View GitHub Profile
View LoadEnvironmentVariables.php
<?php
// Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables
public function bootstrap(Application $app)
{
if ($app->configurationIsCached()) { // if it cached, return empty
return;
}
$this->checkForSpecificEnvironmentFile($app);
View Application.php
<?php
// Illuminate\Foundation\Application
public function configurationIsCached()
{
return file_exists($this->getCachedConfigPath());
}
public function getCachedConfigPath()
View ConfigCacheCommand.php
<?php
protected function getFreshConfiguration()
{
$app = require $this->laravel->bootstrapPath().'/app.php'; // require application kernel of laravel.
$app->useStoragePath($this->laravel->storagePath()); // storage path.
$app->make(ConsoleKernelContract::class)->bootstrap(); // bootstraping instanced of ConsoleKernelContract class.
View ConfigCacheCommand.php
<?php
//Illuminate\Foundation\Console\ConfigCacheCommand
public function handle()
{
$this->call('config:clear'); // clear your config cached if it exists.
$config = $this->getFreshConfiguration(); // get a new config
View app.php
$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
View index.php
...
// Here is the application starting.
$app = require_once __DIR__.'/../bootstrap/app.php';
...
View vuepress.sh
# install
npm install -g vuepress
# create a markdown file
echo '# Hello VuePress' > README.md
# start writing
vuepress dev
# build to static files
View request.php
<?php
// passing array.
public function store(Request $request)
{
$data = $request->all();
//array_set, array_add and others way.
array_set($data, 'status', 'draft');
// accept array.
View optional.php
<?php
// User 1 exists, with account
$user1 = User::find(1);
$accountId = $user1->account->id; // 123
// User 2 exists, without account
$user2 = User::find(2);
$accountId = $user2->account->id; // PHP Error: Trying to get property of non-object
View abort_if.php
<?php
abort_if(! Auth::user()->isAdmin(), 403);
abort_if(! Auth::user()->isAdmin(), 403, 'Sorry, you are not an admin');
abort_if(Auth::user()->isCustomer(), 403);
// In "admin" specific controller
public function index()
{
if (! Auth::user()->isAdmin()) {