Watch: Ted Cruz EVISCERATES Merrick Garland Over Targeting Parents and You Just Love to See It

https://www.louderwithcrowder.com/media-library/image.png?id=27810082&width=980

This afternoon, Attorney General Merrick Garland testified before a congressional hearing, and he wasn’t prepared for the kind of metaphorical beating he was going to receive. Senator Ted Cruz gave one helluva performance, skull dragging Garland for every single person in the chamber to see. It made for very compelling television. It was magnificent.

In my head I see Willem Dafoe firing his pistol in the air, "It was a firefight!"

Cruz definitely came in guns-a-blazing, immediately laying into the frail old man with a heavy punch to the gut.

"You came before this committee in your confirmation hearing, you promised things would be different. I asked you specifically, quote, ‘Will you commit to this committee that under your leadership the department of justice will not target the political opponents of this administration.’ Here was your answer, quote, ‘Absolutely. It’s totally inappropriate for the department to target any individual because of their politics or position in a campaign.’ That was your promise just a few months ago. I’m sorry to say you have broken that promise."


Ted Cruz absolutely LAYS into AG Garland, and it is amazing

youtu.be

And before Garland could even begin to process anything, Cruz eviscerated him. He demonstrated just how the AG did, in fact, weaponize the DOJ against parents in an act of political persecution. Garland played stupid—which is never difficult for a leftist hack—as Cruz drilled into him about the FBI being sicked on parents, who the National School Board Association recently described as "domestic terrorists", an event linked directly to the recent rape of a young girl in a Loudoun County school.

Cruz proceeded to grind the white-haired radical into the floor as Garland refuses to answer questions relating to the conflict of interest regarding the DOJ protecting the teaching of CRT and his son-in-law profiting from it.

I cannot describe the throttling properly without thousands of words. Needless to say, you must watch the video to appreciate it, and I promise you will not be disappointed.

Parents are fighting back against CRT. Workers are fighting back against vaccine mandates. And we have a handful of leaders in government who are fighting back against the radicalism in the Biden administration. My fellow Americans, #FightLikeHell.

Get your content free from Big Tech’s filter. Bookmark this website and sign up for our newsletter!


THIS Is Why We #FightLikeHell: LwC Mission Statement | Louder with Crowder

youtu.be

Louder With Crowder

‘Thank God You Are Not on the Supreme Court’: Sen. Tom Cotton Disembowels AG Merrick Garland

https://www.louderwithcrowder.com/media-library/image.png?id=27809584&width=980

Sometimes, you wanna go right to the videotape. Here is Senator Tom Cottom saying what we’re all thinking about Merrick Garland right to his douchey-looking face.


Sen. Cotton On AG Garland Responding To NSBA Letter By Targeting Parents: “Shameful"

youtu.be

"[Scott Smith] was cited by the school boards association as a domestic terrorist, which we now know, that letter and those reports were the basis [for your memorandum]. Your performance is shameful, thank God you are not on the Supreme Court."

Let’s fill in some context. Merrick Garland was being grilled over the White House’s attack on parents at school board meetings. The National School Board Association wrote to the White House to do something about the angry parents they referred to as "threats of violence." The poster child for these threats was Scott Smith, who was angrily removed from a Loudoun County school board meeting. Joe Biden’s White House, of course, was more than happy to side against the parents in favor of the school boards. Unlike the teachers’ unions, middle-class parents don’t give Joe Biden and the Democrats millions and millions of dollars.

THEN, we find out the reason Mr. Smith was angry was that his daughter was (allegedly) raped and the school tried to cover it up.

THEN, Garland testified to a House Committee that he never heard of the case.

THEN, the NSBA retracted their initial letter and apologized for the incendiary rhetoric. You know, calling parents "domestic terrorists" and whatnot. This is also where we find out the White House may have helped the NSBA write the incendiary rhetoric.

This all brings us to today. And Sen. Tom Cotton disemboweling Merrick Garland.

