This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Setup: | |
abstract class TestCase extends BaseTestCase | |
{ | |
use CreatesApplication; | |
protected function setUp(): void | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
composer install --optimize-autoloader --no-dev | |
php artisan route:cache | |
php artisan config:cache | |
php artisan view:cache | |
php artisan event:cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// routes/web.php | |
Route::get('auto-login', function() { | |
// Only available in local environment | |
abort_unless(app()->environment('local'), 403); | |
// Login with first user from DB seeds | |
auth()->login(User::first()); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Eloquent\Builder; | |
Builder::macro('toSqlWithBindings', function () { | |
$bindings = array_map( | |
fn ($value) => is_numeric($value) ? $value : "'{$value}'", | |
$this->getBindings() | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// After setting the environment variables, we can go ahead and create a new Database. We can utilize the power of PHP artisan here with Laravel commands. | |
# Step 1 | |
// Fire up the command line and navigate to the project’s root directory Run the following command – php artisan make:command CreateMySQLDb | |
# Step 2 | |
// In the code editor file explorer, locate the new command file which is named CreateMySQLDb.php within the following folder app/Console/Commands. Edit the contents to look like the following snippet and save it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// if you want to run custom validation having a long function in laravel request file, you can use the following tricks to get the things done using withValidator method. | |
class StoreBlogPost extends FormRequest | |
{ | |
public function authorize() | |
{ | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PricePointHelper | |
<?php | |
namespace AppBundle\Helper; | |
class PricePointHelper | |
{ | |
/** | |
* Round a price up to the next price point | |
* @param float|null $price |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function random_password($length = 12) | |
{ | |
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?"; | |
return substr(str_shuffle($chars), 0, $length); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// search query from scope in laravel model | |
public function scopeSearchResults($query) | |
{ | |
return $query->when(!empty(request()->input('location', 0)), function($query) { | |
$query->whereHas('location', function($query) { | |
$query->whereId(request()->input('location')); | |
}); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Helper; | |
class SizeOrderHelper | |
{ | |
private const PATTERNS = [ | |
'^[0-9]+$' => false, | |
'^[0-9\/]+$' => false, | |
'^[0-9]+yrs$' => false, |
OlderNewer