<commit_before><?php

namespace ErenMustafaOzdal\LaravelModulesBase\Middlewares;

use Closure;
use Illuminate\Contracts\Auth\Guard;

class RelatedModel
{

    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     * @param string $model
     * @param string $relation
     * @return mixed
     */
    public function handle($request, Closure $next, $model, $relation)
    {
        $model = 'App\\' . $model;
        $params = array_values( $request->route()->parameters() );
        // eğer ikinci yoksa dön
        if ( ! isset($params[1])) {
            return $next($request);
        }

        $model = is_numeric($params[0]) ? $model::findOrFail($params[0]) : $params[0];
        $relation_id = is_numeric($params[1]) ? $params[1] : $params[1]->id;

        if ( is_null($model->$relation()->where('id',$relation_id)->first()) ) {
            abort(404);
        }

        return $next($request);
    }
}<commit_msg>alt kategoriye ait verilerin gösterimi ve düzenlemesi sayfası middleware hatası giderildi<commit_after><?php

namespace ErenMustafaOzdal\LaravelModulesBase\Middlewares;

use Closure;
use Illuminate\Contracts\Auth\Guard;

class RelatedModel
{

    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     * @param string $model
     * @param string $relation
     * @return mixed
     */
    public function handle($request, Closure $next, $model, $relation)
    {
        $model = 'App\\' . $model;
        $params = array_values( $request->route()->parameters() );
        // eğer ikinci yoksa dön
        if ( ! isset($params[1])) {
            return $next($request);
        }

        $model = is_numeric($params[0]) ? $model::findOrFail($params[0]) : $params[0];
        $relation_id = is_numeric($params[1]) ? $params[1] : $params[1]->id;

        $relationModel = $model->descendantsAndSelf()->whereHas($relation, function($query) use($relation_id)
        {
            return $query->whereId($relation_id);
        })->get();

        if ( $relationModel->isEmpty() ) {
            abort(404);
        }

        return $next($request);
    }
}
{'fraction_non_alphanumeric': 0.1548154815481548, 'fraction_numerical': 0.009000900090009001, 'mean_word_length': 2.568218298555377, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '6179754', 'n_tokens_mistral': 719, 'n_tokens_neox': 705, 'n_words': 139}