I’m glad we had this talk.

Get your content free from Big Tech’s filter. Bookmark this website and sign up for our newsletter!


THIS Is Why We #FightLikeHell: LwC Mission Statement | Louder with Crowder

youtu.be

Louder With Crowder

Testing And Debugging Laravel APIs

https://images.unsplash.com/photo-1617042375876-a13e36732a04?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw4NjkxNHwwfDF8c2VhcmNofDIxfHxjb2RlfGVufDB8MHx8fDE2MzQ5MjUwODQ&ixlib=rb-1.2.1&q=80&w=1080

Hey guys, last year I published Laravel API Test Helper, a Laravel package that can help you in developing and debugging your Laravel APIs. Since last year, 80% of my work has been around building APIs both at Across The Horizon Technologies and at Greenlite Nigeria. That’s why I have been putting out packages, which are code snippets that I end up duplicating across different projects.

In this tutorial, I will walk you through what the package is all about and how it can help speed up your API development with the Laravel framework.

Laravel Api Test Helper is a trait based Laravel package, meaning that it just contains a PHP trait that you can include in your test class, that’s all.

Let me show you 🙂

Installation & Setup

For this tutorial, I believe you have created a Laravel application . If you are new to Laravel, you can check out my Laravel Series for beginners.

First, let’s install the package with via composer:

composer require stephenjude/api-test-helper --dev

Next, we need you to include the helper trait inside our TestCase.php. This class comes with every Laravel installation. You can find it inside the test directory of your project.

<?php
namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Stephenjude\ApiTestHelper\WithApiHelper;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;
    use WithApiHelper; 
  
    ...
}

You can choose to include this trait to the particular test class that contains your API tests, but keeping it here makes it accessible to all our test class since they will extend the TestCase abstract class.

Usage: Testing and Debugging APIs

For this tutorial, we will create a single endpoint that fetches all the users in our database. Let start by creating a test class for our user list endpoint.

php artisan make:test UserApiTest

This will create a test file inside the tests\Feature directory in your Laravel project. This is the default for Laravel, but you can configure this directory to suit your project 🙂

PS: Make sure you have added your database credentials to your .env file.

Now let’s add the tests for our user list endpoint. We will use the Laravel getJson() to make a request to our endpoint and then set it to our test helper property $this->response. This gives the Api Test Helper package access to the api response, with which the helper trait can help you test and debug the response.

<?php

namespace Tests\Feature;

use App\Models\User;
use Tests\TestCase;

class UserApiTest extends TestCase
{
    public function test_get_user_list()
    {
        User::factory()->create();

        $this->response = $this->getJson('api/users');

        $this->dumpApiData(); 
    }
}

Dumping API Response: dumpApiData()

So I started out with the dumpApiData() with allows us to dump the response returned from our response, this response can either be a valid response or an error response from the api or your application error itself.

Log API Response: logApiData()

You can also log the response of your api by calling the logApiData() . This method logs all the response on your app to your log file.

...
$this->response = $this->getJson('api/users');

$this->logApiData();
...

Decoding API Response: decodeApiResponse()

You can also decode the API response by calling the decodeApiResponse() method which returns the response from your API.

PS: I will advice the use of the json() method provided in Laravel. I have already built this package before I learned about it. $this->response->json()

Testing Successful API Response

To test successful response, this package provides three(3) methods which I am going to explain with example.

To make a valid request, lets create a valid controller and route that can handle our request.

php artisan make:controller UserApiController -r

Here is our controller class with a valid response that returns list user.

<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;

class UserApiController extends Controller
{
    public function index()
    {
        return response()->json([
            'success' => true,
            'data' => User::all(['id', 'name', 'email',])
        ]);
    }
    
