<commit_before><?php

namespace Sapioweb\CrudHelper;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class CrudyController extends Controller
{
    public static function index($model, $relations = [])
    {
        switch (true) {
            case $relations !== null:

                $resource = $model->with($relations);
                break;

            default:
                $resource = $model->all();
                break;
        }

        return $resource;
    }

    public static function store($model, $createData)
    {
        $resource = $model->create($createData);

        return $resource;
    }

    public static function show($model, $field = 'id', $id, $relations = null)
    {
        switch (true) {
            case $relations !== null:

                foreach ($relations as $relation) {
                    $resource = $model->with($relation);
                }

                $resource = $resource->where($field, '=', $id);
                break;

            default:
                $resource = $model->where($field, '=', $id);
                break;
        }

        return $resource->first();
    }

    public static function relationshipQuery($model, $relationships, $relationField = null, $relationshipQuery = null)
    {
        foreach ($relationships as $relationship) {
            $resource = $model->with($relationship);
        }

        $resource = $resource->whereHas($relationship, function($query) use ($relationField, $relationshipQuery) {
            $query->where($relationField, '=', $relationshipQuery);
        });<commit_msg>removed foreach and array relations<commit_after><?php

namespace Sapioweb\CrudHelper;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class CrudyController extends Controller
{
    public static function index($model, $relations = [])
    {
        switch (true) {
            case $relations !== null:

                $resource = $model->with($relations);
                break;

            default:
                $resource = $model->all();
                break;
        }

        return $resource;
    }

    public static function store($model, $createData)
    {
        $resource = $model->create($createData);

        return $resource;
    }

    public static function show($model, $field = 'id', $id, $relations = [])
    {
        switch (true) {
            case $relations !== null:

                $resource = $model->with($relation);

                $resource = $resource->where($field, '=', $id);
                break;

            default:
                $resource = $model->where($field, '=', $id);
                break;
        }

        return $resource->first();
    }

    public static function relationshipQuery($model, $relationships, $relationField = null, $relationshipQuery = null)
    {
        foreach ($relationships as $relationship) {
            $resource = $model->with($relationship);
        }

        $resource = $resource->whereHas($relationship, function($query) use ($relationField, $relationshipQuery) {
            $query->where($relationField, '=', $relationshipQuery);
        });
{'fraction_non_alphanumeric': 0.13238036047234308, 'fraction_numerical': 0.0, 'mean_word_length': 1.988857938718663, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4590730', 'n_tokens_mistral': 875, 'n_tokens_neox': 816, 'n_words': 189}