Skip to content

Instantly share code, notes, and snippets.

View ArielMejiaDev's full-sized avatar
🐘
Focusing

ArielMejiaDev ArielMejiaDev

🐘
Focusing
View GitHub Profile
@ArielMejiaDev
ArielMejiaDev / security-in-laravel.md
Created October 28, 2021 22:58
security-in-laravel.md

Security in Laravel: How to Protect Your App

Code Injections

SQL Injections

User::query()->create($request->all());
@ArielMejiaDev
ArielMejiaDev / controller.php
Created October 5, 2021 22:40 — forked from jnbn/controller.php
Replicate (Duplicate) Eloquent Model With Relations
<?php
public function replicateWithRelations(QuestionCategory $questioncategory)
{
$newCategory = $questioncategory->replicate();
$newCategory->name = "Kopyası: ".$questioncategory->name;
$newCategory->push();
$questioncategory->relations = [];
//load relations on EXISTING MODEL
@ArielMejiaDev
ArielMejiaDev / resourceToArray_helper.md
Last active September 22, 2021 06:25
Transform a resource to an associative array

resourceToArray snippet

Use to transform a resource to an associative array:

abstract class TestCase extends BaseTestCase
{

    //...
@ArielMejiaDev
ArielMejiaDev / assertResource-macro.md
Last active September 23, 2021 19:35
it asserts a resource against a json response from Laravel

TestResponse snippet

On the app service provider boot method or in any custom provider:

/**
 * Assert that the json response match exactly with a given resource.
 * @return \Illuminate\Testing\TestResponse
 * @instantiated
@ArielMejiaDev
ArielMejiaDev / main.yml
Created August 3, 2021 02:54 — forked from roberto-butti/main.yml
GitHub Actions workflow for Laravel (automated test)
name: Laravel
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
laravel-tests:
@ArielMejiaDev
ArielMejiaDev / tests.yml
Created August 3, 2021 02:53 — forked from rubenvanassche/tests.yml
A simple Laravel testing workflow for GitHub Actions
name: Tests (PHP)
on: [push]
jobs:
tests:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
before_script:
- echo 'Before script'
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- chmod 700 ~/.ssh
- ssh-keyscan -H 'domain.com' >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
building:
@ArielMejiaDev
ArielMejiaDev / README.md
Created June 10, 2021 16:15 — forked from ManojKiranA/README.md
Simple Laravel Search Trait

Usage

Put SearchTrait.php in app directory. Then use SearchTrait in your model, like so

use App\SearchTrait;
use Illuminate\Database\Eloquent\Model;

class Article extends Model {
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Pagination\UrlWindow;
use Illuminate\Support\Arr;
use Barryvdh\Debugbar\Facade as DebugbarFacade;
use Illuminate\Container\Container;
use Illuminate\Contracts\Pagination\LengthAwarePaginator as LengthAwarePaginatorContract;
@ArielMejiaDev
ArielMejiaDev / full.php
Created June 10, 2021 16:10 — forked from ManojKiranA/full.php
Inertia Js Paginate
Route::get('/', function (\Illuminate\Http\Request $request) {
$initialSearch = $request->query('search', '');
$userQuery = User::query()
->when($request->filled('search'),function($query) use ($initialSearch){
$query->where('name','LIKE','%'.$initialSearch.'%')
->orWhere('email','LIKE','%'.$initialSearch.'%');
});