    ...

Now let’s add our user list route to api.php

Route::get('/users', [UserApiController::class, 'index']);

Now that we have a valid response for our endpoints, lets test the valid response methods.

assertApiSuccess()

...
$this->response = $this->getJson('api/users');

$this->assertApiSuccess(); 
...

The method asserts the response contains the success field with true value 'success' => true or fails if it doesn’t.

assertApiResponse($data)

The method asserts the response contains the actual data or fails if it doesn’t.

...
$user = User::factory()->create()->only(['id', 'name', 'email']);

$this->response = $this->getJson('api/users/'.$user['id']);

$this->assertApiResponse($user); 
...

assertApiResponseCollection($data)

The method asserts the response contains the actual collection or fails if it doesn’t.

...
User::factory()->count(2)->create();

$this->response = $this->getJson('api/users');

$this->assertApiResponseCollection(User::all(['id', 'name', 'email'])); 
...

Conclusion

I believe you have learnt how to speed up your development process with this package and if you are new, you basically understand how to test your endpoints. You can find the link to the repository for this tutorial below and please don’t forget to star the package repository.

Laravel News Links

Understanding lockForUpdate and sharedLock in Laravel

https://miro.medium.com/max/1200/1*bp5NUD3p_KDDUxlgPH1exg.png

😥 Pessimistic Locking

We fixed the flaw of magically altering the inflation levels, but we face another issue: what if the balance changes mid-transaction? To better show the issue, we will have a new person that also needs money from Alice. Meet Charlie!

In this specific example, because we have a web app with thousands of HTTP web requests (slightly exaggerated, but banks do encounter this), we will ignore the fact that PHP is a blocking-IO programming language in the examples.

Let’s say that Alice has a fast sleight of hand, and both transactions where Alice sends money to Bob and Charlie are done, like at the same time, in the matter of microseconds. This means that if the odds are just right, the database will pull the records at the very same time, and send money at the very exact time.

If this scenario occurs, you will merely become stunned how from $100, you turned a total of $200 in the bank, $100 for each account.

The issue here is because we don’t have a locking mechanism in place for our database.

// FIRST REQUEST
$alice = User::find(1); // 'balance' => 100,
$bob = User::find(2); // 'balance' => 0,
Bank::sendMoney($alice, $bob, 100); // true// SECOND REQUEST
$alice = User::find(1); // 'balance' => 100,
$charlie = User::find(3); // 'balance' => 0,
Bank::sendMoney($alice, $charlie, 100); // true, but should have been false

This happens because if both queries run the SELECT statements (the ones defined by find()) at the same time, both requests will read that Alice has $100 in her account, which can be false because if the other transaction has already changed the balance, we remain with a reading saying she still has $100.

In this particular case, this is what might happen:

Request1: Reads Alice balance as $100
Request2: Reads Alice balance as $100
Request1: Subtract $100 from Alice
Request2: Subtract $100 from Alice
Request1: Add $100 to Bob
Request2: Add $100 to Charlie

But because we don’t know which runs faster, for various reasons, this can also happen:

Request1: Reads Alice balance as $100
Request2: Reads Alice balance as $100
Request1: Subtract $100 from Alice
Request1: Add $100 to Bob
Request2: Subtract $100 from Alice
Request2: Add $100 to Charlie

The ideal situation would be this one:

Request1: Reads Alice balance as $100
Request1: Subtract $100 from Alice.
Request1: Add $100 to Bob
Request2: Reads Alice balance as $0
Request2: Don't allow Alice to send money

The solution would be to be able to run the SELECT statements one-after-another, so we make sure that the request reads from the database the true balance for Alice.

✅ Implementing Pessimistic Locking

Laravel has a neat way to tackle this issue with the help of queries. Databases (like MySQL) have a thing called deadlock. Deadlocks permit the one who runs a query to specifically describe whose rows can be selected or updated within a specific query.

Laravel has a documentation section about deadlocks, but it was hard for me to digest what does what, so I came up with a better example.

Laravel documentation says:

A “for update” lock prevents the selected records from being modified or from being selected with another shared lock.

This is what we want. If we run lockForUpdate in our find() statements, they will not be selected by another shared lock.

And for the shared lock:

A shared lock prevents the selected rows from being modified until your transaction is committed.

Is this also what we want? Of course, if we apply this to the find() queries, the rows (in the first one Alice & Bob, in the second one Alice & Charlie) will not be read, nor modified until our update transaction got committed successfully.

// FIRST REQUEST
DB::statement(function () {
$alice = User::lockForUpdate()->find(1); // 'balance' => 100,
$bob = User::lockForUpdate()->find(2); // 'balance' => 0,
Bank::sendMoney($alice, $bob, 100); // true
});
// SECOND REQUEST
DB::statement(function () {
$alice = User::lockForUpdate()->find(1); // 'balance' => 0,
$charlie = User::lockForUpdate()->find(3); // 'balance' => 0,
Bank::sendMoney($alice, $charlie, 100); // false
});

Obviously, having a lockForUpdate would be just enough, because, by definition, any rows selected by it will never be selected by another shared lock, either lockForUpdate() or sharedLock().

Alternatively, just like Laravel says, you may use sharedLock() just so other queries won’t select the same rows until the transaction is finished. The use case would be for strong read consistency, making sure that if another transaction may be in process, to not get outdated rows.

Thanks to Laravel and deadlocks, we can now avoid any inflation.👏

But if you decide to run your bank in Laravel, you should use Event Sourcing, you definitely don’t want to play with the market. 🤨

Supporting our work

If you enjoyed this article or you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, spread some kind words about our work or sponsor our work via Patreon for some exclusive articles full of Laravel tips and best practices. 📦

Laravel News Links

Different Ways to Back up MySQL Databases and Tables

https://blog.devart.com/wp-content/uploads/2021/08/dbforge-studio-for-mysql-download.png

The article provides an overview of the backup types available in MySQL and describes how-to examples of using the mysqldump command-line utility to take a backup of the database, tables, data, or schema and to restore the MySQL database. In addition, you can view how to generate a database backup with MySQL Workbench and how […]

The post Different Ways to Back up MySQL Databases and Tables appeared first on Devart Blog.

Planet MySQL

Short URL v6.0.0 released

https://opengraph.githubassets.com/d5515559507e3719b5e34e334c25d68142fec164e7e542a28166483fd39bd919/ash-jc-allen/short-url/releases/tag/v6.0.0

Added

  • Added the ability to forward query parameters to the destination URL. Huge thanks to @julienarcin for this contribution! (#94)

Changed

  • Dropped support for Laravel 6 and 7 (#96, #98)
  • Dropped support for PHP 7.3 and 7.4 (#85)

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.

Laravel News Links

Laravel Cashier Provider

https://avatars.githubusercontent.com/u/92824325?s=280&v=4

Pinned


  1. Cashier provides an expressive, fluent interface to manage billing services.



    PHP



    4

  2. Cashier Provider Driver Template



    PHP

  3. Cashier Provider Authorization Driver Template



    PHP



    1

  4. Driver for payment with QR codes via Sber (see cashier-provider/core)



    PHP



    2

  5. Driver for payment with QR codes via Tinkoff (see cashier-provider/core)



    PHP



    1

  6. Driver for managing cash payments in the Cashier Provider ecosystem



    PHP



    2


Repositories


  • tinkoff-qr


    Public

    Driver for payment with QR codes via Tinkoff (see cashier-provider/core)



    PHP



    1


    MIT


    0



    0



    0


    Updated Oct 24, 2021


  • sber-auth


    Public

    Sber API Authorization Driver



    PHP



    1


    MIT


    0



    0



    0


    Updated Oct 24, 2021


  • sber-qr


    Public

    Driver for payment with QR codes via Sber (see cashier-provider/core)



    PHP



    2


    MIT


    0



    0



    0


    Updated Oct 24, 2021


  • core


    Public

    Cashier provides an expressive, fluent interface to manage billing services.



    PHP



    4


    MIT


    0



    0



    0


    Updated Oct 24, 2021


  • cash


    Public

    Driver for managing cash payments in the Cashier Provider ecosystem



    PHP



    2


    MIT


    0



    0



    0


    Updated Oct 24, 2021


  • driver


    Public template

    Cashier Provider Driver Template



    PHP


    0


    MIT


    0



    0



    0


    Updated Oct 24, 2021


  • driver-auth


    Public template

    Cashier Provider Authorization Driver Template



    PHP



    1


    MIT


    0



    0



    0


    Updated Oct 24, 2021



  • PHP



    1


    MIT


    0



    0



    0


    Updated Oct 24, 2021

Most used topics

Loading…

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.

Laravel News Links

Deploying Laravel API on AWS Lambda

https://production.ams3.digitaloceanspaces.com/2021/08/Social-Sharing-photo-Template-1-13.png

AWS Lambda brought the term “serverless” into reality and shook the world of software development.

It gained a lot of popularity in the last few years and is one of the fastest-growing technologies provided by Amazon. One of its strengths is the ability to pay only for the amount of time it takes to run the code and pay nothing while the code isn’t running.

To accomplish this business model, AWS made Lambda scalable by default. You only provide the amount of memory your process needs and the cloud provider will be responsible for provisioning as much hardware as necessary every time your source code needs to be executed.

I have been working with AWS for 4 years and AWS Lambda in particular for 2 years. In this post, I want to share hands-on experience on deploying a Laravel API service on AWS Lambda.

Requirements

To follow along, you’ll need a few ingredients:

– AWS Account

– IAM Access Key / Secret Key

– PHP

– [Composer](https://getcomposer.org/download/)

– [NPM](https://nodejs.org/en/download/)

– [Serverless](https://goserverless.com)

– [Bref](https://bref.sh)

– [Laravel](https://laravel.com)

– [Optional] Docker

If you have an AWS Account already, everything else is manageable.

Let’s get started!

IAM Access

Let’s first start by generating programmatic access to AWS. We’ll need it so that we can provide the Serverless Framework with the ability to provision/deploy AWS lambda into our AWS account.

Log into your AWS account and go to IAM → Users → Add User. Choose a username for your account, check the Programmatic Access checkbox, and hit Next: Permission.

Under Attach existing policies directly, select the AdministratorAccess policy. We can now proceed to Next: Tags and subsequently Next: Review (Tags are optional).

Take this opportunity to double-check the configuration. Once you click Create User, AWS will show you the Access Key and Secret Key. The Secret Key is unrecoverable, so make sure to save it.

PHP, Composer, NPM, and Severless

If you have these tools installed in your environment, you may skip this step. Otherwise, I’ll show you how I install these tools inside a docker container.

#!/usr/bin/env sh

docker run --rm -v $(pwd):/app -w /app -it alpine:3.14 sh

apk add php8 php8-phar php8-curl php8-openssl php8-dom php8-xml php8-xmlwriter php8-xmlreader php8-tokenizer php8-mbstring php8-fileinfo php8-simplexml

apk add composer npm

cp /usr/bin/php8 /usr/bin/php

npm install -g serverless

This sequence of commands will start an Alpine Linux container and install PHP 8, Composer, NPM, and Serverless. Keep this container open because we’ll continue using it for the next steps.

Laravel and Bref

Let’s start a new Laravel project and install Bref using Composer.

#!/usr/bin/env sh

composer create-project laravel/laravel my-api
cd my-api
composer require bref/bref
./vendor/bin/bref init
0
rm index.php

The 0 above is to automatically select the option [0] Web application. Bref will then create serverless.yml and index.php. Since we’re using Laravel, we can remove the index.php and just keep the serverless.yml.

Before we move on to Serverless, let’s add a sample routing for our API by editing the routes/api.php file.

<?php

Route::get('/hello', fn () => response(['data' => 'Hello from Laravel!']));

Remember that by default the api.php folder is configured with the /api prefix, so our route will actually be /api/hello.

Serverless

Before we dive into the serverless.yml template, let’s configure the Serverless Framework. We can do that in two ways:

export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY_HERE
export AWS_SECRET_ACCESS_KEY=YUR_SECRET_KEY_HERE

The framework will automatically pick up the credentials from the environment variable and perform deployments into your account.

The 2nd approach is to use serverless config credentials:

serverless config credentials --provider aws --key YOUR_ACCESS_KEY_HERE --secret YOUR_SECRET_KEY_HERE

After configuring the credentials for your AWS account, let’s tweak the serverless.yml template generated by Bref:

service: app

provider:
  name: aws
  region: us-east-1
  runtime: provided.al2

plugins:
  - ./vendor/bref/bref

functions:
  api:
    handler: public/index.php
    environment:
        LOG_CHANNEL: stderr
        SESSION_DRIVER: array
        CACHE_DRIVER: array
    description: ''
    timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
    layers:
      - ${bref:layer.php-80-fpm}
    events:
      - httpApi: '*'

# Exclude files from deployment
package:
  patterns:
    - '!node_modules/**'
    - '!tests/**'

We change the handler from index.php to public/index.php as that’s the entry point for a Laravel application. There are also 3 important environment variables: LOG_CHANNEL, SESSION_DRIVER, and CACHE_DRIVER. The stderr driver will automatically drive log messages into CloudWatch and the array driver will essentially disable Session and Cache.

Deployment

To deploy the project, let’s issue the following command:

sls deploy

The output should look like this:

/app/my-api # sls deploy
Serverless: Deprecation warning: Detected ".env" files. In the next major release variables from ".env" files will be automatically loaded into the serverless build process. Set "useDotenv: true" to adopt that behavior now.
            More Info: https://www.serverless.com/framework/docs/deprecations/#LOAD_VARIABLES_FROM_ENV_FILES
Serverless: Deprecation warning: Resolution of lambda version hashes was improved with better algorithm, which will be used in next major release.
            Switch to it now by setting "provider.lambdaHashingVersion" to "20201221"
            More Info: https://www.serverless.com/framework/docs/deprecations/#LAMBDA_HASHING_VERSION_V2
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Service files not changed. Skipping deployment...
Service Information
service: app
stage: dev
region: us-east-1
stack: app-dev
resources: 11
api keys:
  None
endpoints:
  ANY - https://0000000000.execute-api.us-east-1.amazonaws.com
functions:
  api: app-dev-api
layers:
  None

You can use your endpoint to test the API. It should look like this: 

https://your_api_gateway_id.execute-api.us-east-1.amazonaws.com/api/hello

This is pretty much it! Your source code is now available behind API Gateway and Lambda and you’ll only pay for the time it takes for your code to execute.

Enforcing JSON Response

If we try to load an invalid route, say https://your_api_gateway_id.execute-api.us-east-1.amazonaws.com/whatever, we’ll get a fatal error because Laravel will try to write the compiled php files for Blade. We can fix that by adjusting the VIEW_COMPILED_PATH environment variable. But since the focus is to deploy API-based projects, we can also add a nice little middleware to enforce that every HTTP Response will be JSON.

<?php

namespace App\Http\Middleware;

use Closure;

class EnforceJsonResponse
{
    public function handle($request, Closure $next)
    {
        $request->headers->set('Accept', 'application/json');

        return $next($request);
    }
}

Then we can register it inside Kernel.php.

Conclusion

This introduction to Serverless with Laravel gives an overview of the foundation behind treating AWS Lambda as a hosting provider that only charges for execution time.

Although it is important to consider the aspect of running code on a read-only environment (with limited disk space under /tmp) and how two requests may not share the same live “container”, this approach doesn’t have a strong impact on the development practices and day-to-day operation of developers.

Providing APIs behind AWS Lambda makes them highly scalable and cheap if you have little to no usage at night or weekends, for instance.

Laravel News Links